Skip to content

Allow to specify name argument in sagmaker.model.Model as a pipeline variable #4254

@lorenzwalthert

Description

@lorenzwalthert

Describe the feature you'd like

Create an unversioned sagemaker model in a pipeline that has a name parametrised at runtime. I.e. I have in my pipeline definition code:

model = sagemaker.model.Model(
  # ...
  name=sagemaker.workflow.execution_variables.ExecutionVariables.PIPELINE_EXECUTION_ID,
)

sagemaker.workflow.model_step.ModelStep(
  name="create_model",
  step_args=model.create(),
    )

This code intends to create an unversioned model where the name of the model is derived from the current pipeline execution.
However, since name has to be a string, the pipeline creation fails with

TypeError: can only concatenate str (not "ExecutionVariable") to str
```python Traceback (most recent call last): File "/my/proj/pipelines/run_pipeline.py", line 100, in main pipeline = get_pipeline_driver( ^^^^^^^^^^^^^^^^^^^^ File "/my/proj/pipelines/_utils.py", line 34, in get_pipeline_driver return _imports.get_pipeline(role_arn=role_arn, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/proj/pipelines/inference/pipeline.py", line 84, in get_pipeline step_create_model = proj.pipelines.inference.steps.create_model( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/proj/pipelines/inference/steps/step_model.py", line 20, in create_model step_args=model.create(instance_type="ml.m5.large"), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/workflow/pipeline_context.py", line 304, in wrapper run_func(*args, **kwargs) File "/my/python/lib/site-packages/sagemaker/model.py", line 552, in create self._create_sagemaker_model( File "/my/python/lib/site-packages/sagemaker/model.py", line 771, in _create_sagemaker_model container_def = self.prepare_container_def( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/model.py", line 598, in prepare_container_def deploy_key_prefix = fw_utils.model_code_key_prefix( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/fw_utils.py", line 603, in model_code_key_prefix return s3_path_join(code_location_key_prefix, model_name or name_from_image) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/s3_utils.py", line 90, in s3_path_join merged_path += path TypeError: can only concatenate str (not "ExecutionVariable") to str Traceback (most recent call last): File "/my/proj/pipelines/run_pipeline.py", line 100, in main pipeline = get_pipeline_driver( ^^^^^^^^^^^^^^^^^^^^ File "/my/proj/pipelines/_utils.py", line 34, in get_pipeline_driver return _imports.get_pipeline(role_arn=role_arn, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/proj/pipelines/inference/pipeline.py", line 84, in get_pipeline step_create_model = proj.pipelines.inference.steps.create_model( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/proj/pipelines/inference/steps/step_model.py", line 20, in create_model step_args=model.create(instance_type="ml.m5.large"), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/workflow/pipeline_context.py", line 304, in wrapper run_func(*args, **kwargs) File "/my/python/lib/site-packages/sagemaker/model.py", line 552, in create self._create_sagemaker_model( File "/my/python/lib/site-packages/sagemaker/model.py", line 771, in _create_sagemaker_model container_def = self.prepare_container_def( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/model.py", line 598, in prepare_container_def deploy_key_prefix = fw_utils.model_code_key_prefix( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/fw_utils.py", line 603, in model_code_key_prefix return s3_path_join(code_location_key_prefix, model_name or name_from_image) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/my/python/lib/site-packages/sagemaker/s3_utils.py", line 90, in s3_path_join merged_path += path TypeError: can only concatenate str (not "ExecutionVariable") to str ```

How would this feature be used? Please describe.
Currently, pipelines create models with non-deterministic names. This makes it impossible to properly reference later. Given the pipeline execution id, we can list all models with boto and filter by name, but that's not guaranteed to be the match we want and cumbersome. Tags are not returned by that API, so we can't use tags to filter and need another call to describe model to get tags, which are typed Dict[str, Union[str, PipelineVariable]], so it should be possible to pass a PipelineVariable.

Describe alternatives you've considered

Using list all models and filter by NameContains the pipeline execution id.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions