INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Deploy the best trained or user specified model to an Amazon SageMaker endpoint and return a ``sagemaker.RealTimePredictor`` object. For more information: http://docs.aws.amazon.com/sagemaker/latest/dg/how-it-works-training.html Args: initial_instance_count (int): Minimum number of...
def deploy(self, initial_instance_count, instance_type, accelerator_type=None, endpoint_name=None, **kwargs): """Deploy the best trained or user specified model to an Amazon SageMaker endpoint and return a ``sagemaker.RealTimePredictor`` object. For more information: http://docs.aws.amazon.com/...
Return name of the best training job for the latest hyperparameter tuning job. Raises: Exception: If there is no best training job available for the hyperparameter tuning job.
def best_training_job(self): """Return name of the best training job for the latest hyperparameter tuning job. Raises: Exception: If there is no best training job available for the hyperparameter tuning job. """ self._ensure_last_tuning_job() tuning_job_describe_res...
Delete an Amazon SageMaker endpoint. If an endpoint name is not specified, this defaults to looking for an endpoint that shares a name with the best training job for deletion. Args: endpoint_name (str): Name of the endpoint to delete
def delete_endpoint(self, endpoint_name=None): """Delete an Amazon SageMaker endpoint. If an endpoint name is not specified, this defaults to looking for an endpoint that shares a name with the best training job for deletion. Args: endpoint_name (str): Name of the endpoint ...
Return the hyperparameter ranges in a dictionary to be used as part of a request for creating a hyperparameter tuning job.
def hyperparameter_ranges(self): """Return the hyperparameter ranges in a dictionary to be used as part of a request for creating a hyperparameter tuning job. """ hyperparameter_ranges = dict() for range_type in ParameterRange.__all_types__: parameter_ranges = [] ...
Creates a new ``HyperparameterTuner`` by copying the request fields from the provided parent to the new instance of ``HyperparameterTuner``. Followed by addition of warm start configuration with the type as "TransferLearning" and parents as the union of provided list of ``additional_parents`` and the ``...
def transfer_learning_tuner(self, additional_parents=None, estimator=None): """Creates a new ``HyperparameterTuner`` by copying the request fields from the provided parent to the new instance of ``HyperparameterTuner``. Followed by addition of warm start configuration with the type as "TransferL...
Creates a new ``HyperparameterTuner`` by copying the request fields from the provided parent to the new instance of ``HyperparameterTuner``. Followed by addition of warm start configuration with the type as "IdenticalDataAndAlgorithm" and parents as the union of provided list of ``additional_parents`` a...
def identical_dataset_and_algorithm_tuner(self, additional_parents=None): """Creates a new ``HyperparameterTuner`` by copying the request fields from the provided parent to the new instance of ``HyperparameterTuner``. Followed by addition of warm start configuration with the type as "IdenticalDa...
Creates a new ``HyperparameterTuner`` with ``WarmStartConfig``, where type will be equal to ``warm_start_type`` and``parents`` would be equal to union of ``additional_parents`` and self. Args: additional_parents (set{str}): Additional parents along with self, to be used for warm starting. ...
def _create_warm_start_tuner(self, additional_parents, warm_start_type, estimator=None): """Creates a new ``HyperparameterTuner`` with ``WarmStartConfig``, where type will be equal to ``warm_start_type`` and``parents`` would be equal to union of ``additional_parents`` and self. Args: ...
Create a new Amazon SageMaker hyperparameter tuning job from the HyperparameterTuner. Args: tuner (sagemaker.tuner.HyperparameterTuner): HyperparameterTuner object created by the user. inputs (str): Parameters used when called :meth:`~sagemaker.estimator.EstimatorBase.fit`. Ret...
def start_new(cls, tuner, inputs): """Create a new Amazon SageMaker hyperparameter tuning job from the HyperparameterTuner. Args: tuner (sagemaker.tuner.HyperparameterTuner): HyperparameterTuner object created by the user. inputs (str): Parameters used when called :meth:`~sagema...
Return True iff there is an element, a, of arr such that a is not None
def some(arr): """Return True iff there is an element, a, of arr such that a is not None""" return functools.reduce(lambda x, y: x or (y is not None), arr, False)
Iterate over the available events coming from a set of log streams in a single log group interleaving the events from each stream so they're yielded in timestamp order. Args: client (boto3 client): The boto client for logs. log_group (str): The name of the log group. streams (list of st...
def multi_stream_iter(client, log_group, streams, positions=None): """Iterate over the available events coming from a set of log streams in a single log group interleaving the events from each stream so they're yielded in timestamp order. Args: client (boto3 client): The boto client for logs. ...
A generator for log items in a single stream. This will yield all the items that are available at the current moment. Args: client (boto3.CloudWatchLogs.Client): The Boto client for CloudWatch logs. log_group (str): The name of the log group. stream_name (str): The name of the specific ...
def log_stream(client, log_group, stream_name, start_time=0, skip=0): """A generator for log items in a single stream. This will yield all the items that are available at the current moment. Args: client (boto3.CloudWatchLogs.Client): The Boto client for CloudWatch logs. log_group (str): Th...
Create a SageMaker ``RLEstimatorModel`` object that can be deployed to an Endpoint. Args: role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``, which is also used during transform jobs. If not specified, the role from the Estimator will be used. vpc_config...
def create_model(self, role=None, vpc_config_override=VPC_CONFIG_DEFAULT, entry_point=None, source_dir=None, dependencies=None): """Create a SageMaker ``RLEstimatorModel`` object that can be deployed to an Endpoint. Args: role (str): The ``ExecutionRoleArn`` IAM Role AR...
Return the Docker image to use for training. The :meth:`~sagemaker.estimator.EstimatorBase.fit` method, which does the model training, calls this method to find the image to use for model training. Returns: str: The URI of the Docker image.
def train_image(self): """Return the Docker image to use for training. The :meth:`~sagemaker.estimator.EstimatorBase.fit` method, which does the model training, calls this method to find the image to use for model training. Returns: str: The URI of the Docker image. ...
Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_name (str): Name of the channel where pre-trained model data will be downloaded. ...
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None): """Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_n...
Return hyperparameters used by your custom TensorFlow code during model training.
def hyperparameters(self): """Return hyperparameters used by your custom TensorFlow code during model training.""" hyperparameters = super(RLEstimator, self).hyperparameters() additional_hyperparameters = {SAGEMAKER_OUTPUT_LOCATION: self.output_path, # TODO...
Provides default metric definitions based on provided toolkit. Args: toolkit(sagemaker.rl.RLToolkit): RL Toolkit to be used for training. Returns: list: metric definitions
def default_metric_definitions(cls, toolkit): """Provides default metric definitions based on provided toolkit. Args: toolkit(sagemaker.rl.RLToolkit): RL Toolkit to be used for training. Returns: list: metric definitions """ if toolkit is RLToolkit.COACH...
Prepare S3 operations (specify where to upload `source_dir`) and environment variables related to framework. Args: estimator (sagemaker.estimator.Estimator): The framework estimator to get information from and update. s3_operations (dict): The dict to specify s3 operations (upload `source_dir`)...
def prepare_framework(estimator, s3_operations): """Prepare S3 operations (specify where to upload `source_dir`) and environment variables related to framework. Args: estimator (sagemaker.estimator.Estimator): The framework estimator to get information from and update. s3_operations (dict):...
Set up amazon algorithm estimator, adding the required `feature_dim` hyperparameter from training data. Args: estimator (sagemaker.amazon.amazon_estimator.AmazonAlgorithmEstimatorBase): An estimator for a built-in Amazon algorithm to get information from and update. inputs: The training...
def prepare_amazon_algorithm_estimator(estimator, inputs, mini_batch_size=None): """ Set up amazon algorithm estimator, adding the required `feature_dim` hyperparameter from training data. Args: estimator (sagemaker.amazon.amazon_estimator.AmazonAlgorithmEstimatorBase): An estimator for a b...
Export Airflow base training config from an estimator Args: estimator (sagemaker.estimator.EstimatorBase): The estimator to export training config from. Can be a BYO estimator, Framework estimator or Amazon algorithm estimator. inputs: Information about the training data. Pl...
def training_base_config(estimator, inputs=None, job_name=None, mini_batch_size=None): """Export Airflow base training config from an estimator Args: estimator (sagemaker.estimator.EstimatorBase): The estimator to export training config from. Can be a BYO estimator, Framework es...
Export Airflow training config from an estimator Args: estimator (sagemaker.estimator.EstimatorBase): The estimator to export training config from. Can be a BYO estimator, Framework estimator or Amazon algorithm estimator. inputs: Information about the training data. Please ...
def training_config(estimator, inputs=None, job_name=None, mini_batch_size=None): """Export Airflow training config from an estimator Args: estimator (sagemaker.estimator.EstimatorBase): The estimator to export training config from. Can be a BYO estimator, Framework estimator or...
Export Airflow tuning config from an estimator Args: tuner (sagemaker.tuner.HyperparameterTuner): The tuner to export tuning config from. inputs: Information about the training data. Please refer to the ``fit()`` method of the associated estimator in the tuner, as this can take any ...
def tuning_config(tuner, inputs, job_name=None): """Export Airflow tuning config from an estimator Args: tuner (sagemaker.tuner.HyperparameterTuner): The tuner to export tuning config from. inputs: Information about the training data. Please refer to the ``fit()`` method of the ...
Updated the S3 URI of the framework source directory in given estimator. Args: estimator (sagemaker.estimator.Framework): The Framework estimator to update. job_name (str): The new job name included in the submit S3 URI Returns: str: The updated S3 URI of framework source directory
def update_submit_s3_uri(estimator, job_name): """Updated the S3 URI of the framework source directory in given estimator. Args: estimator (sagemaker.estimator.Framework): The Framework estimator to update. job_name (str): The new job name included in the submit S3 URI Returns: str...
Update training job of the estimator from a task in the DAG Args: estimator (sagemaker.estimator.EstimatorBase): The estimator to update task_id (str): The task id of any airflow.contrib.operators.SageMakerTrainingOperator or airflow.contrib.operators.SageMakerTuningOperator that genera...
def update_estimator_from_task(estimator, task_id, task_type): """Update training job of the estimator from a task in the DAG Args: estimator (sagemaker.estimator.EstimatorBase): The estimator to update task_id (str): The task id of any airflow.contrib.operators.SageMakerTrainingOperator or ...
Prepare the framework model container information. Specify related S3 operations for Airflow to perform. (Upload `source_dir`) Args: model (sagemaker.model.FrameworkModel): The framework model instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge'. ...
def prepare_framework_container_def(model, instance_type, s3_operations): """Prepare the framework model container information. Specify related S3 operations for Airflow to perform. (Upload `source_dir`) Args: model (sagemaker.model.FrameworkModel): The framework model instance_type (str): ...
Export Airflow model config from a SageMaker model Args: instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge' model (sagemaker.model.FrameworkModel): The SageMaker model to export Airflow config from role (str): The ``ExecutionRoleArn`` IAM Role AR...
def model_config(instance_type, model, role=None, image=None): """Export Airflow model config from a SageMaker model Args: instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge' model (sagemaker.model.FrameworkModel): The SageMaker model to export Airflo...
Export Airflow model config from a SageMaker estimator Args: instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge' estimator (sagemaker.model.EstimatorBase): The SageMaker estimator to export Airflow config from. It has to be an estimator associ...
def model_config_from_estimator(instance_type, estimator, task_id, task_type, role=None, image=None, name=None, model_server_workers=None, vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT): """Export Airflow model config from a SageMaker estimator Args: instance_type (st...
Export Airflow transform config from a SageMaker transformer Args: transformer (sagemaker.transformer.Transformer): The SageMaker transformer to export Airflow config from. data (str): Input data location in S3. data_type (str): What the S3 location defines (default: 'S3Prefix')...
def transform_config(transformer, data, data_type='S3Prefix', content_type=None, compression_type=None, split_type=None, job_name=None): """Export Airflow transform config from a SageMaker transformer Args: transformer (sagemaker.transformer.Transformer): The SageMaker transformer ...
Export Airflow transform config from a SageMaker estimator Args: estimator (sagemaker.model.EstimatorBase): The SageMaker estimator to export Airflow config from. It has to be an estimator associated with a training job. task_id (str): The task id of any airflow.contrib.operators.SageMa...
def transform_config_from_estimator(estimator, task_id, task_type, instance_count, instance_type, data, data_type='S3Prefix', content_type=None, compression_type=None, split_type=None, job_name=None, model_name=None, strategy=None, assemble_with=No...
Export Airflow deploy config from a SageMaker model Args: model (sagemaker.model.Model): The SageMaker model to export the Airflow config from. instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge'. initial_instance_count (int): The initial number o...
def deploy_config(model, initial_instance_count, instance_type, endpoint_name=None, tags=None): """Export Airflow deploy config from a SageMaker model Args: model (sagemaker.model.Model): The SageMaker model to export the Airflow config from. instance_type (str): The EC2 instance type to deploy...
Export Airflow deploy config from a SageMaker estimator Args: estimator (sagemaker.model.EstimatorBase): The SageMaker estimator to export Airflow config from. It has to be an estimator associated with a training job. task_id (str): The task id of any airflow.contrib.operators.SageMaker...
def deploy_config_from_estimator(estimator, task_id, task_type, initial_instance_count, instance_type, model_name=None, endpoint_name=None, tags=None, **kwargs): """Export Airflow deploy config from a SageMaker estimator Args: estimator (sagemaker.model.EstimatorBase): ...
Create a model to deploy. The serializer, deserializer, content_type, and accept arguments are only used to define a default RealTimePredictor. They are ignored if an explicit predictor class is passed in. Other arguments are passed through to the Model class. Args: role (s...
def create_model( self, role=None, predictor_cls=None, serializer=None, deserializer=None, content_type=None, accept=None, vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT, **kwargs ): """Create a model to deploy. The serialize...
Return a ``Transformer`` that uses a SageMaker Model based on the training job. It reuses the SageMaker Session and base job name used by the Estimator. Args: instance_count (int): Number of EC2 instances to use. instance_type (str): Type of EC2 instance to use, for example, 'ml...
def transformer(self, instance_count, instance_type, strategy=None, assemble_with=None, output_path=None, output_kms_key=None, accept=None, env=None, max_concurrent_transforms=None, max_payload=None, tags=None, role=None, volume_kms_key=None): """Return a ``Transformer`` ...
Set any values in the estimator that need to be set before training. Args: * job_name (str): Name of the training job to be created. If not specified, one is generated, using the base name given to the constructor if applicable.
def _prepare_for_training(self, job_name=None): """Set any values in the estimator that need to be set before training. Args: * job_name (str): Name of the training job to be created. If not specified, one is generated, using the base name given to the constructor if applica...
Train a model using the input training dataset. The API calls the Amazon SageMaker CreateTrainingJob API to start model training. The API uses configuration you provided to create the estimator and the specified input training data to send the CreatingTrainingJob request to Amazon SageMaker. ...
def fit(self, inputs=None, wait=True, logs=True, job_name=None): """Train a model using the input training dataset. The API calls the Amazon SageMaker CreateTrainingJob API to start model training. The API uses configuration you provided to create the estimator and the specified input t...
Compile a Neo model using the input model. Args: target_instance_family (str): Identifies the device that you want to run your model after compilation, for example: ml_c5. Allowed strings are: ml_c5, ml_m5, ml_c4, ml_m4, jetsontx1, jetsontx2, ml_p2, ml_p3, deeplens, ...
def compile_model(self, target_instance_family, input_shape, output_path, framework=None, framework_version=None, compile_max_run=5 * 60, tags=None, **kwargs): """Compile a Neo model using the input model. Args: target_instance_family (str): Identifies the device that ...
Attach to an existing training job. Create an Estimator bound to an existing training job, each subclass is responsible to implement ``_prepare_init_params_from_job_description()`` as this method delegates the actual conversion of a training job description to the arguments that the class const...
def attach(cls, training_job_name, sagemaker_session=None, model_channel_name='model'): """Attach to an existing training job. Create an Estimator bound to an existing training job, each subclass is responsible to implement ``_prepare_init_params_from_job_description()`` as this method delegate...
Deploy the trained model to an Amazon SageMaker endpoint and return a ``sagemaker.RealTimePredictor`` object. More information: http://docs.aws.amazon.com/sagemaker/latest/dg/how-it-works-training.html Args: initial_instance_count (int): Minimum number of EC2 instances to deploy to...
def deploy(self, initial_instance_count, instance_type, accelerator_type=None, endpoint_name=None, use_compiled_model=False, update_endpoint=False, **kwargs): """Deploy the trained model to an Amazon SageMaker endpoint and return a ``sagemaker.RealTimePredictor`` object. More information...
str: The model location in S3. Only set if Estimator has been ``fit()``.
def model_data(self): """str: The model location in S3. Only set if Estimator has been ``fit()``.""" if self.latest_training_job is not None: model_uri = self.sagemaker_session.sagemaker_client.describe_training_job( TrainingJobName=self.latest_training_job.name)['ModelArtifa...
Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_name (str): Name of the channel where pre-trained model data will be downloaded. Returns: ...
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None): """Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_n...
Delete an Amazon SageMaker ``Endpoint``. Raises: ValueError: If the endpoint does not exist.
def delete_endpoint(self): """Delete an Amazon SageMaker ``Endpoint``. Raises: ValueError: If the endpoint does not exist. """ self._ensure_latest_training_job(error_message='Endpoint was not created yet') self.sagemaker_session.delete_endpoint(self.latest_training_j...
Return a ``Transformer`` that uses a SageMaker Model based on the training job. It reuses the SageMaker Session and base job name used by the Estimator. Args: instance_count (int): Number of EC2 instances to use. instance_type (str): Type of EC2 instance to use, for example, 'ml...
def transformer(self, instance_count, instance_type, strategy=None, assemble_with=None, output_path=None, output_kms_key=None, accept=None, env=None, max_concurrent_transforms=None, max_payload=None, tags=None, role=None, volume_kms_key=None): """Return a ``Transformer`` ...
Return a ``TrainingJobAnalytics`` object for the current training job.
def training_job_analytics(self): """Return a ``TrainingJobAnalytics`` object for the current training job. """ if self._current_job_name is None: raise ValueError('Estimator is not associated with a TrainingJob') return TrainingJobAnalytics(self._current_job_name, sagemaker_...
Returns VpcConfig dict either from this Estimator's subnets and security groups, or else validate and return an optional override value.
def get_vpc_config(self, vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT): """ Returns VpcConfig dict either from this Estimator's subnets and security groups, or else validate and return an optional override value. """ if vpc_config_override is vpc_utils.VPC_CONFIG_DEFAULT: ...
Create a new Amazon SageMaker training job from the estimator. Args: estimator (sagemaker.estimator.EstimatorBase): Estimator object created by the user. inputs (str): Parameters used when called :meth:`~sagemaker.estimator.EstimatorBase.fit`. Returns: sagemaker.es...
def start_new(cls, estimator, inputs): """Create a new Amazon SageMaker training job from the estimator. Args: estimator (sagemaker.estimator.EstimatorBase): Estimator object created by the user. inputs (str): Parameters used when called :meth:`~sagemaker.estimator.EstimatorBas...
Create a model to deploy. Args: role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``, which is also used during transform jobs. If not specified, the role from the Estimator will be used. image (str): An container image to use for deploying the model. Defa...
def create_model(self, role=None, image=None, predictor_cls=None, serializer=None, deserializer=None, content_type=None, accept=None, vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT, **kwargs): """ Create a model to deploy. Args: role (str): The ``ExecutionRole...
Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_name (str): Name of the channel where pre-trained model data will be downloaded Returns: ...
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None): """Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_n...
Set hyperparameters needed for training. This method will also validate ``source_dir``. Args: * job_name (str): Name of the training job to be created. If not specified, one is generated, using the base name given to the constructor if applicable.
def _prepare_for_training(self, job_name=None): """Set hyperparameters needed for training. This method will also validate ``source_dir``. Args: * job_name (str): Name of the training job to be created. If not specified, one is generated, using the base name given to the con...
Upload the user training script to s3 and return the location. Returns: s3 uri
def _stage_user_code_in_s3(self): """Upload the user training script to s3 and return the location. Returns: s3 uri """ local_mode = self.output_path.startswith('file://') if self.code_location is None and local_mode: code_bucket = self.sagemaker_session.default_bu...
Get the appropriate value to pass as source_dir to model constructor on deploying Returns: str: Either a local or an S3 path pointing to the source_dir to be used for code by the model to be deployed
def _model_source_dir(self): """Get the appropriate value to pass as source_dir to model constructor on deploying Returns: str: Either a local or an S3 path pointing to the source_dir to be used for code by the model to be deployed """ return self.source_dir if self.sagemake...
Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_name (str): Name of the channel where pre-trained model data will be downloaded Returns: ...
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None): """Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_n...
Return the Docker image to use for training. The :meth:`~sagemaker.estimator.EstimatorBase.fit` method, which does the model training, calls this method to find the image to use for model training. Returns: str: The URI of the Docker image.
def train_image(self): """Return the Docker image to use for training. The :meth:`~sagemaker.estimator.EstimatorBase.fit` method, which does the model training, calls this method to find the image to use for model training. Returns: str: The URI of the Docker image. ...
Attach to an existing training job. Create an Estimator bound to an existing training job, each subclass is responsible to implement ``_prepare_init_params_from_job_description()`` as this method delegates the actual conversion of a training job description to the arguments that the class const...
def attach(cls, training_job_name, sagemaker_session=None, model_channel_name='model'): """Attach to an existing training job. Create an Estimator bound to an existing training job, each subclass is responsible to implement ``_prepare_init_params_from_job_description()`` as this method delegate...
Return a ``Transformer`` that uses a SageMaker Model based on the training job. It reuses the SageMaker Session and base job name used by the Estimator. Args: instance_count (int): Number of EC2 instances to use. instance_type (str): Type of EC2 instance to use, for example, 'ml...
def transformer(self, instance_count, instance_type, strategy=None, assemble_with=None, output_path=None, output_kms_key=None, accept=None, env=None, max_concurrent_transforms=None, max_payload=None, tags=None, role=None, model_server_workers=None, volume_kms_key=None): "...
Return all non-None ``hyperparameter`` values on ``obj`` as a ``dict[str,str].``
def serialize_all(obj): """Return all non-None ``hyperparameter`` values on ``obj`` as a ``dict[str,str].``""" if '_hyperparameters' not in dir(obj): return {} return {k: str(v) for k, v in obj._hyperparameters.items() if v is not None}
Start the Local Transform Job Args: input_data (dict): Describes the dataset to be transformed and the location where it is stored. output_data (dict): Identifies the location where to save the results from the transform job transform_resources (dict): compute instances for ...
def start(self, input_data, output_data, transform_resources, **kwargs): """Start the Local Transform Job Args: input_data (dict): Describes the dataset to be transformed and the location where it is stored. output_data (dict): Identifies the location where to save the results f...
Describe this _LocalTransformJob The response is a JSON-like dictionary that follows the response of the boto describe_transform_job() API. Returns: dict: description of this _LocalTransformJob
def describe(self): """Describe this _LocalTransformJob The response is a JSON-like dictionary that follows the response of the boto describe_transform_job() API. Returns: dict: description of this _LocalTransformJob """ response = { 'TransformJo...
Get all the Environment variables that will be passed to the container Certain input fields such as BatchStrategy have different values for the API vs the Environment variables, such as SingleRecord vs SINGLE_RECORD. This method also handles this conversion. Args: **kwargs: existin...
def _get_container_environment(self, **kwargs): """Get all the Environment variables that will be passed to the container Certain input fields such as BatchStrategy have different values for the API vs the Environment variables, such as SingleRecord vs SINGLE_RECORD. This method also handles th...
Represent the parameter range as a dicionary suitable for a request to create an Amazon SageMaker hyperparameter tuning job. Args: name (str): The name of the hyperparameter. Returns: dict[str, str]: A dictionary that contains the name and values of the hyperparameter.
def as_tuning_range(self, name): """Represent the parameter range as a dicionary suitable for a request to create an Amazon SageMaker hyperparameter tuning job. Args: name (str): The name of the hyperparameter. Returns: dict[str, str]: A dictionary that contains...
Represent the parameter range as a dictionary suitable for a request to create an Amazon SageMaker hyperparameter tuning job using one of the deep learning frameworks. The deep learning framework images require that hyperparameters be serialized as JSON. Args: name (str): The name ...
def as_json_range(self, name): """Represent the parameter range as a dictionary suitable for a request to create an Amazon SageMaker hyperparameter tuning job using one of the deep learning frameworks. The deep learning framework images require that hyperparameters be serialized as JSON. ...
Create a definition for executing a container as part of a SageMaker model. Args: image (str): Docker image to run for this container. model_data_url (str): S3 URI of data required by this container, e.g. SageMaker training job model artifacts (default: None). env (dict[str, str...
def container_def(image, model_data_url=None, env=None): """Create a definition for executing a container as part of a SageMaker model. Args: image (str): Docker image to run for this container. model_data_url (str): S3 URI of data required by this container, e.g. SageMaker training...
Create a definition for executing a pipeline of containers as part of a SageMaker model. Args: models (list[sagemaker.Model]): this will be a list of ``sagemaker.Model`` objects in the order the inference should be invoked. instance_type (str): The EC2 instance type to deploy this Model to. ...
def pipeline_container_def(models, instance_type=None): """ Create a definition for executing a pipeline of containers as part of a SageMaker model. Args: models (list[sagemaker.Model]): this will be a list of ``sagemaker.Model`` objects in the order the inference should be invoked. ...
Create a production variant description suitable for use in a ``ProductionVariant`` list as part of a ``CreateEndpointConfig`` request. Args: model_name (str): The name of the SageMaker model this production variant references. instance_type (str): The EC2 instance type for this production vari...
def production_variant(model_name, instance_type, initial_instance_count=1, variant_name='AllTraffic', initial_weight=1, accelerator_type=None): """Create a production variant description suitable for use in a ``ProductionVariant`` list as part of a ``CreateEndpointConfig`` request. ...
Return the role ARN whose credentials are used to call the API. Throws an exception if Args: sagemaker_session(Session): Current sagemaker session Returns: (str): The role ARN
def get_execution_role(sagemaker_session=None): """Return the role ARN whose credentials are used to call the API. Throws an exception if Args: sagemaker_session(Session): Current sagemaker session Returns: (str): The role ARN """ if not sagemaker_session: sagemaker_sessi...
Initialize this SageMaker Session. Creates or uses a boto_session, sagemaker_client and sagemaker_runtime_client. Sets the region_name.
def _initialize(self, boto_session, sagemaker_client, sagemaker_runtime_client): """Initialize this SageMaker Session. Creates or uses a boto_session, sagemaker_client and sagemaker_runtime_client. Sets the region_name. """ self.boto_session = boto_session or boto3.Session() ...
Upload local file or directory to S3. If a single file is specified for upload, the resulting S3 object key is ``{key_prefix}/{filename}`` (filename does not include the local path, if any specified). If a directory is specified for upload, the API uploads all content, recursively, pre...
def upload_data(self, path, bucket=None, key_prefix='data'): """Upload local file or directory to S3. If a single file is specified for upload, the resulting S3 object key is ``{key_prefix}/{filename}`` (filename does not include the local path, if any specified). If a directory is spe...
Return the name of the default bucket to use in relevant Amazon SageMaker interactions. Returns: str: The name of the default bucket, which is of the form: ``sagemaker-{region}-{AWS account ID}``.
def default_bucket(self): """Return the name of the default bucket to use in relevant Amazon SageMaker interactions. Returns: str: The name of the default bucket, which is of the form: ``sagemaker-{region}-{AWS account ID}``. """ if self._default_bucket: return s...
Create an Amazon SageMaker training job. Args: input_mode (str): The input mode that the algorithm supports. Valid modes: * 'File' - Amazon SageMaker copies the training dataset from the S3 location to a directory in the Docker container. * 'Pipe...
def train(self, input_mode, input_config, role, job_name, output_config, # noqa: C901 resource_config, vpc_config, hyperparameters, stop_condition, tags, metric_definitions, enable_network_isolation=False, image=None, algorithm_arn=None, encrypt_inter_container_traffic=False):...
Create an Amazon SageMaker Neo compilation job. Args: input_model_config (dict): the trained model and the Amazon S3 location where it is stored. output_model_config (dict): Identifies the Amazon S3 location where you want Amazon SageMaker Neo to save the results of comp...
def compile_model(self, input_model_config, output_model_config, role, job_name, stop_condition, tags): """Create an Amazon SageMaker Neo compilation job. Args: input_model_config (dict): the trained model and the Amazon S3 location where it is stored. outp...
Create an Amazon SageMaker hyperparameter tuning job Args: job_name (str): Name of the tuning job being created. strategy (str): Strategy to be used for hyperparameter estimations. objective_type (str): The type of the objective metric for evaluating training jobs. This valu...
def tune(self, job_name, strategy, objective_type, objective_metric_name, max_jobs, max_parallel_jobs, parameter_ranges, static_hyperparameters, input_mode, metric_definitions, role, input_config, output_config, resource_config, stop_condition, tags, warm_start_config...
Stop the Amazon SageMaker hyperparameter tuning job with the specified name. Args: name (str): Name of the Amazon SageMaker hyperparameter tuning job. Raises: ClientError: If an error occurs while trying to stop the hyperparameter tuning job.
def stop_tuning_job(self, name): """Stop the Amazon SageMaker hyperparameter tuning job with the specified name. Args: name (str): Name of the Amazon SageMaker hyperparameter tuning job. Raises: ClientError: If an error occurs while trying to stop the hyperparameter tun...
Create an Amazon SageMaker transform job. Args: job_name (str): Name of the transform job being created. model_name (str): Name of the SageMaker model being used for the transform job. strategy (str): The strategy used to decide how to batch records in a single request. ...
def transform(self, job_name, model_name, strategy, max_concurrent_transforms, max_payload, env, input_config, output_config, resource_config, tags): """Create an Amazon SageMaker transform job. Args: job_name (str): Name of the transform job being created. mod...
Create an Amazon SageMaker ``Model``. Specify the S3 location of the model artifacts and Docker image containing the inference code. Amazon SageMaker uses this information to deploy the model in Amazon SageMaker. This method can also be used to create a Model for an Inference Pipeline if...
def create_model(self, name, role, container_defs, vpc_config=None, enable_network_isolation=False, primary_container=None, tags=None): """Create an Amazon SageMaker ``Model``. Specify the S3 location of the model artifacts and Docker image containing th...
Create an Amazon SageMaker ``Model`` from a SageMaker Training Job. Args: training_job_name (str): The Amazon SageMaker Training Job name. name (str): The name of the SageMaker ``Model`` to create (default: None). If not specified, the training job name is used. ...
def create_model_from_job(self, training_job_name, name=None, role=None, primary_container_image=None, model_data_url=None, env=None, vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT): """Create an Amazon SageMaker ``Model`` from a SageMaker Training Job. Args: ...
Create a SageMaker Model Package from the results of training with an Algorithm Package Args: name (str): ModelPackage name description (str): Model Package description algorithm_arn (str): arn or name of the algorithm used for training. model_data (str): s3 URI ...
def create_model_package_from_algorithm(self, name, description, algorithm_arn, model_data): """Create a SageMaker Model Package from the results of training with an Algorithm Package Args: name (str): ModelPackage name description (str): Model Package description al...
Wait for an Amazon SageMaker endpoint deployment to complete. Args: endpoint (str): Name of the ``Endpoint`` to wait for. poll (int): Polling interval in seconds (default: 5). Returns: dict: Return value from the ``DescribeEndpoint`` API.
def wait_for_model_package(self, model_package_name, poll=5): """Wait for an Amazon SageMaker endpoint deployment to complete. Args: endpoint (str): Name of the ``Endpoint`` to wait for. poll (int): Polling interval in seconds (default: 5). Returns: dict: Re...
Create an Amazon SageMaker endpoint configuration. The endpoint configuration identifies the Amazon SageMaker model (created using the ``CreateModel`` API) and the hardware configuration on which to deploy the model. Provide this endpoint configuration to the ``CreateEndpoint`` API, which then ...
def create_endpoint_config(self, name, model_name, initial_instance_count, instance_type, accelerator_type=None, tags=None, kms_key=None): """Create an Amazon SageMaker endpoint configuration. The endpoint configuration identifies the Amazon SageMaker model (created using...
Create an Amazon SageMaker ``Endpoint`` according to the endpoint configuration specified in the request. Once the ``Endpoint`` is created, client applications can send requests to obtain inferences. The endpoint configuration is created using the ``CreateEndpointConfig`` API. Args: ...
def create_endpoint(self, endpoint_name, config_name, tags=None, wait=True): """Create an Amazon SageMaker ``Endpoint`` according to the endpoint configuration specified in the request. Once the ``Endpoint`` is created, client applications can send requests to obtain inferences. The endpoint co...
Update an Amazon SageMaker ``Endpoint`` according to the endpoint configuration specified in the request Raise an error if endpoint with endpoint_name does not exist. Args: endpoint_name (str): Name of the Amazon SageMaker ``Endpoint`` to update. endpoint_config_name (str): Nam...
def update_endpoint(self, endpoint_name, endpoint_config_name): """ Update an Amazon SageMaker ``Endpoint`` according to the endpoint configuration specified in the request Raise an error if endpoint with endpoint_name does not exist. Args: endpoint_name (str): Name of the Amazon S...
Delete an Amazon SageMaker ``Endpoint``. Args: endpoint_name (str): Name of the Amazon SageMaker ``Endpoint`` to delete.
def delete_endpoint(self, endpoint_name): """Delete an Amazon SageMaker ``Endpoint``. Args: endpoint_name (str): Name of the Amazon SageMaker ``Endpoint`` to delete. """ LOGGER.info('Deleting endpoint with name: {}'.format(endpoint_name)) self.sagemaker_client.delete...
Delete an Amazon SageMaker endpoint configuration. Args: endpoint_config_name (str): Name of the Amazon SageMaker endpoint configuration to delete.
def delete_endpoint_config(self, endpoint_config_name): """Delete an Amazon SageMaker endpoint configuration. Args: endpoint_config_name (str): Name of the Amazon SageMaker endpoint configuration to delete. """ LOGGER.info('Deleting endpoint configuration with name: {}'.form...
Delete an Amazon SageMaker Model. Args: model_name (str): Name of the Amazon SageMaker model to delete.
def delete_model(self, model_name): """Delete an Amazon SageMaker Model. Args: model_name (str): Name of the Amazon SageMaker model to delete. """ LOGGER.info('Deleting model with name: {}'.format(model_name)) self.sagemaker_client.delete_model(ModelName=model_name)
Wait for an Amazon SageMaker training job to complete. Args: job (str): Name of the training job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from the ``DescribeTrainingJob`` API. Raises: Value...
def wait_for_job(self, job, poll=5): """Wait for an Amazon SageMaker training job to complete. Args: job (str): Name of the training job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from the ``DescribeTrain...
Wait for an Amazon SageMaker Neo compilation job to complete. Args: job (str): Name of the compilation job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from the ``DescribeCompilationJob`` API. Raises: ...
def wait_for_compilation_job(self, job, poll=5): """Wait for an Amazon SageMaker Neo compilation job to complete. Args: job (str): Name of the compilation job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value fr...
Wait for an Amazon SageMaker hyperparameter tuning job to complete. Args: job (str): Name of the tuning job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from the ``DescribeHyperParameterTuningJob`` API. Ra...
def wait_for_tuning_job(self, job, poll=5): """Wait for an Amazon SageMaker hyperparameter tuning job to complete. Args: job (str): Name of the tuning job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from t...
Wait for an Amazon SageMaker transform job to complete. Args: job (str): Name of the transform job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from the ``DescribeTransformJob`` API. Raises: Va...
def wait_for_transform_job(self, job, poll=5): """Wait for an Amazon SageMaker transform job to complete. Args: job (str): Name of the transform job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from the ``D...
Check to see if the job completed successfully and, if not, construct and raise a ValueError. Args: job (str): The name of the job to check. desc (dict[str, str]): The result of ``describe_training_job()``. status_key_name (str): Status key name to check for. ...
def _check_job_status(self, job, desc, status_key_name): """Check to see if the job completed successfully and, if not, construct and raise a ValueError. Args: job (str): The name of the job to check. desc (dict[str, str]): The result of ``describe_training_job()``. ...
Wait for an Amazon SageMaker endpoint deployment to complete. Args: endpoint (str): Name of the ``Endpoint`` to wait for. poll (int): Polling interval in seconds (default: 5). Returns: dict: Return value from the ``DescribeEndpoint`` API.
def wait_for_endpoint(self, endpoint, poll=5): """Wait for an Amazon SageMaker endpoint deployment to complete. Args: endpoint (str): Name of the ``Endpoint`` to wait for. poll (int): Polling interval in seconds (default: 5). Returns: dict: Return value from...
Create an ``Endpoint`` using the results of a successful training job. Specify the job name, Docker image containing the inference code, and hardware configuration to deploy the model. Internally the API, creates an Amazon SageMaker model (that describes the model artifacts and the Docker image...
def endpoint_from_job(self, job_name, initial_instance_count, instance_type, deployment_image=None, name=None, role=None, wait=True, model_environment_vars=None, vpc_config_override=vpc_utils.VPC_CONFIG_DEFAULT, accelerator_type=None): ...
Create and deploy to an ``Endpoint`` using existing model data stored in S3. Args: model_s3_location (str): S3 URI of the model artifacts to use for the endpoint. deployment_image (str): The Docker image which defines the runtime code to be used as the entry point for ac...
def endpoint_from_model_data(self, model_s3_location, deployment_image, initial_instance_count, instance_type, name=None, role=None, wait=True, model_environment_vars=None, model_vpc_config=None, accelerator_type=None): """Create and deploy to an...
Create an SageMaker ``Endpoint`` from a list of production variants. Args: name (str): The name of the ``Endpoint`` to create. production_variants (list[dict[str, str]]): The list of production variants to deploy. tags (list[dict[str, str]]): A list of key-value pairs for ta...
def endpoint_from_production_variants(self, name, production_variants, tags=None, kms_key=None, wait=True): """Create an SageMaker ``Endpoint`` from a list of production variants. Args: name (str): The name of the ``Endpoint`` to create. production_variants (list[dict[str, str]]...
Expand an IAM role name into an ARN. If the role is already in the form of an ARN, then the role is simply returned. Otherwise we retrieve the full ARN and return it. Args: role (str): An AWS IAM role (either name or full ARN). Returns: str: The corresponding A...
def expand_role(self, role): """Expand an IAM role name into an ARN. If the role is already in the form of an ARN, then the role is simply returned. Otherwise we retrieve the full ARN and return it. Args: role (str): An AWS IAM role (either name or full ARN). Retur...
Returns the ARN user or role whose credentials are used to call the API. Returns: (str): The ARN user or role
def get_caller_identity_arn(self): """Returns the ARN user or role whose credentials are used to call the API. Returns: (str): The ARN user or role """ assumed_role = self.boto_session.client('sts').get_caller_identity()['Arn'] if 'AmazonSageMaker-ExecutionRole' in a...
Display the logs for a given training job, optionally tailing them until the job is complete. If the output is a tty or a Jupyter cell, it will be color-coded based on which instance the log entry is from. Args: job_name (str): Name of the training job to display the logs for. ...
def logs_for_job(self, job_name, wait=False, poll=10): # noqa: C901 - suppress complexity warning for this method """Display the logs for a given training job, optionally tailing them until the job is complete. If the output is a tty or a Jupyter cell, it will be color-coded based on which inst...
Return docker registry for the given AWS region for the given framework. This is only used for SparkML and Scikit-learn for now.
def registry(region_name, framework=None): """ Return docker registry for the given AWS region for the given framework. This is only used for SparkML and Scikit-learn for now. """ try: account_id = image_registry_map[region_name][framework] return get_ecr_image_uri_prefix(account_id,...
Return a :class:`~sagemaker.amazon.KNNModel` referencing the latest s3 model data produced by this Estimator. Args: vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on the model. Default: use subnets and security groups from this Estimator. ...
def create_model(self, vpc_config_override=VPC_CONFIG_DEFAULT): """Return a :class:`~sagemaker.amazon.KNNModel` referencing the latest s3 model data produced by this Estimator. Args: vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on the model. ...
Create all the intermediate directories required for relative_path to exist within destination_directory. This assumes that relative_path is a directory located within root_dir. Examples: destination_directory: /tmp/destination relative_path: test/unit/ will create: /tmp/destination/t...
def copy_directory_structure(destination_directory, relative_path): """Create all the intermediate directories required for relative_path to exist within destination_directory. This assumes that relative_path is a directory located within root_dir. Examples: destination_directory: /tmp/destination ...
move source to destination. Can handle uploading to S3 Args: source (str): root directory to move destination (str): file:// or s3:// URI that source will be moved to. job_name (str): SageMaker job name. sagemaker_session (sagemaker.Session): a sagemaker_session to interact with S3 ...
def move_to_destination(source, destination, job_name, sagemaker_session): """move source to destination. Can handle uploading to S3 Args: source (str): root directory to move destination (str): file:// or s3:// URI that source will be moved to. job_name (str): SageMaker job name. ...
A wrapper around distutils.dir_util.copy_tree but won't throw any exception when the source directory does not exist. Args: source (str): source path destination (str): destination path
def recursive_copy(source, destination): """A wrapper around distutils.dir_util.copy_tree but won't throw any exception when the source directory does not exist. Args: source (str): source path destination (str): destination path """ if os.path.isdir(source): copy_tree(sourc...
Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_name (str): Name of the channel where pre-trained model data will be downloaded. Returns: ...
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None): """Convert the job description to init params that can be handled by the class constructor Args: job_details: the returned job details from a describe_training_job API call. model_channel_n...
Start a new transform job. Args: data (str): Input data location in S3. data_type (str): What the S3 location defines (default: 'S3Prefix'). Valid values: * 'S3Prefix' - the S3 URI defines a key name prefix. All objects with this prefix will be used as ...
def transform(self, data, data_type='S3Prefix', content_type=None, compression_type=None, split_type=None, job_name=None): """Start a new transform job. Args: data (str): Input data location in S3. data_type (str): What the S3 location defines (default: 'S3Pref...