class_docstr: Handle end-to-end training and deployment of user-provided TensorFlow code.
class_docstr_tok: ["Handle","end-to-end","training","and","deployment","of","user-provided","TensorFlow","code","."]
docstr: Initialize a ``TensorFlow`` estimator.
  
  Args:
      py_version (str): Python version you want to use for executing your model training
          code. Defaults to ``None``. Required unless ``image_uri`` is provided.
      framework_version (str): TensorFlow version you want to use for executing your model
          training code. Defaults to ``None``. Required unless ``image_uri`` is provided.
          List of supported versions:
          https://aws.amazon.com/releasenotes/available-deep-learning-containers-images/.
      model_dir (str or PipelineVariable): S3 location where the checkpoint data and models
          can be exported to during training (default: None). It will be passed in the
          training script as one of the command line arguments. If not specified,
          one is provided based on your training configuration:
  
          * *distributed training with SMDistributed or MPI with Horovod* - ``/opt/ml/model``
          * *single-machine training or distributed training without MPI* -                     ``s3://{output_path}/model``
          * *Local Mode with local sources (file:// instead of s3://)* -                     ``/opt/ml/shared/model``
  
          To disable having ``model_dir`` passed to your training script,
          set ``model_dir=False``.
      image_uri (str or PipelineVariable): If specified, the estimator will use this image
          for training and hosting, instead of selecting the appropriate SageMaker official
          image based on framework_version and py_version.
          It can be an ECR url or dockerhub image and tag.
  
          Examples:
              123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
              custom-image:latest.
  
          If ``framework_version`` or ``py_version`` are ``None``, then
          ``image_uri`` is required. If also ``None``, then a ``ValueError``
          will be raised.
      distribution (dict): A dictionary with information on how to run distributed training
          (default: None).
  
          **To enable Multi Worker Mirrored Strategy:**
  
              .. code:: python
  
                  {
                      "multi_worker_mirrored_strategy": {
                          "enabled": True
                      }
                  }
  
              This distribution strategy option is available for TensorFlow 2.9 and later in
              the SageMaker Python SDK v2.xx.yy and later.
              To learn more about the mirrored strategy for TensorFlow,
              see `TensorFlow Distributed Training
              <https://www.tensorflow.org/guide/distributed_training>`_
              in the *TensorFlow documentation*.
  
          **To enable MPI:**
  
              .. code:: python
  
                  {
                      "mpi": {
                          "enabled": True
                      }
                  }
  
              To learn more, see `Training with Horovod
              <https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/using_tf.html#training-with-horovod>`_.
  
          **To enable parameter server:**
  
              .. code:: python
  
                  {
                      "parameter_server": {
                          "enabled": True
                      }
                  }
  
              To learn more, see `Training with parameter servers
              <https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/using_tf.html#training-with-parameter-servers>`_.
  
          .. note::
  
              The SageMaker distributed data parallelism (SMDDP) library
              discontinued support for TensorFlow.
              The documentation for the SMDDP library v1.x is still available at
              `Use the SMDDP library in your TensorFlow training script (deprecated)
              <https://docs.aws.amazon.com/sagemaker/latest/dg/data-parallel-modify-sdp-tf2.html>`_
              in the *Amazon SageMaker User Guide*,
              and the `SMDDP v1 API reference in the
              SageMaker Python SDK v2.199.0 documentation
              <https://sagemaker.readthedocs.io/en/v2.199.0/api/training/distributed.html#the-sagemaker-distributed-data-parallel-library>`_.
  
          .. note::
  
              The SageMaker model parallelism (SMP) library v2 discontinued support
              for TensorFlow.
              The documentation for the SMP library v1.x is archived and available at
              `Run distributed training with the SageMaker model parallelism library
              <https://docs.aws.amazon.com/sagemaker/latest/dg/model-parallel.html>`_
              in the *Amazon SageMaker User Guide*,
              and the `SMP v1 API reference in the
              SageMaker Python SDK v2.199.0 documentation
              <https://sagemaker.readthedocs.io/en/v2.199.0/api/training/distributed.html#the-sagemaker-distributed-model-parallel-library>`_.
  
      compiler_config (:class:`~sagemaker.tensorflow.TrainingCompilerConfig`):
          Configures SageMaker Training Compiler to accelerate training.
  
      **kwargs: Additional kwargs passed to the Framework constructor.
  
  .. tip::
  
      You can find additional parameters for initializing this class at
      :class:`~sagemaker.estimator.Framework` and
      :class:`~sagemaker.estimator.EstimatorBase`.
docstr_tok: ["Initialize","a","``","TensorFlow","``","estimator",".","Args",":","py_version","(","str",")",":","Python","version","you","want","to","use","for","executing","your","model","training","code",".","Defaults","to","``","None","``",".","Required","unless","``","image_uri","``","is","provided",".","framework_version","(","str",")",":","TensorFlow","version","you","want","to","use","for","executing","your","model","training","code",".","Defaults","to","``","None","``",".","Required","unless","``","image_uri","``","is","provided",".","List","of","supported","versions",":","https",":","\/\/aws.amazon.com\/releasenotes\/available-deep-learning-containers-images\/",".","model_dir","(","str","or","PipelineVariable",")",":","S3","location","where","the","checkpoint","data","and","models","can","be","exported","to","during","training","(","default",":","None",")",".","It","will","be","passed","in","the","training","script","as","one","of","the","command","line","arguments",".","If","not","specified",",","one","is","provided","based","on","your","training","configuration",":","*","*","distributed","training","with","SMDistributed","or","MPI","with","Horovod","*","-","``","\/opt\/ml\/model","``","*","*","single-machine","training","or","distributed","training","without","MPI","*","-","``","s3",":","\/\/","{","output_path","}","\/model","``","*","*","Local","Mode","with","local","sources","(","file",":","\/\/","instead","of","s3",":","\/\/",")","*","-","``","\/opt\/ml\/shared\/model","``","To","disable","having","``","model_dir","``","passed","to","your","training","script",",","set","``","model_dir=False","``",".","image_uri","(","str","or","PipelineVariable",")",":","If","specified",",","the","estimator","will","use","this","image","for","training","and","hosting",",","instead","of","selecting","the","appropriate","SageMaker","official","image","based","on","framework_version","and","py_version",".","It","can","be","an","ECR","url","or","dockerhub","image","and","tag",".","Examples",":","123.dkr.ecr.us-west-2.amazonaws.com\/my-custom-image:1.0","custom-image",":","latest",".","If","``","framework_version","``","or","``","py_version","``","are","``","None","``",",","then","``","image_uri","``","is","required",".","If","also","``","None","``",",","then","a","``","ValueError","``","will","be","raised",".","distribution","(","dict",")",":","A","dictionary","with","information","on","how","to","run","distributed","training","(","default",":","None",")",".","*","*","To","enable","Multi","Worker","Mirrored","Strategy",":","*","*","..","code",":",":","python","{","``","multi_worker_mirrored_strategy","''",":","{","``","enabled","''",":","True","}","}","This","distribution","strategy","option","is","available","for","TensorFlow","2.9","and","later","in","the","SageMaker","Python","SDK","v2.xx.yy","and","later",".","To","learn","more","about","the","mirrored","strategy","for","TensorFlow",",","see","`","TensorFlow","Distributed","Training","<","https",":","\/\/www.tensorflow.org\/guide\/distributed_training",">","`","_","in","the","*","TensorFlow","documentation","*",".","*","*","To","enable","MPI",":","*","*","..","code",":",":","python","{","``","mpi","''",":","{","``","enabled","''",":","True","}","}","To","learn","more",",","see","`","Training","with","Horovod","<","https",":","\/\/sagemaker.readthedocs.io\/en\/stable\/frameworks\/tensorflow\/using_tf.html","#","training-with-horovod",">","`","_",".","*","*","To","enable","parameter","server",":","*","*","..","code",":",":","python","{","``","parameter_server","''",":","{","``","enabled","''",":","True","}","}","To","learn","more",",","see","`","Training","with","parameter","servers","<","https",":","\/\/sagemaker.readthedocs.io\/en\/stable\/frameworks\/tensorflow\/using_tf.html","#","training-with-parameter-servers",">","`","_",".","..","note",":",":","The","SageMaker","distributed","data","parallelism","(","SMDDP",")","library","discontinued","support","for","TensorFlow",".","The","documentation","for","the","SMDDP","library","v1.x","is","still","available","at","`","Use","the","SMDDP","library","in","your","TensorFlow","training","script","(","deprecated",")","<","https",":","\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/data-parallel-modify-sdp-tf2.html",">","`","_","in","the","*","Amazon","SageMaker","User","Guide","*",",","and","the","`","SMDDP","v1","API","reference","in","the","SageMaker","Python","SDK","v2.199.0","documentation","<","https",":","\/\/sagemaker.readthedocs.io\/en\/v2.199.0\/api\/training\/distributed.html","#","the-sagemaker-distributed-data-parallel-library",">","`","_",".","..","note",":",":","The","SageMaker","model","parallelism","(","SMP",")","library","v2","discontinued","support","for","TensorFlow",".","The","documentation","for","the","SMP","library","v1.x","is","archived","and","available","at","`","Run","distributed","training","with","the","SageMaker","model","parallelism","library","<","https",":","\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/model-parallel.html",">","`","_","in","the","*","Amazon","SageMaker","User","Guide","*",",","and","the","`","SMP","v1","API","reference","in","the","SageMaker","Python","SDK","v2.199.0","documentation","<","https",":","\/\/sagemaker.readthedocs.io\/en\/v2.199.0\/api\/training\/distributed.html","#","the-sagemaker-distributed-model-parallel-library",">","`","_",".","compiler_config","(",":","class",":","`","~sagemaker.tensorflow.TrainingCompilerConfig","`",")",":","Configures","SageMaker","Training","Compiler","to","accelerate","training",".","*","*","kwargs",":","Additional","kwargs","passed","to","the","Framework","constructor",".","..","tip",":",":","You","can","find","additional","parameters","for","initializing","this","class","at",":","class",":","`","~sagemaker.estimator.Framework","`","and",":","class",":","`","~sagemaker.estimator.EstimatorBase","`","."]
code: def __init__(
      self,
      py_version: Optional[str] = None,
      framework_version: Optional[str] = None,
      model_dir: Optional[Union[str, PipelineVariable]] = None,
      image_uri: Optional[Union[str, PipelineVariable]] = None,
      distribution: Optional[Dict[str, str]] = None,
      compiler_config: Optional[TrainingCompilerConfig] = None,
      **kwargs,
  ):
      """Initialize a ``TensorFlow`` estimator.
  
          Args:
              py_version (str): Python version you want to use for executing your model training
                  code. Defaults to ``None``. Required unless ``image_uri`` is provided.
              framework_version (str): TensorFlow version you want to use for executing your model
                  training code. Defaults to ``None``. Required unless ``image_uri`` is provided.
                  List of supported versions:
                  https://aws.amazon.com/releasenotes/available-deep-learning-containers-images/.
              model_dir (str or PipelineVariable): S3 location where the checkpoint data and models
                  can be exported to during training (default: None). It will be passed in the
                  training script as one of the command line arguments. If not specified,
                  one is provided based on your training configuration:
  
                  * *distributed training with SMDistributed or MPI with Horovod* - ``/opt/ml/model``
                  * *single-machine training or distributed training without MPI* - \
                      ``s3://{output_path}/model``
                  * *Local Mode with local sources (file:// instead of s3://)* - \
                      ``/opt/ml/shared/model``
  
                  To disable having ``model_dir`` passed to your training script,
                  set ``model_dir=False``.
              image_uri (str or PipelineVariable): If specified, the estimator will use this image
                  for training and hosting, instead of selecting the appropriate SageMaker official
                  image based on framework_version and py_version.
                  It can be an ECR url or dockerhub image and tag.
  
                  Examples:
                      123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
                      custom-image:latest.
  
                  If ``framework_version`` or ``py_version`` are ``None``, then
                  ``image_uri`` is required. If also ``None``, then a ``ValueError``
                  will be raised.
              distribution (dict): A dictionary with information on how to run distributed training
                  (default: None).
  
                  **To enable Multi Worker Mirrored Strategy:**
  
                      .. code:: python
  
                          {
                              "multi_worker_mirrored_strategy": {
                                  "enabled": True
                              }
                          }
  
                      This distribution strategy option is available for TensorFlow 2.9 and later in
                      the SageMaker Python SDK v2.xx.yy and later.
                      To learn more about the mirrored strategy for TensorFlow,
                      see `TensorFlow Distributed Training
                      <https://www.tensorflow.org/guide/distributed_training>`_
                      in the *TensorFlow documentation*.
  
                  **To enable MPI:**
  
                      .. code:: python
  
                          {
                              "mpi": {
                                  "enabled": True
                              }
                          }
  
                      To learn more, see `Training with Horovod
                      <https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/using_tf.html#training-with-horovod>`_.
  
                  **To enable parameter server:**
  
                      .. code:: python
  
                          {
                              "parameter_server": {
                                  "enabled": True
                              }
                          }
  
                      To learn more, see `Training with parameter servers
                      <https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/using_tf.html#training-with-parameter-servers>`_.
  
                  .. note::
  
                      The SageMaker distributed data parallelism (SMDDP) library
                      discontinued support for TensorFlow.
                      The documentation for the SMDDP library v1.x is still available at
                      `Use the SMDDP library in your TensorFlow training script (deprecated)
                      <https://docs.aws.amazon.com/sagemaker/latest/dg/data-parallel-modify-sdp-tf2.html>`_
                      in the *Amazon SageMaker User Guide*,
                      and the `SMDDP v1 API reference in the
                      SageMaker Python SDK v2.199.0 documentation
                      <https://sagemaker.readthedocs.io/en/v2.199.0/api/training/distributed.html#the-sagemaker-distributed-data-parallel-library>`_.
  
                  .. note::
  
                      The SageMaker model parallelism (SMP) library v2 discontinued support
                      for TensorFlow.
                      The documentation for the SMP library v1.x is archived and available at
                      `Run distributed training with the SageMaker model parallelism library
                      <https://docs.aws.amazon.com/sagemaker/latest/dg/model-parallel.html>`_
                      in the *Amazon SageMaker User Guide*,
                      and the `SMP v1 API reference in the
                      SageMaker Python SDK v2.199.0 documentation
                      <https://sagemaker.readthedocs.io/en/v2.199.0/api/training/distributed.html#the-sagemaker-distributed-model-parallel-library>`_.
  
              compiler_config (:class:`~sagemaker.tensorflow.TrainingCompilerConfig`):
                  Configures SageMaker Training Compiler to accelerate training.
  
              **kwargs: Additional kwargs passed to the Framework constructor.
  
          .. tip::
  
              You can find additional parameters for initializing this class at
              :class:`~sagemaker.estimator.Framework` and
              :class:`~sagemaker.estimator.EstimatorBase`.
          """
      distribution = renamed_kwargs(
          "distributions", "distribution", distribution, kwargs
      )
      instance_type = renamed_kwargs(
          "train_instance_type",
          "instance_type",
          kwargs.get("instance_type"),
          kwargs,
      )
      fw.validate_version_or_image_args(
          framework_version, py_version, image_uri
      )
      if py_version == "py2":
          logger.warning(
              fw.python_deprecation_warning(
                  self._framework_name, defaults.LATEST_PY2_VERSION
              )
          )
      self.framework_version = framework_version
      self.py_version = py_version
      self.instance_type = instance_type
  
      if "enable_sagemaker_metrics" not in kwargs:
          # enable sagemaker metrics for TF v1.15 or greater:
          if framework_version and version.Version(
              framework_version
          ) >= version.Version("1.15"):
              kwargs["enable_sagemaker_metrics"] = True
  
      super(TensorFlow, self).__init__(image_uri=image_uri, **kwargs)
      if distribution is not None:
          distribution = fw.validate_distribution(
              distribution,
              self.instance_groups,
              self._framework_name,
              framework_version,
              py_version,
              image_uri,
              kwargs,
          )
      self.model_dir = model_dir
      self.distribution = distribution or {}
  
      self._validate_args(py_version=py_version)
      if compiler_config is not None:
          if not isinstance(compiler_config, TrainingCompilerConfig):
              error_string = (
                  f"Expected instance of type {TrainingCompilerConfig}"
                  f"for argument compiler_config. "
                  f"Instead got {type(compiler_config)}"
              )
              raise ValueError(error_string)
          if compiler_config:
              compiler_config.validate(self)
      self.compiler_config = compiler_config
  
      if "profiler_config" in kwargs:
          fw.profiler_config_deprecation_warning(
              kwargs["profiler_config"],
              image_uri,
              self._framework_name,
              framework_version,
          )
  
imports: from __future__ import absolute_import
  import logging
  from typing import Optional, Union, Dict
  from packaging import version
  from sagemaker import image_uris, s3, utils
  from sagemaker.deprecations import renamed_kwargs
  from sagemaker.estimator import Framework, EstimatorBase
  import sagemaker.fw_utils
  from sagemaker.tensorflow import defaults
  from sagemaker.tensorflow.model import TensorFlowModel
  from sagemaker.transformer import Transformer
  from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
  from sagemaker.workflow import is_pipeline_variable
  from sagemaker.tensorflow.training_compiler.config import TrainingCompilerConfig
  from sagemaker.workflow.entities import PipelineVariable
  from sagemaker.utils import format_tags
label_desc: Use image node_id 1 to create a new TensorFlow object from inherited base classes: Framework with example: obj = TensorFlow(py_version, framework_version, model_dir, image_uri, distribution, compiler_config)