Skip to main content
You can use W&B Sweeps with custom CLI commands if training configuration passes command-line arguments. This lets you run sweeps against existing training scripts that already expect specific CLI flags, without modifying how the script consumes its arguments. The following example shows a Bash terminal that trains a Python script named train.py and provides values that the script parses:
To reproduce that invocation under a sweep, modify the command key in the sweep configuration YAML file so the sweep agent builds the same command line. Based on the previous example, the configuration looks like this:
The ${args} key expands to all parameters in the sweep configuration, formatted for argparse as --param1 value1 --param2 value2. If your script accepts additional arguments outside of argparse, use parse_known_args so unrecognized flags don’t cause the parser to fail:
Depending on the environment, python might refer to Python 2. To invoke Python 3, use python3 in the command configuration:

Sweeps