Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-2887: Support command line args for training scripts #3617

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,8 @@ Use a training script to train an ML model on data.

```sh {class="command-line" data-prompt="$"}
viam train submit managed --dataset-id=<dataset-id> --model-org-id=<model-org-id> --model-name=<model-name> --model-type=<model-type> --model-labels=<model-labels> [...named args]
viam train submit custom from-registry --dataset-id=<dataset-id> --org-id=<org-id> --model-name=<model-name> --script-name=<script-name> --version=<version> [...named args]
viam train submit custom with-upload --dataset-id=<dataset-id> --org-id=<org-id> --model-name=<model-name> --path=<path> --script-name=<script-name> [...named args]
viam train submit custom from-registry --dataset-id=<dataset-id> --org-id=<org-id> --model-name=<model-name> --script-name=<script-name> --version=<version> --args=<arg-key>=<arg-value> [...named args]
viam train submit custom with-upload --dataset-id=<dataset-id> --org-id=<org-id> --model-name=<model-name> --path=<path> --script-name=<script-name> --args=<arg-key>=<arg-value> [...named args]
viam train get --job-id=<job-id>
viam train logs --job-id=<job-id>
viam train cancel --job-id=<job-id>
Expand All @@ -1310,10 +1310,10 @@ Examples:
viam train submit managed --dataset-id=456 --model-org-id=123 --model-name=MyCoolClassifier --model-type=single_label_classification --model-labels=1,2,3

# submit custom training job with an existing training script in the Registry on data in Viam cloud
viam train submit custom from-registry --dataset-id=<INSERT DATASET ID> --org-id=<INSERT ORG ID> --model-name=MyRegistryModel --model-version=2 --version=1 --script-name=mycompany:MyCustomTrainingScript
viam train submit custom from-registry --dataset-id=<INSERT DATASET ID> --org-id=<INSERT ORG ID> --model-name=MyRegistryModel --model-version=2 --version=1 --script-name=mycompany:MyCustomTrainingScript --args=num_epochs=3,model_type=multi_label

# submit custom training job with an uploaded training script on data in Viam cloud
viam train submit custom with-upload --dataset-id=<INSERT DATASET ID> --model-org-id=<INSERT ORG ID> --model-name=MyRegistryModel --model-type=single_label_classification --model-version=2 --version=1 --path=<path-to-tar.gz> --script-name=mycompany:MyCustomTrainingScript
viam train submit custom with-upload --dataset-id=<INSERT DATASET ID> --model-org-id=<INSERT ORG ID> --model-name=MyRegistryModel --model-type=single_label_classification --model-version=2 --version=1 --path=<path-to-tar.gz> --script-name=mycompany:MyCustomTrainingScript --args=num_epochs=3,labels="'green_square blue_star'"

# get a training job from Viam cloud based on training job ID
viam train get --job-id=123
Expand Down Expand Up @@ -1373,6 +1373,7 @@ viam train list --org-id=123 --job-status=completed
| `--job-id` | The ID of the training job to get or cancel. You can retrieve this value with `train list`. | `get`, `logs`, `cancel` | **Required** |
| `--job-status` | Training status to filter for. Can be one of `canceled`, `canceling`, `completed`, `failed`, `in_progress`, `pending`, or `unspecified`. | `list` | **Required** |
| `--framework` | Framework of the ML training script to upload, can be `tflite`, `tensorflow`, `pytorch`, or `onnx`. | `submit custom with-upload` | Optional |
| `--args` | Pass custom comma-separated arguments to the training script. Example: `num_epochs=3,model_type=multi_label`. To include whitespace, enclose the value with whitespace in single and double quotes. Example: `num_epochs=3,labels="'green_square blue_star'"`. | `submit custom from-registry`, `submit custom with-upload` | Optional |

### `version`

Expand Down
14 changes: 9 additions & 5 deletions docs/how-tos/create-custom-training-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ The script you are creating must take the following command line inputs:

The `parse_args()` function in the template parses your arguments.

You can add additional custom command line inputs by adding them to the `parse_args()` function.

{{% /expand %}}

{{% expand "Click for more information on parsing annotations from dataset file." %}}
Expand Down Expand Up @@ -450,9 +452,9 @@ You can export one of your Viam datasets to test your training script locally.
{{% tablestep %}}
**1. Export your dataset**

You can get the dataset id from the dataset page or using the [`viam dataset list`](/cli/#dataset) command:
You can get the dataset ID from the dataset page or using the [`viam dataset list`](/cli/#dataset) command:

```sh {class="command-line" data-prompt="$" data-output="1-10"}
```sh {class="command-line" data-prompt="$"}
viam dataset export --destination=<destination> --dataset-id=<dataset-id> --include-jsonl=true
```

Expand All @@ -465,8 +467,9 @@ Use the `parse_filenames_and_labels_from_json` and `parse_filenames_and_bboxes_f

Install any required dependencies and run your training script specifying the path to the <FILE>dataset.jsonl</FILE> file from your exported dataset:

```sh {class="command-line" data-prompt="$" data-output="1-10"}
python3 -m model.training --dataset_file=/path/to/dataset.jsonl --model_output_directory=.
```sh {class="command-line" data-prompt="$"}
python3 -m model.training --dataset_file=/path/to/dataset.jsonl \
--model_output_directory=. --custom_arg=3
```

{{% /tablestep %}}
Expand All @@ -482,7 +485,7 @@ To be able to use your training script in the Viam platform, you must upload it

Before you can upload your training script to Viam, you have to compress your project folder into a tar.gz file:

```sh {class="command-line" data-prompt="$" data-output="1-10"}
```sh {class="command-line" data-prompt="$"}
tar -czvf my-training.tar.gz my-training/
```

Expand Down Expand Up @@ -564,6 +567,7 @@ viam train submit custom from-registry --dataset-id=<INSERT DATASET ID> \
--org-id=<INSERT ORG ID> --model-name=MyRegistryModel \
--model-version=2 --version=1 \
--script-name=mycompany:MyCustomTrainingScript
--args=custom_arg1=3,custom_arg2="'green_square blue_star'"
```

This command submits a training job to the previously uploaded `MyCustomTrainingScript` with another input dataset, which trains `MyRegistryModel` and publishes that to the registry.
Expand Down
Loading