Skip to content

Commit f24a702

Browse files
author
Larry O'Brien
committed
Modified discussion, added code showing correct way.
1 parent 06c55c2 commit f24a702

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

articles/machine-learning/how-to-manage-runs.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,42 @@ creating a batch of runs is more efficient than creating them one by one.
260260

261261
### Submit child runs
262262

263-
Child runs can also be submitted from a parent run. This allows you to create hierarchies of parent and child runs, each running on different
264-
compute targets, connected by common parent run ID.
263+
Child runs can also be submitted from a parent run. This allows you to create hierarchies of parent and child runs.
265264

266-
Use the ['submit_child()'](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run.run?view=azure-ml-py#submit-child-config--tags-none----kwargs-)
267-
method to submit a child run from within a parent run. To do this in the parent run script, get the run context and submit the child run
268-
using the ``submit_child`` method of the context instance.
265+
You may wish your child runs to use a different run configuration than the parent run. For instance, you might use a less-powerful, CPU-based configuration for the parent, while using GPU-based configurations for your children. Another common desire is to pass each child different arguments and data. To customize a child run, pass a `RunConfiguration` object to the child's `ScriptRunConfig` constructor. This code example, which would be part of the parent `ScriptRunConfig` object's script:
266+
267+
- Creates a `RunConfiguration` retrieving a named compute resource `"gpu-compute"`
268+
- Iterates over different argument values to be passed to the children `ScriptRunConfig` objects
269+
- Creates and submits a new child run, using the custom compute resource and argument
270+
- Blocks until all of the child runs complete
269271

270272
```python
271-
## In parent run script
272-
parent_run = Run.get_context()
273-
child_run_config = ScriptRunConfig(source_directory='.', script='child_script.py')
274-
parent_run.submit_child(child_run_config)
273+
# parent.py
274+
# This script controls the launching of child scripts
275+
from azureml.core import Run, ScriptRunConfig, RunConfiguration
276+
277+
run_config_for_aml_compute = RunConfiguration()
278+
run_config_for_aml_compute.target = "gpu-compute"
279+
run_config_for_aml_compute.environment.docker.enabled = True
280+
281+
run = Run.get_context()
282+
283+
child_args = ['Apple', 'Banana', 'Orange']
284+
for arg in child_args:
285+
run.log('Status', f'Launching {arg}')
286+
child_config = ScriptRunConfig(source_directory=".", script='child.py', arguments=['--fruit', arg], run_config = run_config_for_aml_compute)
287+
# Starts the run asynchronously
288+
run.submit_child(child_config)
289+
290+
# Experiment will "complete" successfully at this point.
291+
# Instead of returning immediately, block until child runs complete
292+
293+
for child in run.get_children():
294+
child.wait_for_completion()
275295
```
276296

297+
To create many child runs with identical configurations, arguments, and inputs efficiently, use the [`create_children()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run.run?view=azure-ml-py#create-children-count-none--tag-key-none--tag-values-none-) method. Because each creation results in a network call, creating a batch of runs is more efficient than creating them one by one.
298+
277299
Within a child run, you can view the parent run ID:
278300

279301
```python

0 commit comments

Comments
 (0)