class_docstr: `ModelStep` for SageMaker Pipelines Workflows.
class_docstr_tok: ["`","ModelStep","`","for","SageMaker","Pipelines","Workflows","."]
docstr: Constructs a `ModelStep`.
  
  Args:
      name (str): The name of the `ModelStep`. A name is required and must be
          unique within a pipeline.
      step_args (_ModelStepArguments): The arguments for the `ModelStep` definition,
          generated by invoking the :func:`~sagemaker.model.Model.register` or
          :func:`~sagemaker.model.Model.create`
          under the :class:`~sagemaker.workflow.pipeline_context.PipelineSession`. Example::
  
               model = Model(sagemaker_session=PipelineSession())
               model_step = ModelStep(step_args=model.register())
  
      depends_on (List[Union[str, Step, StepCollection]]):
          A list of `Step` or `StepCollection`
          names or `Step` instances or `StepCollection` instances that it depends on.
          If a listed `Step` name does not exist, an error is returned (default: None).
      retry_policies (List[RetryPolicy] or Dict[str, List[RetryPolicy]]): The list of retry
          policies for the `ModelStep` (default: None).
  
          If a list of retry policies is provided, it would be applied to all steps in the
          `ModelStep` collection. Note: in this case, `SageMakerJobStepRetryPolicy`
          is not allowed, since create/register model step does not support it.
          Please find the example below:
  
          .. code:: python
  
              ModelStep(
                  ...
                  retry_policies=[
                      StepRetryPolicy(...),
                  ],
              )
  
          If a dict is provided, it can specify different retry policies for different
          types of steps in the `ModelStep` collection. Similarly,
          `SageMakerJobStepRetryPolicy` is not allowed for create/register model step.
          See examples below:
  
          .. code:: python
  
              ModelStep(
                  ...
                  retry_policies=dict(
                     register_model_retry_policies=[
                         StepRetryPolicy(...),
                     ],
                     repack_model_retry_policies=[
                         SageMakerJobStepRetryPolicy(...),
                     ],
                  )
              )
  
          or
  
          .. code:: python
  
              ModelStep(
                  ...
                  retry_policies=dict(
                     create_model_retry_policies=[
                         StepRetryPolicy(...),
                     ],
                     repack_model_retry_policies=[
                         SageMakerJobStepRetryPolicy(...),
                     ],
                  )
              )
  
      display_name (str): The display name of the `ModelStep`.
          The display name provides better UI readability. (default: None).
      description (str): The description of the `ModelStep` (default: None).
      repack_model_step_settings (Dict[str, any]): The kwargs passed to the _RepackModelStep
          to customize the configuration of the underlying repack model job (default: None).
          Notes:
              1. If the _RepackModelStep is unnecessary, the settings will be ignored.
              2. If the _RepackModelStep is added, the repack_model_step_settings
                  is honored if set.
              3. In repack_model_step_settings, the arguments with misspelled keys will be
                  ignored. Please refer to the expected parameters of repack model job in
                  :class:`~sagemaker.sklearn.estimator.SKLearn` and its base classes.
docstr_tok: ["Constructs","a","`","ModelStep","`",".","Args",":","name","(","str",")",":","The","name","of","the","`","ModelStep","`",".","A","name","is","required","and","must","be","unique","within","a","pipeline",".","step_args","(","_ModelStepArguments",")",":","The","arguments","for","the","`","ModelStep","`","definition",",","generated","by","invoking","the",":","func",":","`","~sagemaker.model.Model.register","`","or",":","func",":","`","~sagemaker.model.Model.create","`","under","the",":","class",":","`","~sagemaker.workflow.pipeline_context.PipelineSession","`",".","Example",":",":","model","=","Model","(","sagemaker_session=PipelineSession","(",")",")","model_step","=","ModelStep","(","step_args=model.register","(",")",")","depends_on","(","List","[","Union","[","str",",","Step",",","StepCollection","]","]",")",":","A","list","of","`","Step","`","or","`","StepCollection","`","names","or","`","Step","`","instances","or","`","StepCollection","`","instances","that","it","depends","on",".","If","a","listed","`","Step","`","name","does","not","exist",",","an","error","is","returned","(","default",":","None",")",".","retry_policies","(","List","[","RetryPolicy","]","or","Dict","[","str",",","List","[","RetryPolicy","]","]",")",":","The","list","of","retry","policies","for","the","`","ModelStep","`","(","default",":","None",")",".","If","a","list","of","retry","policies","is","provided",",","it","would","be","applied","to","all","steps","in","the","`","ModelStep","`","collection",".","Note",":","in","this","case",",","`","SageMakerJobStepRetryPolicy","`","is","not","allowed",",","since","create\/register","model","step","does","not","support","it",".","Please","find","the","example","below",":","..","code",":",":","python","ModelStep","(","...","retry_policies=","[","StepRetryPolicy","(","...",")",",","]",",",")","If","a","dict","is","provided",",","it","can","specify","different","retry","policies","for","different","types","of","steps","in","the","`","ModelStep","`","collection",".","Similarly",",","`","SageMakerJobStepRetryPolicy","`","is","not","allowed","for","create\/register","model","step",".","See","examples","below",":","..","code",":",":","python","ModelStep","(","...","retry_policies=dict","(","register_model_retry_policies=","[","StepRetryPolicy","(","...",")",",","]",",","repack_model_retry_policies=","[","SageMakerJobStepRetryPolicy","(","...",")",",","]",",",")",")","or","..","code",":",":","python","ModelStep","(","...","retry_policies=dict","(","create_model_retry_policies=","[","StepRetryPolicy","(","...",")",",","]",",","repack_model_retry_policies=","[","SageMakerJobStepRetryPolicy","(","...",")",",","]",",",")",")","display_name","(","str",")",":","The","display","name","of","the","`","ModelStep","`",".","The","display","name","provides","better","UI","readability",".","(","default",":","None",")",".","description","(","str",")",":","The","description","of","the","`","ModelStep","`","(","default",":","None",")",".","repack_model_step_settings","(","Dict","[","str",",","any","]",")",":","The","kwargs","passed","to","the","_RepackModelStep","to","customize","the","configuration","of","the","underlying","repack","model","job","(","default",":","None",")",".","Notes",":","1",".","If","the","_RepackModelStep","is","unnecessary",",","the","settings","will","be","ignored",".","2",".","If","the","_RepackModelStep","is","added",",","the","repack_model_step_settings","is","honored","if","set",".","3",".","In","repack_model_step_settings",",","the","arguments","with","misspelled","keys","will","be","ignored",".","Please","refer","to","the","expected","parameters","of","repack","model","job","in",":","class",":","`","~sagemaker.sklearn.estimator.SKLearn","`","and","its","base","classes","."]
code: def __init__(
      self,
      name: str,
      step_args: _ModelStepArguments,
      depends_on: Optional[
          List[Union[str, Step, StepCollection]]
      ] = None,
      retry_policies: Optional[
          Union[List[RetryPolicy], Dict[str, List[RetryPolicy]]]
      ] = None,
      display_name: Optional[str] = None,
      description: Optional[str] = None,
      repack_model_step_settings: Optional[Dict[str, any]] = None,
  ):
      """Constructs a `ModelStep`.
  
      Args:
          name (str): The name of the `ModelStep`. A name is required and must be
              unique within a pipeline.
          step_args (_ModelStepArguments): The arguments for the `ModelStep` definition,
              generated by invoking the :func:`~sagemaker.model.Model.register` or
              :func:`~sagemaker.model.Model.create`
              under the :class:`~sagemaker.workflow.pipeline_context.PipelineSession`. Example::
  
                   model = Model(sagemaker_session=PipelineSession())
                   model_step = ModelStep(step_args=model.register())
  
          depends_on (List[Union[str, Step, StepCollection]]):
              A list of `Step` or `StepCollection`
              names or `Step` instances or `StepCollection` instances that it depends on.
              If a listed `Step` name does not exist, an error is returned (default: None).
          retry_policies (List[RetryPolicy] or Dict[str, List[RetryPolicy]]): The list of retry
              policies for the `ModelStep` (default: None).
  
              If a list of retry policies is provided, it would be applied to all steps in the
              `ModelStep` collection. Note: in this case, `SageMakerJobStepRetryPolicy`
              is not allowed, since create/register model step does not support it.
              Please find the example below:
  
              .. code:: python
  
                  ModelStep(
                      ...
                      retry_policies=[
                          StepRetryPolicy(...),
                      ],
                  )
  
              If a dict is provided, it can specify different retry policies for different
              types of steps in the `ModelStep` collection. Similarly,
              `SageMakerJobStepRetryPolicy` is not allowed for create/register model step.
              See examples below:
  
              .. code:: python
  
                  ModelStep(
                      ...
                      retry_policies=dict(
                         register_model_retry_policies=[
                             StepRetryPolicy(...),
                         ],
                         repack_model_retry_policies=[
                             SageMakerJobStepRetryPolicy(...),
                         ],
                      )
                  )
  
              or
  
              .. code:: python
  
                  ModelStep(
                      ...
                      retry_policies=dict(
                         create_model_retry_policies=[
                             StepRetryPolicy(...),
                         ],
                         repack_model_retry_policies=[
                             SageMakerJobStepRetryPolicy(...),
                         ],
                      )
                  )
  
          display_name (str): The display name of the `ModelStep`.
              The display name provides better UI readability. (default: None).
          description (str): The description of the `ModelStep` (default: None).
          repack_model_step_settings (Dict[str, any]): The kwargs passed to the _RepackModelStep
              to customize the configuration of the underlying repack model job (default: None).
              Notes:
                  1. If the _RepackModelStep is unnecessary, the settings will be ignored.
                  2. If the _RepackModelStep is added, the repack_model_step_settings
                      is honored if set.
                  3. In repack_model_step_settings, the arguments with misspelled keys will be
                      ignored. Please refer to the expected parameters of repack model job in
                      :class:`~sagemaker.sklearn.estimator.SKLearn` and its base classes.
      """
      from sagemaker.workflow.utilities import validate_step_args_input
  
      validate_step_args_input(
          step_args=step_args,
          expected_caller={
              Session.create_model.__name__,
              Session.create_model_package_from_containers.__name__,
          },
          error_message="The step_args of ModelStep must be obtained from model.create() "
          "or model.register(). For more, see: https://sagemaker.readthedocs.io/en/stable/"
          "amazon_sagemaker_model_building_pipeline.html#model-step",
      )
      if not (step_args.create_model_request is None) ^ (
          step_args.create_model_package_request is None
      ):
          raise ValueError(
              "Invalid step_args: either _register_model_args or _create_model_args"
              " should be provided. They are mutually exclusive. Please use the model's "
              ".create() or .register() method to generate the step_args under PipelineSession."
          )
      if not isinstance(
          step_args.model.sagemaker_session, PipelineSession
      ):
          raise TypeError(
              "To correctly configure a ModelStep, "
              "the sagemaker_session of the model must be a PipelineSession object."
          )
  
      super().__init__(name=name, depends_on=depends_on)
      self.step_args = step_args
      self.retry_policies = retry_policies
      self.display_name = display_name
      self.description = description
      self.steps: List[Step] = []
      self._repack_model_step_settings = (
          dict(repack_model_step_settings)
          if repack_model_step_settings
          else {}
      )
      self._model = step_args.model
      self._create_model_args = self.step_args.create_model_request
      self._register_model_args = (
          self.step_args.create_model_package_request
      )
      self._need_runtime_repack = self.step_args.need_runtime_repack
      self._runtime_repack_output_prefix = (
          self.step_args.runtime_repack_output_prefix
      )
      self._assign_and_validate_retry_policies(retry_policies)
  
      if self._need_runtime_repack:
          self._append_repack_model_step()
      elif self._repack_model_step_settings:
          logger.warning(
              "Non-empty repack_model_step_settings is supplied but no repack model "
              "step is needed. Ignoring the repack_model_step_settings."
          )
  
      if self._register_model_args:
          self._append_register_model_step()
      else:
          self._append_create_model_step()
  
file_path: sagemaker-python-sdk/src/sagemaker/workflow/model_step.py
imports: from __future__ import absolute_import
  import logging
  from typing import Union, List, Dict, Optional
  from sagemaker import Model, PipelineModel, Session
  from sagemaker.workflow._utils import _RegisterModelStep, _RepackModelStep
  from sagemaker.workflow.pipeline_context import PipelineSession, _ModelStepArguments
  from sagemaker.workflow.retry import RetryPolicy, SageMakerJobStepRetryPolicy
  from sagemaker.workflow.step_collections import StepCollection
  from sagemaker.workflow.steps import Step, CreateModelStep
label_desc: Use image node_id 1 to create a new ModelStep object from inherited base classes: StepCollection with example: obj = ModelStep(name, step_args, depends_on, retry_policies, display_name, description, repack_model_step_settings)