class_docstr: The SageMaker Debugger Rule class configures *debugging* rules to debug your training job.
  
  The debugging rules analyze tensor outputs from your training job
  and monitor conditions that are critical for the success of the training
  job.
  
  SageMaker Debugger comes pre-packaged with built-in *debugging* rules.
  For example, the debugging rules can detect whether gradients are getting too large or
  too small, or if a model is overfitting.
  For a full list of built-in rules for debugging, see
  `List of Debugger Built-in Rules
  <https://docs.aws.amazon.com/sagemaker/latest/dg/debugger-built-in-rules.html>`_.
  You can also write your own rules using the custom rule classmethod.
class_docstr_tok: ["The","SageMaker","Debugger","Rule","class","configures","*","debugging","*","rules","to","debug","your","training","job",".","The","debugging","rules","analyze","tensor","outputs","from","your","training","job","and","monitor","conditions","that","are","critical","for","the","success","of","the","training","job",".","SageMaker","Debugger","comes","pre-packaged","with","built-in","*","debugging","*","rules",".","For","example",",","the","debugging","rules","can","detect","whether","gradients","are","getting","too","large","or","too","small",",","or","if","a","model","is","overfitting",".","For","a","full","list","of","built-in","rules","for","debugging",",","see","`","List","of","Debugger","Built-in","Rules","<","https",":","\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/debugger-built-in-rules.html",">","`","_",".","You","can","also","write","your","own","rules","using","the","custom","rule","classmethod","."]
docstr: Initialize a ``Rule`` object for a *built-in* debugging rule.
  
  Args:
      base_config (dict): Required. This is the base rule config dictionary returned from the
          :class:`~sagemaker.debugger.rule_configs` method.
          For example, ``rule_configs.dead_relu()``.
          For a full list of built-in rules for debugging, see
          `List of Debugger Built-in Rules
          <https://docs.aws.amazon.com/sagemaker/latest/dg/debugger-built-in-rules.html>`_.
      name (str): Optional. The name of the debugger rule. If one is not provided,
          the name of the base_config will be used.
      container_local_output_path (str): Optional. The local path in the rule processing
          container.
      s3_output_path (str): Optional. The location in Amazon S3 to store the output tensors.
          The default Debugger output path for debugging data is created under the
          default output path of the :class:`~sagemaker.estimator.Estimator` class.
          For example,
          s3://sagemaker-<region>-<12digit_account_id>/<training-job-name>/debug-output/.
      other_trials_s3_input_paths ([str]): Optional. The Amazon S3 input paths
          of other trials to use the SimilarAcrossRuns rule.
      rule_parameters (dict): Optional. A dictionary of parameters for the rule.
      collections_to_save (:class:`~sagemaker.debugger.CollectionConfig`):
          Optional. A list
          of :class:`~sagemaker.debugger.CollectionConfig` objects to be saved.
  
  Returns:
      :class:`~sagemaker.debugger.Rule`: An instance of the built-in rule.
  
  **Example of how to create a built-in rule instance:**
  
  .. code-block:: python
  
      from sagemaker.debugger import Rule, rule_configs
  
      built_in_rules = [
          Rule.sagemaker(rule_configs.built_in_rule_name_in_pysdk_format_1()),
          Rule.sagemaker(rule_configs.built_in_rule_name_in_pysdk_format_2()),
          ...
          Rule.sagemaker(rule_configs.built_in_rule_name_in_pysdk_format_n())
      ]
  
  You need to replace the ``built_in_rule_name_in_pysdk_format_*`` with the
  names of built-in rules. You can find the rule names at `List of Debugger Built-in
  Rules <https://docs.aws.amazon.com/sagemaker/latest/dg/debugger-built-in-rules.html>`_.
  
  **Example of creating a built-in rule instance with adjusting parameter values:**
  
  .. code-block:: python
  
      from sagemaker.debugger import Rule, rule_configs
  
      built_in_rules = [
          Rule.sagemaker(
              base_config=rule_configs.built_in_rule_name_in_pysdk_format(),
              rule_parameters={
                      "key": "value"
              }
              collections_to_save=[
                  CollectionConfig(
                      name="tensor_collection_name",
                      parameters={
                          "key": "value"
                      }
                  )
              ]
          )
      ]
  
  For more information about setting up the ``rule_parameters`` parameter,
  see `List of Debugger Built-in
  Rules <https://docs.aws.amazon.com/sagemaker/latest/dg/debugger-built-in-rules.html>`_.
  
  For more information about setting up the ``collections_to_save`` parameter,
  see the :class:`~sagemaker.debugger.CollectionConfig` class.
