ENH: Add support to pass a prefix for hyperparam args (#936)

When `hyperparam_args` is passed, the command is modified to add the
argument in the settings. For example, if the looks like
`{learning_rate: [1, 2, 3]}`, something like
`--learning_rate=${{inputs.learning_rate}}` will be added to the
command. But sometimes we wouldn't want the dashes, e.g., when using
Hydra (`learning_rate=${{inputs.learning_rate}}` or maybe
`+learning_rate=${{inputs.learning_rate}}`). This PR adds support to
specify the prefix for the argument (default: `"--"`). For Hydra, we
might want, e.g., `""` or `"+"`.

<!--
## Guidelines

Please follow the guidelines for pull requests (PRs) in
[CONTRIBUTING](/CONTRIBUTING.md). Checklist:

- Ensure that your PR is small, and implements one change
- Give your PR title one of the prefixes listed in
[CONTRIBUTING](../docs/source/coding_guidelines.md#pull-request-titles)
to indicate what type of change that is
- Link the correct GitHub issue for tracking
- Add unit tests for all functions that you introduced or modified
- Run automatic code formatting / linting on all files ("Format
Document" Shift-Alt-F in VSCode)
- Ensure that documentation renders correctly in Sphinx by running `make
html` in the `docs` folder

## Change the default merge message

When completing your PR, you will be asked for a title and an optional
extended description. By default, the extended description will be a
concatenation of the individual
commit messages. Please DELETE/REPLACE that with a human readable
extended description for non-trivial PRs.
-->
This commit is contained in:
Fernando Pérez-García 2024-05-15 09:51:11 +01:00 коммит произвёл GitHub
Родитель e31ac35d11
Коммит 664ac09578
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -419,6 +419,7 @@ def submit_run_v2(
pytorch_processes_per_node: Optional[int] = None,
use_mpi_run_for_single_node_jobs: bool = True,
display_name: Optional[str] = None,
hyperdrive_argument_prefix: str = "--",
) -> Job:
"""
Starts a v2 AML Job on a given workspace by submitting a command
@ -452,6 +453,9 @@ def submit_run_v2(
This is required for Kubernetes compute. If False, single node jobs will not be run as distributed jobs.
:param display_name: The name for the run that will be displayed in the AML UI. If not provided, a random
display name will be generated by AzureML.
:param: hyperdrive_argument_prefix: Prefix to add to hyperparameter arguments. Some examples might be "--", "-"
or "". For example, if "+" is used, a hyperparameter "learning_rate" with value 0.01 will be passed as
`+learning_rate=0.01`.
:return: An AzureML Run object.
"""
root_dir = sanitize_snapshoot_directory(snapshot_root_directory)
@ -512,7 +516,7 @@ def submit_run_v2(
for sample_param, choices in param_sampling.items():
input_datasets_v2[sample_param] = choices.values[0]
cmd += f" --{sample_param}=" + "${{inputs." + sample_param + "}}"
cmd += f" {hyperdrive_argument_prefix}{sample_param}=" + "${{inputs." + sample_param + "}}"
command_job = create_command_job(cmd)
@ -744,6 +748,7 @@ def submit_to_azure_if_needed( # type: ignore
use_mpi_run_for_single_node_jobs: bool = False,
display_name: Optional[str] = None,
entry_command: Optional[PathOrString] = None,
hyperdrive_argument_prefix: str = "--",
) -> AzureRunInfo: # pragma: no cover
"""
Submit a folder to Azure, if needed and run it.
@ -819,6 +824,9 @@ def submit_to_azure_if_needed( # type: ignore
Setting this flag to True is required Kubernetes compute.
:param display_name: The name for the run that will be displayed in the AML UI. If not provided, a random
display name will be generated by AzureML.
:param: hyperdrive_argument_prefix: Prefix to add to hyperparameter arguments. Some examples might be "--", "-"
or "". For example, if "+" is used, a hyperparameter "learning_rate" with value 0.01 will be passed as
`+learning_rate=0.01`.
:return: If the script is submitted to AzureML then we terminate python as the script should be executed in AzureML,
otherwise we return a AzureRunInfo object.
"""
@ -986,6 +994,7 @@ def submit_to_azure_if_needed( # type: ignore
num_nodes=num_nodes,
pytorch_processes_per_node=pytorch_processes_per_node_v2,
use_mpi_run_for_single_node_jobs=use_mpi_run_for_single_node_jobs,
hyperdrive_argument_prefix=hyperdrive_argument_prefix,
)
if after_submission is not None: