Skip to content

Commit d907b64

Browse files
authored
update code reference
remove the hardcoded code. reference to azureml-example repo
1 parent 167a1fc commit d907b64

File tree

1 file changed

+3
-83
lines changed

1 file changed

+3
-83
lines changed

articles/machine-learning/concept-component.md

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,8 @@ The component specification file defines the metadata and execution parameters f
4646

4747
The following example is a component specification for a training component.
4848

49-
```yaml
50-
name: Example_Train
51-
display_name: Example Train
52-
version: 20
53-
type: command
54-
description: Example of a torchvision training component
55-
tags: {category: Component Tutorial, contact: [email protected]}
56-
inputs:
57-
training_data:
58-
type: path
59-
description: Training data organized in torchvision structure
60-
max_epochs:
61-
type: integer
62-
description: Maximum epochs for training
63-
learning_rate:
64-
type: number
65-
description: Learning rate, default is 0.01
66-
default: 0.01
67-
learning_rate_schedule:
68-
type: string
69-
default: time-based
70-
outputs:
71-
model_output:
72-
type: path
73-
code:
74-
local_path: ./train_src
75-
environment: azureml:AzureML-Minimal:1
76-
command: >-
77-
python train.py
78-
--training_data ${{inputs.training_data}}
79-
--max_epochs ${{inputs.max_epochs}}
80-
--learning_rate ${{inputs.learning_rate}}
81-
--learning_rate_schedule ${{inputs.learning_rate_schedule}}
82-
--model_output ${{outputs.model_output}}
83-
```
49+
:::code language="yaml" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/basics/1b_e2e_registered_components/train.yml":::
50+
8451

8552
The following table explains the fields in the example. For a full list of available fields, see the [YAML component specification reference page](reference-yaml-component-command.md).
8653

@@ -105,55 +72,8 @@ Your Python script contains the executable logic for your component. Your script
10572

10673
To run, you must match the arguments for your Python script with the arguments you defined in the YAML specification. The following example is a Python training script that matches the YAML specification from the previous section.
10774

108-
```python
109-
## Required imports
110-
import argparse
111-
import os
112-
## Import other dependencies your script needs
113-
from pathlib import Path
114-
from uuid import uuid4
115-
from datetime import datetime
116-
117-
## Define an argument parser that matches the arguments from the components specification file
118-
parser = argparse.ArgumentParser("train")
119-
parser.add_argument("--training_data", type=str, help="Path to training data")
120-
parser.add_argument("--max_epochs", type=int, help="Max # of epochs for the training")
121-
parser.add_argument("--learning_rate", type=float, help="Learning rate")
122-
parser.add_argument("--learning_rate_schedule", type=str, help="Learning rate schedule")
123-
parser.add_argument("--model_output", type=str, help="Path of output model")
124-
125-
args = parser.parse_args()
126-
127-
## Implement your custom logic (in this case a training script)
128-
print ("hello training world...")
129-
130-
lines = [
131-
f'Training data path: {args.training_data}',
132-
f'Max epochs: {args.max_epochs}',
133-
f'Learning rate: {args.learning_rate}',
134-
f'Learning rate: {args.learning_rate_schedule}',
135-
f'Model output path: {args.model_output}',
136-
]
137-
138-
for line in lines:
139-
print(line)
140-
141-
print("mounted_path files: ")
142-
arr = os.listdir(args.training_data)
143-
print(arr)
144-
145-
for filename in arr:
146-
print ("reading file: %s ..." % filename)
147-
with open(os.path.join(args.training_data, filename), 'r') as handle:
148-
print (handle.read())
149-
150-
## Do the train and save the trained model as a file into the output folder.
151-
## Here only output a dummy data for example.
152-
curtime = datetime.now().strftime("%b-%d-%Y %H:%M:%S")
153-
model = f"This is a dummy model with id: {str(uuid4())} generated at: {curtime}\n"
154-
(Path(args.model_output) / 'model.txt').write_text(model)
75+
:::code language="python" source="~/azureml-examples-main/cli/jobs/pipelines-with-components/basics/1b_e2e_registered_components/train_src/train.py":::
15576

156-
```
15777

15878
:::image type="content" source="media/concept-component/component-introduction.png" lightbox="media/concept-component/component-introduction.png" alt-text="Conceptual doc showing mapping between source code elements and component UI." :::
15979

0 commit comments

Comments
 (0)