Return list of available methods

I’m wondering if there’s a simple way to return a list all available optimizers, activation functions, and loss functions?

Using Python’s built-in inspect module I was able to do this:


and returned this:

[('ASGD', torch.optim.asgd.ASGD),
 ('Adadelta', torch.optim.adadelta.Adadelta),
 ('Adagrad', torch.optim.adagrad.Adagrad),
 ('Adam', torch.optim.adam.Adam),
 ('Adamax', torch.optim.adamax.Adamax),
 ('LBFGS', torch.optim.lbfgs.LBFGS),
 ('Optimizer', torch.optim.optimizer.Optimizer),
 ('RMSprop', torch.optim.rmsprop.RMSprop),
 ('Rprop', torch.optim.rprop.Rprop),
 ('SGD', torch.optim.sgd.SGD),
 ('SparseAdam', torch.optim.sparse_adam.SparseAdam)]

However, I would prefer to return, e.g., torch.optim.Adam instead of torch.optim.adam.Adam.

Does anyone have any ideas?


Maybe you can use dir(torch.optim) and getattr(torch.optim, class_name) to get them?


I think this will work. Thank you.