Files
Kaiwen Wang 20f3d33382 Add registry for Optimizers and LR Scheduler (#259)
Summary:
Make all the optimizers and schedulers in torch.optim available for use. (except CyclicLR, which has a Callable field `scale_fn` that's unsupported by FBL)
Convert DiscreteDQN and QRDQN to trainers to use this new format.
After this diff, OptimizerParameters would be deprecated. Instead, you should specify optimizer directly via the registry.

Pull Request resolved: https://github.com/facebookresearch/ReAgent/pull/259

Reviewed By: badrinarayan

Differential Revision: D21470948

fbshipit-source-id: 793222adbfebb87b064dbe7768bbbea89b2129dd
2020-05-28 17:54:45 -07:00

20 lines
399 B
Python

#!/usr/bin/env python3
import inspect
import torch
def is_strict_subclass(a, b):
if not inspect.isclass(a) or not inspect.isclass(b):
return False
return issubclass(a, b) and a != b
def is_torch_optimizer(cls):
return is_strict_subclass(cls, torch.optim.Optimizer)
def is_torch_lr_scheduler(cls):
return is_strict_subclass(cls, torch.optim.lr_scheduler._LRScheduler)