Checking if something is a PyTorch optimizer is pretty straightforward:
isinstance(something, torch.optim.Optimizer)
I was wondering what is the best / preferred way to check if something is a LR scheduler?
There is a (protected) class _LR_scheduler
in the lr_scheduler.py
, but first of all not every type of LR scheduler inherits from it (e.g., ReduceLROnPlateau
), and secondly it is kind of against Python conventions to type-check against a protected member of a module…
Anybody got some advice what is the best practice here?
Edit: I gave it some more thought, and the best I came up with is to check if:
something.__module__ == 'torch.optim.lr_scheduler'
I guess this works, but it still feels a bit hacky, so if anyone’s got a better idea let me know!