0

I am try to train a model using automl feature of Azure using a simple dataset which is working fine when doing it manually or via notebook but not working in azure devops pipeline. Created a azure devops pipeline with required service connection to ML workspace.

Below python code states required files are uploaded but I am not able to find the model when running below command to register whereas code stated below uploaded it:

I am trying to train the model via az cli command not via python. Any suggestion. Referred https://github.com/SaschaDittmann/MLOps-Lab as a reference but changed for automl piece since this git repo is not for auto ml abut remaining steps are same.

az ml model register -g $(azureml.resourceGroup) -w $(azureml.workspaceName) -n $(model.Name) -f metadata/run.json --asset-path outputs/models/abc.pkl -d "test" --tag "data"="test" --model-framework ScikitLearn -t metadata/model.json

Above command always giving me :- {'Azure-cli-ml Version': '1.12.0', 'Error': ModelPathNotFoundException: Message: Could not locate the provided model_path outputs/models/abc.pkl

##local_run is the another run id for automl and run.getContext() is the current run id.

automl_config = AutoMLConfig(task = 'classification',
                             primary_metric = 'accuracy',
                             X = X_train, 
                             y = y_train,
                             n_cross_validations = 2,
                             **automl_settings)

local_run = exp.submit(automl_config, show_output = True)

local_run = list(exp.get_runs())[0]

children = list(local_run.get_children())
metricslist = {}
for run in children:
    properties = run.get_properties()
    metrics = {k: v for k, v in run.get_metrics().items() if isinstance(v, float)}
    metricslist[int(properties['iteration'])] = metrics

rundata = pd.DataFrame(metricslist).sort_index(1)

best_run, fitted_model = local_run.get_output()
model_path = os.path.join(outputs_folder, model_filename)
#dump(fitted_model, model_path)

# upload the model file explicitly into artifacts

print("Uploading the model into run artifacts   RUN ***** ...")
run.upload_file(name="./outputs/models/" +`enter code here` model_filename, path_or_stream=model_path1)
run.upload_file("outputs/models/abc.pkl", path_or_stream=model_path1)
print("Uploaded the model {} to experiment {}".format(model_filename, run.experiment.name))
dirpath = os.getcwd()
print(dirpath)
print("Following files are uploaded ")
print(run.get_file_names())


print("Uploading the model into run artifacts  NEW **** ...")
local_run.upload_file(name="./outputs/models/" + model_filename, path_or_stream=model_path1)
local_run.upload_file("outputs/models/abc.pkl", path_or_stream=model_path1)
print("Uploaded the model {} to experiment {}".format(model_filename, local_run.experiment.name))
dirpath = os.getcwd()
print(dirpath)
print("Following files are uploaded ")
print(local_run.get_file_names())

run.complete()
Ajay Singh
  • 16
  • 4

0 Answers0