code: def sagemaker(
      cls,
      base_config,
      name=None,
      container_local_output_path=None,
      s3_output_path=None,
      other_trials_s3_input_paths=None,
      rule_parameters=None,
      collections_to_save=None,
      actions=None,
  ):
      """Initialize a ``Rule`` object for a *built-in* debugging rule.
  
      Args:
          base_config (dict): Required. This is the base rule config dictionary returned from the
              :class:`~sagemaker.debugger.rule_configs` method.
              For example, ``rule_configs.dead_relu()``.
              For a full list of built-in rules for debugging, see
              `List of Debugger Built-in Rules
              <https://docs.aws.amazon.com/sagemaker/latest/dg/debugger-built-in-rules.html>`_.
          name (str): Optional. The name of the debugger rule. If one is not provided,
              the name of the base_config will be used.
          container_local_output_path (str): Optional. The local path in the rule processing
              container.
          s3_output_path (str): Optional. The location in Amazon S3 to store the output tensors.
              The default Debugger output path for debugging data is created under the
              default output path of the :class:`~sagemaker.estimator.Estimator` class.
              For example,
              s3://sagemaker-<region>-<12digit_account_id>/<training-job-name>/debug-output/.
          other_trials_s3_input_paths ([str]): Optional. The Amazon S3 input paths
              of other trials to use the SimilarAcrossRuns rule.
          rule_parameters (dict): Optional. A dictionary of parameters for the rule.
          collections_to_save (:class:`~sagemaker.debugger.CollectionConfig`):
              Optional. A list
              of :class:`~sagemaker.debugger.CollectionConfig` objects to be saved.
  
      Returns:
          :class:`~sagemaker.debugger.Rule`: An instance of the built-in rule.
  
      **Example of how to create a built-in rule instance:**
  
      .. code-block:: python
  
          from sagemaker.debugger import Rule, rule_configs
  
          built_in_rules = [
              Rule.sagemaker(rule_configs.built_in_rule_name_in_pysdk_format_1()),
              Rule.sagemaker(rule_configs.built_in_rule_name_in_pysdk_format_2()),
              ...
              Rule.sagemaker(rule_configs.built_in_rule_name_in_pysdk_format_n())
          ]
  
      You need to replace the ``built_in_rule_name_in_pysdk_format_*`` with the
      names of built-in rules. You can find the rule names at `List of Debugger Built-in
      Rules <https://docs.aws.amazon.com/sagemaker/latest/dg/debugger-built-in-rules.html>`_.
  
      **Example of creating a built-in rule instance with adjusting parameter values:**
  
      .. code-block:: python
  
          from sagemaker.debugger import Rule, rule_configs
  
          built_in_rules = [
              Rule.sagemaker(
                  base_config=rule_configs.built_in_rule_name_in_pysdk_format(),
                  rule_parameters={
                          "key": "value"
                  }
                  collections_to_save=[
                      CollectionConfig(
                          name="tensor_collection_name",
                          parameters={
                              "key": "value"
                          }
                      )
                  ]
              )
          ]
  
      For more information about setting up the ``rule_parameters`` parameter,
      see `List of Debugger Built-in
      Rules <https://docs.aws.amazon.com/sagemaker/latest/dg/debugger-built-in-rules.html>`_.
  
      For more information about setting up the ``collections_to_save`` parameter,
      see the :class:`~sagemaker.debugger.CollectionConfig` class.
  
      """
      merged_rule_params = {}
  
      if (
          rule_parameters is not None
          and rule_parameters.get("rule_to_invoke") is not None
      ):
          raise RuntimeError(
              """You cannot provide a 'rule_to_invoke' for SageMaker rules.
                  Either remove the rule_to_invoke or use a custom rule.
  
                  """
          )
  
      if (
          actions is not None
          and not rule_configs.is_valid_action_object(actions)
      ):
          raise RuntimeError(
              """`actions` must be of type `Action` or `ActionList`!"""
          )
  
      if other_trials_s3_input_paths is not None:
          for index, s3_input_path in enumerate(
              other_trials_s3_input_paths
          ):
              merged_rule_params[
                  "other_trial_{}".format(str(index))
              ] = s3_input_path
  
      default_rule_params = base_config["DebugRuleConfiguration"].get(
          "RuleParameters", {}
      )
      merged_rule_params.update(default_rule_params)
      merged_rule_params.update(rule_parameters or {})
  
      base_config_collections = []
      for config in base_config.get("CollectionConfigurations", []):
          collection_name = None
          collection_parameters = {}
          for key, value in config.items():
              if key == "CollectionName":
                  collection_name = value
              if key == "CollectionParameters":
                  collection_parameters = value
          base_config_collections.append(
              CollectionConfig(
                  name=collection_name, parameters=collection_parameters
              )
          )
  
      return cls(
          name=name
          or base_config["DebugRuleConfiguration"].get(
              "RuleConfigurationName"
          ),
          image_uri="DEFAULT_RULE_EVALUATOR_IMAGE",
          instance_type=None,
          container_local_output_path=container_local_output_path,
          s3_output_path=s3_output_path,
          volume_size_in_gb=None,
          rule_parameters=merged_rule_params,
          collections_to_save=collections_to_save
          or base_config_collections,
          actions=actions,
      )
  
imports: from __future__ import absolute_import
  from abc import ABC
  from typing import Union, Optional, List, Dict
  import attr
  import smdebug_rulesconfig
  from sagemaker import image_uris
  from sagemaker.utils import build_dict, name_from_base
  from sagemaker.workflow.entities import PipelineVariable
  from sagemaker.debugger.profiler_constants import DETAIL_PROF_PROCESSING_DEFAULT_INSTANCE_TYPE, DETAIL_PROF_PROCESSING_DEFAULT_VOLUME_SIZE
label_desc: Use image node_id 2 for calling the Rule obj's underlying member method code with example usage: obj.sagemaker(cls, base_config, name, container_local_output_path, s3_output_path, other_trials_s3_input_paths, rule_parameters, collections_to_save, actions) and returns: cls