INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
Create a SageMaker TensorFlowModel object that can be deployed to an Endpoint.
def create_model(self, model_server_workers=None, role=None, vpc_config_override=VPC_CONFIG_DEFAULT, endpoint_type=None): """Create a SageMaker ``TensorFlowModel`` object that can be deployed to an ``Endpoint``. Args: role (str): The ``ExecutionRoleArn`` IAM Role ARN fo...
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(TensorFlow, self).hyperparameters() self.checkpoint_path = self.checkpoint_path or self._default_s3_path('checkpoints') mpi_enabled = False ...
Extracts subnets and security group ids as lists from a VpcConfig dict
def from_dict(vpc_config, do_sanitize=False): """ Extracts subnets and security group ids as lists from a VpcConfig dict Args: vpc_config (dict): a VpcConfig dict containing 'Subnets' and 'SecurityGroupIds' do_sanitize (bool): whether to sanitize the VpcConfig dict before extracting values ...
Checks that an instance of VpcConfig has the expected keys and values removes unexpected keys and raises ValueErrors if any expectations are violated
def sanitize(vpc_config): """ Checks that an instance of VpcConfig has the expected keys and values, removes unexpected keys, and raises ValueErrors if any expectations are violated Args: vpc_config (dict): a VpcConfig dict containing 'Subnets' and 'SecurityGroupIds' Returns: A val...
Return the SageMaker hyperparameters for training this KMeans Estimator
def hyperparameters(self): """Return the SageMaker hyperparameters for training this KMeans Estimator""" hp_dict = dict(force_dense='True') # KMeans requires this hp to fit on Record objects hp_dict.update(super(KMeans, self).hyperparameters()) return hp_dict
Creates a new tuner 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 and the parent.
def create_identical_dataset_and_algorithm_tuner(parent, additional_parents=None, sagemaker_session=None): """Creates a new tuner 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 "I...
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 parent.
def create_transfer_learning_tuner(parent, additional_parents=None, estimator=None, sagemaker_session=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 th...
Creates an instance of WarmStartConfig class from warm start configuration response from DescribeTrainingJob.
def from_job_desc(cls, warm_start_config): """Creates an instance of ``WarmStartConfig`` class, from warm start configuration response from DescribeTrainingJob. Args: warm_start_config (dict): The expected format of the ``warm_start_config`` contains two first-class fiel...
Converts the self instance to the desired input request format.
def to_input_req(self): """Converts the ``self`` instance to the desired input request format. Returns: dict: Containing the "WarmStartType" and "ParentHyperParameterTuningJobs" as the first class fields. Examples: >>> warm_start_config = WarmStartConfig(warm_start_type...
Start a hyperparameter tuning job.
def fit(self, inputs=None, job_name=None, include_cls_metadata=False, **kwargs): """Start a hyperparameter tuning job. Args: inputs: Information about the training data. Please refer to the ``fit()`` method of the associated estimator, as this can take any of the following f...
Attach to an existing hyperparameter tuning job.
def attach(cls, tuning_job_name, sagemaker_session=None, job_details=None, estimator_cls=None): """Attach to an existing hyperparameter tuning job. Create a HyperparameterTuner bound to an existing hyperparameter tuning job. After attaching, if there exists a best training job (or any other com...
Deploy the best trained or user specified model to an Amazon SageMaker endpoint and return a sagemaker. RealTimePredictor object.
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.
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.
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 self. Also training image in 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 and the self
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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
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
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
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.
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
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 )
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
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
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
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
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
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
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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
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.
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.
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
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
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.
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.
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.
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
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
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
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.
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.
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.
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. For example ml. p2. xla...
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.
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.
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.
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.
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.
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.
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
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.
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.
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 you pass the list of container defi...
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.
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
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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...