Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/ml/azure-ai-ml/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@

### Features Added

- First preview.
- First preview.
10 changes: 10 additions & 0 deletions sdk/ml/azure-ai-ml/azure/ai/ml/entities/_builders/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ def _to_job(self) -> SweepJob:
def _get_component_attr_name(cls):
return "trial"

def _build_inputs(self):
inputs = super(Sweep, self)._build_inputs()
built_inputs = {}
# Validate and remove non-specified inputs
for key, value in inputs.items():
if value is not None:
built_inputs[key] = value

return built_inputs

@classmethod
def _create_schema_for_validation(cls, context) -> Union[PathAwareSchema, Schema]:
from azure.ai.ml._schema.pipeline.component_job import SweepSchema
Expand Down
30 changes: 30 additions & 0 deletions sdk/ml/azure-ai-ml/tests/dsl/unittests/test_dsl_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2136,3 +2136,33 @@ def spark_pipeline_from_yaml(iris_data):
"outputs": {"output": {"job_output_type": "uri_folder", "mode": "Direct"}},
"settings": {"_source": "DSL"},
}

def test_node_sweep_with_optional_input(self) -> None:
component_yaml = components_dir / "helloworld_component_optional_input.yml"
component_func = load_component(component_yaml)

@dsl.pipeline
def pipeline_func():
node1 = component_func(required_input=1, optional_input=2) # noqa: F841
node2 = component_func(required_input=1) # noqa: F841
node3 = component_func(required_input=1)
node_sweep = node3.sweep(
primary_metric="training_f1_score",
goal="minimize",
sampling_algorithm="random",
)
node_sweep.set_limits(
max_total_trials=20,
max_concurrent_trials=10,
)

pipeline_job = pipeline_func()
jobs_dict = pipeline_job._to_rest_object().as_dict()["properties"]["jobs"]
# for node1 inputs, should contain required_input and optional_input;
# while for node2 and node_sweep, should only contain required_input.
assert jobs_dict["node1"]["inputs"] == {
"required_input": {"job_input_type": "literal", "value": "1"},
"optional_input": {"job_input_type": "literal", "value": "2"},
}
assert jobs_dict["node2"]["inputs"] == {"required_input": {"job_input_type": "literal", "value": "1"}}
assert jobs_dict["node_sweep"]["inputs"] == {"required_input": {"job_input_type": "literal", "value": "1"}}
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,6 @@ def mock_get_asset_arm_id(*args, **kwargs):
"tests/test_configs/pipeline_jobs/pipeline_job_with_sweep_job_with_input_bindings.yml",
{
"hello_world": {
"component_in_number": {
"job_input_type": "literal",
},
Comment thread
zhengfeiwang marked this conversation as resolved.
"test1": {
"job_input_type": "literal",
"value": "${{parent.inputs.job_data_path}}",
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
name: helloworld_component_optional_input
command: ls
inputs:
required_input:
type: integer
optional: false
optional_input:
type: integer
optional: true
environment:
image: library/python:latest
compute: azureml:cpu-cluster