Hi @PONS LOPEZ Antonio ,
Thank you for providing more information.
To implement the dynamic model versioning and updating of a machine learning training pipeline in Azure Data Factory, you'll need to incorporate Azure Data Factory (ADF) activities and Azure Functions or other methods to achieve the dynamic model versioning. Below are the steps you can try:
Determine the New Model Version
from azureml.core import Model
# List all registered models with the same name
registered_models = Model.list(workspace=ws, name='your_model_name')
# Find the latest version number
latest_version = max([int(model.version) for model in registered_models])
# Increment the version for the new model
new_version = str(latest_version + 1)
Update the Training Step with the New Version
train_step = PythonScriptStep(
name='train_step',
script_name='train.py',
arguments=[
'--input_data', input_data.as_named_input('input_data'),
'--output_data', output_data,
'--model_version', new_version # Pass the new version as an argument
],
inputs=[input_data],
outputs=[output_data],
compute_target='your_compute_target_name',
source_directory='your_source_directory',
allow_reuse=False
)
For more information, please refer to this technical document for implementing the PythonScriptStep
parse the 'model_version' argument and use it when registering the new model version.
import argparse
from azureml.core import Workspace, Model
# Parse the arguments
parser = argparse.ArgumentParser()
parser.add_argument('--model_version', type=str, help='New model version')
args = parser.parse_args()
# Connect to your Azure ML workspace
ws = Workspace.from_config()
# Register the new model with the specified version
model = Model.register(workspace=ws,
model_path='path_to_new_model',
model_name='your_model_name',
tags={'area': 'your_model_area'},
properties={'version': args.model_version})
Submit the Pipeline
With these modifications in place, submit your pipeline as before, and it will dynamically update the model version each time it's run.
You can set up a trigger in Azure Data Factory to execute your training pipeline when the Azure Function provides the new model version. The trigger can be event driven.
Please refer to the below document which explains about StepSequence:
azureml.pipeline.core.builder.StepSequence class - Azure Machine Learning Python | Microsoft Learn
I hope this helps. Thank you!