Skip to content

Commit

Permalink
Image notebook/cli param update (#2435)
Browse files Browse the repository at this point in the history
* notebook/cli param update

* notebook param update

* cli param update

* notebooks updated to foundational model

* vision batch deployment cli and sdk notebook (#2433)

* vision batch deployment cli and sdk notebook

* black formatting

* Comments

* comments

* updated to take latest version in FT notebooks

---------

Co-authored-by: grajguru <grajguru@microsoft.com>

* notebook/cli param update

* notebook param update

* notebook/cli param update

* notebook param update

* cli param update

* notebooks updated to foundational model

* notebook/cli param update

* notebook param update

* notebooks updated to foundational model

* notebook/cli param update

* notebook param update

* notebook/cli param update

* notebooks updated to foundational model

* cli update

* doc update

* addressing comments

---------

Co-authored-by: Gaurav Rajguru <rajgurugaurav77@gmail.com>
Co-authored-by: grajguru <grajguru@microsoft.com>
  • Loading branch information
3 people authored Jul 11, 2023
1 parent b9e9c94 commit a739ecf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
# Compute
compute_model_import: ${{parent.inputs.compute_model_import}}
compute_finetune: ${{parent.inputs.compute_finetune}}
number_of_gpu_to_use_finetuning: 1
num_nodes_finetune: 1
process_count_per_instance: 1
instance_count: 1

# model
task_name: image-classification
Expand All @@ -57,10 +57,12 @@ jobs:
training_data: ${{parent.inputs.training_data}}
validation_data: ${{parent.inputs.validation_data}}

image_width: 224
image_height: 224
number_of_workers: 8
auto_hyperparameter_selection: False
image_width: -1
image_height: -1
metric_for_best_model: accuracy
apply_augmentations: True
number_of_workers: 8
apply_deepspeed: False
deepspeed_config: ${{parent.inputs.ds_finetune}}
apply_ort: False
Expand All @@ -74,9 +76,9 @@ jobs:
warmup_steps: 0
optimizer: adamw_hf
weight_decay: 0.0
extra_optim_args: ""
gradient_accumulation_step: 1
precision: 32
metric_for_best_model: accuracy
label_smoothing_factor: 0.0
random_seed: 42
evaluation_strategy: epoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ finetuning_pipeline_component="transformers_image_classification_pipeline"
number_of_gpu_to_use_finetuning=$gpus_per_node # set to the number of GPUs available in the compute

# 1. Install dependencies
pip install azure-ai-ml==1.0.0
pip install azure-identity
pip install azure-ai-ml==1.8.0
pip install azure-identity==1.13.0
pip install datasets==2.3.2

unameOut=$(uname -a)
Expand Down Expand Up @@ -127,7 +127,7 @@ then
fi

# get the latest model version
model_version=$(az ml model show --name $model_name --label $model_label --registry-name $registry_name --query version --output tsv)
model_version=$(az ml model show --name $aml_registry_model_name --label $model_label --registry-name $registry_name --query version --output tsv)

# 4. Prepare data
python prepare_data.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
# Compute
compute_model_import: ${{parent.inputs.compute_model_import}}
compute_finetune: ${{parent.inputs.compute_finetune}}
number_of_gpu_to_use_finetuning: 1
num_nodes_finetune: 1
process_count_per_instance: 1
instance_count: 1

# model
task_name: image-classification-multilabel
Expand All @@ -58,10 +58,12 @@ jobs:
training_data: ${{parent.inputs.training_data}}
validation_data: ${{parent.inputs.validation_data}}

image_width: 224
image_height: 224
number_of_workers: 8
auto_hyperparameter_selection: False
image_width: -1
image_height: -1
metric_for_best_model: iou
apply_augmentations: True
number_of_workers: 8
apply_deepspeed: False
deepspeed_config: ${{parent.inputs.ds_finetune}}
apply_ort: False
Expand All @@ -75,9 +77,9 @@ jobs:
warmup_steps: 0
optimizer: adamw_hf
weight_decay: 0.0
extra_optim_args: ""
gradient_accumulation_step: 1
precision: 32
metric_for_best_model: accuracy
label_smoothing_factor: 0.0
random_seed: 42
evaluation_strategy: epoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ finetuning_pipeline_component="transformers_image_classification_pipeline"
number_of_gpu_to_use_finetuning=$gpus_per_node # set to the number of GPUs available in the compute

# 1. Install dependencies
pip install azure-ai-ml==1.0.0
pip install azure-identity
pip install azure-ai-ml==1.8.0
pip install azure-identity==1.13.0
pip install datasets==2.3.2

unameOut=$(uname -a)
Expand Down Expand Up @@ -126,7 +126,7 @@ then
fi

# get the latest model version
model_version=$(az ml model show --name $model_name --label $model_label --registry-name $registry_name --query version --output tsv)
model_version=$(az ml model show --name $aml_registry_model_name --label $model_label --registry-name $registry_name --query version --output tsv)

# 4. Prepare data
python prepare_data.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ The components can be seen here ![as shown in the figure](../../images/image_cla

5. _image_height_ (int, optional)

Final Image height after augmentation that is input to the network. The default value is 224.
Final Image height after augmentation that is input to the network. Default value is -1 which means it would be overwritten by default image height in Hugging Face feature extractor. If either image_width or image_height is set to -1, default value would be used for both width and height.

6. _image_width_ (int, optional)

Final Image width after augmentation that is input to the network. The default value is 224.
Final Image width after augmentation that is input to the network. Default value is -1 which means it would be overwritten by default image width in Hugging Face feature extractor. If either image_width or image_height is set to -1, default value would be used for both width and height.

7. _task_name_ (string, required)

Which task the model is solving.
It could be one of [`image-classification`, `image-classification-multilabel`].

7. _metric_for_best_model_ (string, optional)

Specify the metric to use to compare two different models. The default value is accuracy. It could be one of
[`loss`, `f1_score_macro`,
`accuracy`, `precision_score_macro`,
`recall_score_macro`, `iou`,
`iou_macro`, `iou_micro`,
`iou_weighted`]

8. _apply_augmentations_ (bool, optional)

If set to true, will enable data augmentations for training and validation.
Expand Down Expand Up @@ -81,7 +90,7 @@ The components can be seen here ![as shown in the figure](../../images/image_cla

19. _learning_rate_scheduler_ (string, optional)

The learning rate scheduler to use. The default value is warmup_linear.
The learning rate scheduler to use.
It could be one of [`warmup_linear`, `warmup_cosine`, `warmup_cosine_with_restarts`, `warmup_polynomial`,
`constant`, `warmup_constant`]

Expand All @@ -91,13 +100,19 @@ The components can be seen here ![as shown in the figure](../../images/image_cla

21. _optimizer_ (string, optional)

Optimizer to be used while training. The default value is adamw_hf.
Optimizer to be used while training.
It could be one of [`adamw_hf`, `adamw`, `sgd`, `adafactor`, `adagrad`]

22. _weight_decay_ (float, optional)

The weight decay to apply (if not zero) to all layers except all bias and LayerNorm weights in AdamW optimizer. The default value is 0.

23. _extra_optim_args_: (string, optional)

Optional additional arguments that are supplied to SGD Optimizer. The arguments should be semi-colon separated key value pairs and should be enclosed in double quotes. For example, "momentum=0.5; nesterov=True" for sgd. Please make sure to use a valid parameter names for the chosen optimizer. For exact parameter
names, please refer https://pytorch.org/docs/1.13/generated/torch.optim.SGD.html#torch.optim.SGD for SGD. Parameters supplied in extra_optim_args will take precedence over the parameter supplied via other arguments such as weight_decay. If weight_decay is provided via "weight_decay"
parameter and via extra_optim_args both, values specified in extra_optim_args will be used.

23. _gradient_accumulation_step_ (int, optional)

Number of updates steps to accumulate the gradients for, before performing a backward/update pass. The default value is 1.
Expand All @@ -107,9 +122,6 @@ The components can be seen here ![as shown in the figure](../../images/image_cla
Apply mixed precision training. This can reduce memory footprint by performing operations in half-precision. The default value is 32.
It could one of [`16`, `32`]

25. _metric_for_best_model_ (string, optional)

Specify the metric to use to compare two different models. The default value is accuracy.

26. _label_smoothing_factor_ (float, optional)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"metadata": {},
"outputs": [],
"source": [
"! pip install azure-ai-ml==1.0.0\n",
"! pip install azure-identity\n",
"! pip install azure-ai-ml==1.8.0\n",
"! pip install azure-identity==1.13.0\n",
"! pip install datasets==2.3.2"
]
},
Expand Down Expand Up @@ -499,9 +499,10 @@
" # \"model_name\": huggingface_model_name,\n",
" # finetune_args\n",
" \"auto_hyperparameter_selection\": False,\n",
" \"image_width\": 224,\n",
" \"image_height\": 224,\n",
" \"image_width\": -1,\n",
" \"image_height\": -1,\n",
" \"task_name\": \"image-classification\",\n",
" \"metric_for_best_model\": \"accuracy\",\n",
" \"apply_augmentations\": True,\n",
" \"number_of_workers\": 8,\n",
" \"apply_deepspeed\": False,\n",
Expand All @@ -517,9 +518,9 @@
" \"warmup_steps\": 0,\n",
" \"optimizer\": \"adamw_hf\",\n",
" \"weight_decay\": 0.0,\n",
" \"extra_optim_args\": \"\",\n",
" \"gradient_accumulation_step\": 1,\n",
" \"precision\": \"32\",\n",
" \"metric_for_best_model\": \"accuracy\",\n",
" \"label_smoothing_factor\": 0.0,\n",
" \"random_seed\": 42,\n",
" \"evaluation_strategy\": \"epoch\",\n",
Expand All @@ -535,8 +536,8 @@
" \"resume_from_checkpoint\": False,\n",
" \"save_as_mlflow_model\": True,\n",
"}\n",
"number_of_gpu_to_use_finetuning = 1\n",
"num_nodes_finetune = 1\n",
"process_count_per_instance = 1\n",
"instance_count = 1\n",
"\n",
"# Ensure that the user provides only one of mlflow_model or model_name\n",
"if pipeline_component_args.get(\"mlflow_model\") is None and pipeline_component_args.get(\"model_name\") is None:\n",
Expand Down Expand Up @@ -579,8 +580,8 @@
" compute_finetune=finetune_cluster_name,\n",
" training_data=Input(type=AssetTypes.MLTABLE, path=training_mltable_path),\n",
" validation_data=Input(type=AssetTypes.MLTABLE, path=validation_mltable_path),\n",
" number_of_gpu_to_use_finetuning=number_of_gpu_to_use_finetuning,\n",
" num_nodes_finetune=num_nodes_finetune,\n",
" instance_count=instance_count,\n",
" process_count_per_instance=process_count_per_instance,\n",
" **pipeline_component_args,\n",
" )\n",
" return {\n",
Expand Down Expand Up @@ -858,14 +859,14 @@
" success_threshold=1,\n",
" timeout=10,\n",
" period=10,\n",
" initial_delay=10,\n",
" initial_delay=2000,\n",
" ),\n",
" readiness_probe=ProbeSettings(\n",
" failure_threshold=10,\n",
" success_threshold=1,\n",
" timeout=10,\n",
" period=10,\n",
" initial_delay=10,\n",
" initial_delay=2000,\n",
" ),\n",
")\n",
"workspace_ml_client.online_deployments.begin_create_or_update(demo_deployment).wait()\n",
Expand Down Expand Up @@ -923,8 +924,9 @@
"\n",
"\n",
"request_json = {\n",
" \"inputs\": {\n",
" \"image\": [base64.encodebytes(read_image(sample_image)).decode(\"utf-8\")],\n",
" \"input_data\": {\n",
" \"columns\": [\"image\"],\n",
" \"data\": [base64.encodebytes(read_image(sample_image)).decode(\"utf-8\")],\n",
" }\n",
"}\n",
"\n",
Expand Down Expand Up @@ -972,13 +974,6 @@
"source": [
"workspace_ml_client.online_endpoints.begin_delete(name=online_endpoint_name).wait()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"metadata": {},
"outputs": [],
"source": [
"! pip install azure-ai-ml==1.0.0\n",
"! pip install azure-identity\n",
"! pip install azure-ai-ml==1.8.0\n",
"! pip install azure-identity==1.13.0\n",
"! pip install datasets==2.3.2"
]
},
Expand Down Expand Up @@ -95,7 +95,10 @@
" subscription_id = \"SUBSCRIPTION_ID\"\n",
" resource_group = \"RESOURCE_GROUP\"\n",
" workspace_name = \"AML_WORKSPACE_NAME\"\n",
" workspace_ml_client = MLClient(credential, subscription_id, resource_group, workspace_name)\n",
"\n",
"workspace_ml_client = MLClient(\n",
" credential, subscription_id, resource_group, workspace_name\n",
")\n",
"\n",
"registry_ml_client = MLClient(\n",
" credential,\n",
Expand Down Expand Up @@ -499,9 +502,10 @@
" # \"model_name\": huggingface_model_name,\n",
" # finetune_args\n",
" \"auto_hyperparameter_selection\": False,\n",
" \"image_width\": 224,\n",
" \"image_height\": 224,\n",
" \"image_width\": -1,\n",
" \"image_height\": -1,\n",
" \"task_name\": \"image-classification-multilabel\",\n",
" \"metric_for_best_model\": \"iou\",\n",
" \"apply_augmentations\": True,\n",
" \"number_of_workers\": 8,\n",
" \"apply_deepspeed\": False,\n",
Expand All @@ -517,9 +521,9 @@
" \"warmup_steps\": 0,\n",
" \"optimizer\": \"adamw_hf\",\n",
" \"weight_decay\": 0.0,\n",
" \"extra_optim_args\": \"\",\n",
" \"gradient_accumulation_step\": 1,\n",
" \"precision\": \"32\",\n",
" \"metric_for_best_model\": \"accuracy\",\n",
" \"label_smoothing_factor\": 0.0,\n",
" \"random_seed\": 42,\n",
" \"evaluation_strategy\": \"epoch\",\n",
Expand All @@ -535,8 +539,8 @@
" \"resume_from_checkpoint\": False,\n",
" \"save_as_mlflow_model\": True,\n",
"}\n",
"number_of_gpu_to_use_finetuning = 1\n",
"num_nodes_finetune = 1\n",
"process_count_per_instance = 1\n",
"instance_count = 1\n",
"\n",
"# Ensure that the user provides only one of mlflow_model or model_name\n",
"if pipeline_component_args.get(\"mlflow_model\") is None and pipeline_component_args.get(\"model_name\") is None:\n",
Expand Down Expand Up @@ -579,8 +583,8 @@
" compute_finetune=finetune_cluster_name,\n",
" training_data=Input(type=AssetTypes.MLTABLE, path=training_mltable_path),\n",
" validation_data=Input(type=AssetTypes.MLTABLE, path=validation_mltable_path),\n",
" number_of_gpu_to_use_finetuning=number_of_gpu_to_use_finetuning,\n",
" num_nodes_finetune=num_nodes_finetune,\n",
" instance_count=instance_count,\n",
" process_count_per_instance=process_count_per_instance,\n",
" **pipeline_component_args,\n",
" )\n",
" return {\n",
Expand Down Expand Up @@ -625,7 +629,7 @@
"metadata": {},
"outputs": [],
"source": [
"workspace_ml_client.jobs.stream(transformers_pipeline_run.name)"
"workspace_ml_client.jobs.stream(transformers_pipeline_run.name)\n"
]
},
{
Expand Down Expand Up @@ -919,8 +923,9 @@
"\n",
"\n",
"request_json = {\n",
" \"inputs\": {\n",
" \"image\": [base64.encodebytes(read_image(sample_image)).decode(\"utf-8\")],\n",
" \"input_data\": {\n",
" \"columns\": [\"image\"],\n",
" \"data\": [base64.encodebytes(read_image(sample_image)).decode(\"utf-8\")],\n",
" }\n",
"}\n",
"\n",
Expand Down Expand Up @@ -968,13 +973,6 @@
"source": [
"workspace_ml_client.online_endpoints.begin_delete(name=online_endpoint_name).wait()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit a739ecf

Please sign in to comment.