HuggingFace¶
HuggingFace Estimator¶
-
class
sagemaker.huggingface.estimator.
HuggingFace
(py_version, entry_point, transformers_version=None, tensorflow_version=None, pytorch_version=None, source_dir=None, hyperparameters=None, image_uri=None, distribution=None, **kwargs)¶ Bases:
sagemaker.estimator.Framework
Handle training of custom HuggingFace code.
This
Estimator
executes a HuggingFace script in a managed execution environment.The managed HuggingFace environment is an Amazon-built Docker container that executes functions defined in the supplied
entry_point
Python script within a SageMaker Training Job.Training is started by calling
fit()
on this Estimator.- Parameters
py_version (str) – Python version you want to use for executing your model training code. Defaults to
None
. Required unlessimage_uri
is provided. If using PyTorch, the current supported version ispy36
. If using TensorFlow, the current supported version ispy37
.entry_point (str) – Path (absolute or relative) to the Python source file which should be executed as the entry point to training. If
source_dir
is specified, thenentry_point
must point to a file located at the root ofsource_dir
.transformers_version (str) – Transformers version you want to use for executing your model training code. Defaults to
None
. Required unlessimage_uri
is provided. The current supported version is4.4.2
.tensorflow_version (str) – TensorFlow version you want to use for executing your model training code. Defaults to
None
. Required unlesspytorch_version
is provided. The current supported version is1.6.0
.pytorch_version (str) – PyTorch version you want to use for executing your model training code. Defaults to
None
. Required unlesstensorflow_version
is provided. The current supported version is2.4.1
.source_dir (str) – Path (absolute, relative or an S3 URI) to a directory with any other training source code dependencies aside from the entry point file (default: None). If
source_dir
is an S3 URI, it must point to a tar.gz file. Structure within this directory are preserved when training on Amazon SageMaker.hyperparameters (dict) – Hyperparameters that will be used for training (default: None). The hyperparameters are made accessible as a dict[str, str] to the training code on SageMaker. For convenience, this accepts other types for keys and values, but
str()
will be called to convert them before training.image_uri (str) –
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. .. rubric:: Examples
123412341234.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
custom-image:latest
If
framework_version
orpy_version
areNone
, thenimage_uri
is required. If alsoNone
, then aValueError
will be raised.distribution (dict) –
A dictionary with information on how to run distributed training (default: None). Currently, the following are supported: distributed training with parameter servers, SageMaker Distributed (SMD) Data and Model Parallelism, and MPI. SMD Model Parallelism can only be used with MPI. To enable parameter server use the following setup:
{ "parameter_server": { "enabled": True } }
To enable MPI:
{ "mpi": { "enabled": True } }
To enable SMDistributed Data Parallel or Model Parallel:
{ "smdistributed": { "dataparallel": { "enabled": True }, "modelparallel": { "enabled": True, "parameters": {} } } }
**kwargs – Additional kwargs passed to the
Framework
constructor.
Tip
You can find additional parameters for initializing this class at
Framework
andEstimatorBase
.-
hyperparameters
()¶ Return hyperparameters used by your custom PyTorch code during model training.
-
create_model
(model_server_workers=None, role=None, vpc_config_override='VPC_CONFIG_DEFAULT', entry_point=None, source_dir=None, dependencies=None, **kwargs)¶ Placeholder docstring