OneCycleLR and OneCycle training[Question]
State: closed | Pull request: no

I promise this is the last issue of the day haha. I would like to use OneCycleLearning (torch.optim.lr_scheduler.OneCycleLR) for my scheduler, but it is not available under the list of NeMo optimizers as far as I can tell. I have included the full list below so that someone can point out if it is available under a different name.

I tried setting sched.cls to be `torch.optim.lr_scheduler.OneCycleLR` but I get a message that the scheduler isn't being used:

```
[NeMo W 2020-11-23 16:34:28 lr_scheduler:463] Could not resolve classpath for Scheduler Config, and `name` was not provided either. 
    Scheduler cannot be instantiated !
```

Why can't I pass in the cls through the config? Do I need to implement my own subclass of WarmupPolicy as is done in `nemo.core.optim.lr_scheduler` 

**Additional context**

I got the class path for OneCycleLR using the following function:
```
def get_class_path(cls):
  return f'{cls.__module__}.{cls.__name__}'
```

Full list of schedulers:
```
AVAILABLE_SCHEDULERS = {
    'WarmupPolicy': WarmupPolicy,
    'WarmupHoldPolicy': WarmupHoldPolicy,
    'SquareAnnealing': SquareAnnealing,
    'CosineAnnealing': CosineAnnealing,
    'NoamAnnealing': NoamAnnealing,
    'WarmupAnnealing': WarmupAnnealing,
    'InverseSquareRootAnnealing': InverseSquareRootAnnealing,
    'SquareRootAnnealing': SquareRootAnnealing,
    'PolynomialDecayAnnealing': PolynomialDecayAnnealing,
    'PolynomialHoldDecayAnnealing': PolynomialHoldDecayAnnealing,
    'StepLR': pt_scheduler.StepLR,
    'ExponentialLR': pt_scheduler.ExponentialLR,
    'ReduceLROnPlateau': pt_scheduler.ReduceLROnPlateau,
    'CyclicLR': pt_scheduler.CyclicLR,
}
```

Only optimizers/schedulers that exist within the AVAILABLE_OPTIMIZERS and AVAILABLE_SCHEDULERS  can be resolved via config/classpath. 

You can register your own scheduler via the following method - before your code calls the hydra main function, in order to add external optimizers and schedulers support without having them integrated into NeMo. https://github.com/NVIDIA/NeMo/blob/main/nemo/core/optim/lr_scheduler.py#L365-L382 

We do have some support for ordinary pytorch schedulers, but if the registration + config doesn't work, let me know and I can look into it. 

I also got to work on this today but wasn't able to get it working. Here's what I did 

```
from nemo.core.optim import lr_scheduler
from torch.optim.lr_scheduler import OneCycleLR

# I'm pretty lost as to what to pass in as scheduler params
scheduler_params = {"optimizer":torch.optim.AdamW}
lr_scheduler.register_scheduler('OneCycleLR', scheduler=OneCycleLR, scheduler_params=scheduler_params)
# this subclass just adds a custom `configure_optimizers` with param_groups and discrim. learning rates, code in issue #1485 
empty_model = EncDecSubclass(cfg=DictConfig(params['model']))
checkpoint_name = 'quartznet_base.nemo'
my_model = empty_model.restore_from(PATH_SAVED_MODELS/checkpoint_name)
# code to load data and freeze model omitted
new_opt = copy.deepcopy(params["model"]["optim"])
new_opt["lr"] = 5e-3
new_opt["name"] = adamw
new_opt["weight_decay"] = 1e-8
my_model.setup_optimization(new_opt)
trainer = pl.Trainer(gpus=1, max_steps=1000, log_every_n_steps=5)
my_model.set_trainer(trainer)
trainer.fit(my_model)
```

Checking TensorBoard, I not only see that I'm not getting a OneCycle Scheduler, but that my LR is 1e-4 instead of 5e-3. 
![image](https://user-images.githubusercontent.com/47190785/104639196-206b5700-5675-11eb-978f-115dc7948fad.png)

I do get the message about scheduler not being used. I read the discussion in #1292 but I am setting my data before setting the new optimizer, and calling `set_trainer`. 

```
[NeMo W 2021-01-14 19:30:12 lr_scheduler:542] Neither `max_steps` nor `iters_per_batch` were provided to `optim.sched`, cannot compute effective `max_steps` !
    Scheduler will not be instantiated !
```

What am I doing wrong here? Thank you.

To setup the scheduler automatically you need three things - set the model trainer, set the models train data loader and then call setup optimization. It will use the train dataloader to determine how many steps it must take c