hyperstate icon indicating copy to clipboard operation
hyperstate copied to clipboard

Is there any help message supported?

Open sleepwalker2017 opened this issue 2 years ago • 2 comments

For example, I wrote a complex dataclass with many members. I don't really remember the name of each member. How can I know the correct way to set a member if I don't remember the full name? I can see some help message in argparse_dataclass like this. Do we support similar functions? image

sleepwalker2017 avatar Oct 11 '22 10:10 sleepwalker2017

Yes, if you run e.g. the example script with --help it will show usage help:

⋊> ~/s/hyperstate on main ◦ poetry run python examples/basic_config/main.py --help                                                                                                                                                                                              06:53:36
usage: main.py [-h] [--config CONFIG] [--hps-info [HPS_INFO]] [-v] [hyperparams [hyperparams ...]]

positional arguments:
  hyperparams           Hyperparameter values in the form of 'hyper.param=value'.

optional arguments:
  -h, --help            show this help message and exit
  --config CONFIG       Optional path to ron config file.
  --hps-info [HPS_INFO]
                        Print information about hyperparameters.
  -v, --verbose         Print verbose output.

You can pass the --hps-info option to print out all the different members:

⋊> ~/s/hyperstate on main ◦ poetry run python examples/basic_config/main.py --hps-info                                                                                                                                                                                          06:54:13
optimizer: OptimizerConfig
  lr: float = 0.0001                      # Learning rate.
  batch_size: int = 512                   # Batch size.
  optimizer: str = 'adam'
net: NetConfig
  hidden_size: int = 128                  # Number of activations in the hidden layer.
  num_layers: int = 2                     # Number of layers.
  norm: 'batchnorm'|'layernorm'|None
steps: int = 10                           # Number of steps to run.

You can also pass a search term to --hps-info to do a fuzzy search (doesn't work optimally in all cases yet):

⋊> ~/s/hyperstate on main ◦ poetry run python examples/basic_config/main.py --hps-info nlayer                                                                                                                                                                                   06:55:30
net.num_layers: int = 2                   # Number of layers.

When you pass in a parameter that doesn't exist, hyperstate will try to find similarly named members:

⋊> ~/s/hyperstate on main ◦ poetry run python examples/basic_config/main.py optim='sgd'                                                                                                                                                                                         06:56:08
error: Unknown field 'optim' for class 'Config

Most similar fields:
optimizer: OptimizerConfig                # Optimizer configuration.
optimizer.optimizer: str = 'adam'

cswinter avatar Oct 11 '22 13:10 cswinter

wow,thank you! I suggest that you put this message in README. It's a very good feature.

sleepwalker2017 avatar Oct 11 '22 21:10 sleepwalker2017