-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roopa G
committed
Dec 2, 2024
1 parent
5de9a42
commit 74de879
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
assets/training/model_management/components/condition_block/asset.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type: component | ||
spec: spec.yaml | ||
categories: ["Models"] |
34 changes: 34 additions & 0 deletions
34
assets/training/model_management/components/condition_block/spec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
$schema: https://azuremlschemas.azureedge.net/latest/commandComponent.schema.json | ||
|
||
name: condition_block | ||
version: 0.0.1 | ||
type: command | ||
|
||
is_deterministic: True | ||
|
||
display_name: Condition Block | ||
description: Component takes a condition and executes the command based on the condition. | ||
|
||
environment: azureml://registries/azureml/environments/model-management/versions/34 | ||
|
||
code: ../../src/ | ||
command: | | ||
set -ex | ||
IFS=',' read -ra input_args <<< "${{inputs.args}}" | ||
echo "Running condition block ..." | ||
python -u run_condition_block.py --condition ${{inputs.condition}} --input-args "${{inputs.args}}" | ||
echo "Completed condition block ... " | ||
inputs: | ||
condition: | ||
type: string | ||
description: Input condition. | ||
optional: false | ||
|
||
extra_pip_requirements: | ||
type: string | ||
description: | | ||
Input arguments. | ||
Arguments expressed as below. Do not use quotes for passing. | ||
eg: a==1.0, b==1 | ||
optional: false |
58 changes: 58 additions & 0 deletions
58
assets/training/model_management/src/run_condition_block.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
"""Run Model preprocessor module.""" | ||
|
||
import argparse | ||
import os | ||
import json | ||
import shutil | ||
from azureml.model.mgmt.config import AppName, ModelFramework | ||
from azureml.model.mgmt.processors.transformers.config import HF_CONF | ||
from azureml.model.mgmt.processors.preprocess import run_preprocess, check_for_py_files | ||
from azureml.model.mgmt.processors.transformers.config import SupportedTasks as TransformersSupportedTasks | ||
from azureml.model.mgmt.processors.pyfunc.config import SupportedTasks as PyFuncSupportedTasks | ||
from azureml.model.mgmt.utils.exceptions import swallow_all_exceptions, UnsupportedTaskType | ||
from azureml._common.exceptions import AzureMLException | ||
from azureml._common._error_definition.azureml_error import AzureMLError | ||
from azureml.model.mgmt.utils.logging_utils import custom_dimensions, get_logger | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
import json | ||
|
||
|
||
logger = get_logger(__name__) | ||
custom_dimensions.app_name = AppName.CONVERT_MODEL_TO_MLFLOW | ||
|
||
|
||
def _get_parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--condition", type=str, required=True, help="Condition") | ||
parser.add_argument( | ||
"--input-args", | ||
type=str, | ||
required=True, | ||
help="Input args", | ||
) | ||
return parser | ||
|
||
|
||
@swallow_all_exceptions(logger) | ||
def run(): | ||
"""Run preprocess.""" | ||
parser = _get_parser() | ||
args, _ = parser.parse_known_args() | ||
|
||
input_args = args.input_args | ||
condition = args.condition | ||
input_args = json.loads(input_args) | ||
result = None | ||
try: | ||
result = eval(condition, input_args) | ||
except Exception as e: | ||
logger.error(f"Error evaluating condition: {e}") | ||
result = False | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |