RLEstimator¶
RLEstimator Estimator¶
- class sagemaker.rl.estimator.RLEstimator(entry_point, toolkit=None, toolkit_version=None, framework=None, source_dir=None, hyperparameters=None, image_uri=None, metric_definitions=None, **kwargs)¶
Bases:
Framework
Handle end-to-end training and deployment of custom RLEstimator code.
Creates an RLEstimator for managed Reinforcement Learning (RL).
It will execute an RLEstimator script within a SageMaker Training Job. The managed RL environment is an Amazon-built Docker container that executes functions defined in the supplied
entry_point
Python script.Training is started by calling
fit()
on this Estimator. After training is complete, callingdeploy()
creates a hosted SageMaker endpoint and based on the specified framework returns anMXNetPredictor
orTensorFlowPredictor
instance that can be used to perform inference against the hosted model.Technical documentation on preparing RLEstimator scripts for SageMaker training and using the RLEstimator is available on the project homepage: https://github.com/aws/sagemaker-python-sdk
- Parameters
entry_point (str or PipelineVariable) – 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
.toolkit (sagemaker.rl.RLToolkit) – RL toolkit you want to use for executing your model training code.
toolkit_version (str) – RL toolkit version you want to be use for executing your model training code.
framework (sagemaker.rl.RLFramework) – Framework (MXNet or TensorFlow) you want to be used as a toolkit backed for reinforcement learning training.
source_dir (str or PipelineVariable) – 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[str, str] or dict[str, PipelineVariable]) – 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.
image_uri (str or PipelineVariable) – An ECR url. 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. Example: 123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
metric_definitions (list[dict[str, str] or list[dict[str, PipelineVariable]]) – A list of dictionaries that defines the metric(s) used to evaluate the training jobs. Each dictionary contains two keys: ‘Name’ for the name of the metric, and ‘Regex’ for the regular expression used to extract the metric from the logs. This should be defined only for jobs that don’t use an Amazon algorithm.
**kwargs – Additional kwargs passed to the
Framework
constructor.
Tip
You can find additional parameters for initializing this class at
Framework
andEstimatorBase
.- COACH_LATEST_VERSION_TF = '0.11.1'¶
- COACH_LATEST_VERSION_MXNET = '0.11.0'¶
- RAY_LATEST_VERSION = '1.6.0'¶
- create_model(role=None, vpc_config_override='VPC_CONFIG_DEFAULT', entry_point=None, source_dir=None, dependencies=None, **kwargs)¶
Create a SageMaker
RLEstimatorModel
object that can be deployed to an Endpoint.- Parameters
role (str) – The
ExecutionRoleArn
IAM Role ARN for theModel
, which is also used during transform jobs. If not specified, the role from the Estimator will be used.vpc_config_override (dict[str, list[str]]) –
Optional override for VpcConfig set on the model. Default: use subnets and security groups from this Estimator.
’Subnets’ (list[str]): List of subnet ids.
’SecurityGroupIds’ (list[str]): List of security group ids.
entry_point (str) – Path (absolute or relative) to the Python source file which should be executed as the entry point for MXNet hosting (default: self.entry_point). If
source_dir
is specified, thenentry_point
must point to a file located at the root ofsource_dir
.source_dir (str) – Path (absolute or relative) to a directory with any other training source code dependencies aside from the entry point file (default: self.source_dir). Structure within this directory are preserved when hosting on Amazon SageMaker.
dependencies (list[str]) – A list of paths to directories (absolute or relative) with any additional libraries that will be exported to the container (default: self.dependencies). The library folders will be copied to SageMaker in the same folder where the entry_point is copied. If the
`source_dir`
points to S3, code will be uploaded and the S3 location will be used instead. This is not supported with “local code” in Local Mode.**kwargs – Additional kwargs passed to the
FrameworkModel
constructor.
- Returns
- Depending on input parameters returns
one of the following:
FrameworkModel
- ifimage_uri
is specifiedon the estimator;
MXNetModel
- ifimage_uri
isn’t specified andMXNet is used as the RL backend;
TensorFlowModel
- ifimage_uri
isn’tspecified and TensorFlow is used as the RL backend.
- Return type
- Raises
ValueError – If image_uri is not specified and framework enum is not valid.
- training_image_uri()¶
Return the Docker image to use for training.
The
fit()
method, which does the model training, calls this method to find the image to use for model training.- Returns
The URI of the Docker image.
- Return type
- hyperparameters()¶
Return hyperparameters used by your custom TensorFlow code during model training.
- classmethod default_metric_definitions(toolkit)¶
Provides default metric definitions based on provided toolkit.
- Parameters
toolkit (sagemaker.rl.RLToolkit) – RL Toolkit to be used for training.
- Returns
metric definitions
- Return type
- Raises
ValueError – If toolkit enum is not valid.
- uploaded_code: Optional[UploadedCode]¶