diff --git a/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification-pipeline.yaml b/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification-pipeline.yaml index ecd6cd5307..e97b563005 100644 --- a/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification-pipeline.yaml +++ b/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification-pipeline.yaml @@ -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 @@ -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 @@ -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 diff --git a/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh b/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh index e685885ccd..1144ff0858 100644 --- a/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh +++ b/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh @@ -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) @@ -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 diff --git a/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification-pipeline.yaml b/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification-pipeline.yaml index 83d4a9a96d..8abaf2827a 100644 --- a/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification-pipeline.yaml +++ b/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification-pipeline.yaml @@ -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 @@ -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 @@ -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 diff --git a/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh b/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh index e543f89fa5..41178df5c7 100644 --- a/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh +++ b/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh @@ -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) @@ -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 diff --git a/sdk/python/foundation-models/system/docs/component_docs/image_finetune/transformers_finetune_component.md b/sdk/python/foundation-models/system/docs/component_docs/image_finetune/transformers_finetune_component.md index 9e57038ade..90b3b7a935 100644 --- a/sdk/python/foundation-models/system/docs/component_docs/image_finetune/transformers_finetune_component.md +++ b/sdk/python/foundation-models/system/docs/component_docs/image_finetune/transformers_finetune_component.md @@ -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. @@ -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`] @@ -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. @@ -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) diff --git a/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb b/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb index bab5b3a3db..80300f9dcb 100644 --- a/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb +++ b/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb @@ -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" ] }, @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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": { diff --git a/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb b/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb index 3c0735e7ab..351fccd83f 100644 --- a/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb +++ b/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb @@ -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" ] }, @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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" ] }, { @@ -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", @@ -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": {