Skip to content

breaking: remove "train_" where redundant in parameter/variable names #1676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/sagemaker/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def __init__(
self,
algorithm_arn,
role,
train_instance_count,
train_instance_type,
train_volume_size=30,
train_volume_kms_key=None,
train_max_run=24 * 60 * 60,
instance_count,
instance_type,
volume_size=30,
volume_kms_key=None,
max_run=24 * 60 * 60,
input_mode="File",
output_path=None,
output_kms_key=None,
Expand All @@ -65,15 +65,15 @@ def __init__(
access training data and model artifacts. After the endpoint
is created, the inference code might use the IAM role, if it
needs to access an AWS resource.
train_instance_count (int): Number of Amazon EC2 instances to
use for training. train_instance_type (str): Type of EC2
instance_count (int): Number of Amazon EC2 instances to
use for training. instance_type (str): Type of EC2
instance to use for training, for example, 'ml.c4.xlarge'.
train_volume_size (int): Size in GB of the EBS volume to use for
volume_size (int): Size in GB of the EBS volume to use for
storing input data during training (default: 30). Must be large enough to store
training data if File Mode is used (which is the default).
train_volume_kms_key (str): Optional. KMS key ID for encrypting EBS volume attached
volume_kms_key (str): Optional. KMS key ID for encrypting EBS volume attached
to the training instance (default: None).
train_max_run (int): Timeout in seconds for training (default: 24 * 60 * 60).
max_run (int): Timeout in seconds for training (default: 24 * 60 * 60).
After this amount of time Amazon SageMaker terminates the
job regardless of its current status.
input_mode (str): The input mode that the algorithm supports
Expand Down Expand Up @@ -131,11 +131,11 @@ def __init__(
self.algorithm_arn = algorithm_arn
super(AlgorithmEstimator, self).__init__(
role,
train_instance_count,
train_instance_type,
train_volume_size,
train_volume_kms_key,
train_max_run,
instance_count,
instance_type,
volume_size,
volume_kms_key,
max_run,
input_mode,
output_path,
output_kms_key,
Expand Down Expand Up @@ -167,30 +167,30 @@ def validate_train_spec(self):

# Check that the input mode provided is compatible with the training input modes for the
# algorithm.
train_input_modes = self._algorithm_training_input_modes(train_spec["TrainingChannels"])
if self.input_mode not in train_input_modes:
input_modes = self._algorithm_training_input_modes(train_spec["TrainingChannels"])
if self.input_mode not in input_modes:
raise ValueError(
"Invalid input mode: %s. %s only supports: %s"
% (self.input_mode, algorithm_name, train_input_modes)
% (self.input_mode, algorithm_name, input_modes)
)

# Check that the training instance type is compatible with the algorithm.
supported_instances = train_spec["SupportedTrainingInstanceTypes"]
if self.train_instance_type not in supported_instances:
if self.instance_type not in supported_instances:
raise ValueError(
"Invalid train_instance_type: %s. %s supports the following instance types: %s"
% (self.train_instance_type, algorithm_name, supported_instances)
"Invalid instance_type: %s. %s supports the following instance types: %s"
% (self.instance_type, algorithm_name, supported_instances)
)

# Verify if distributed training is supported by the algorithm
if (
self.train_instance_count > 1
self.instance_count > 1
and "SupportsDistributedTraining" in train_spec
and not train_spec["SupportsDistributedTraining"]
):
raise ValueError(
"Distributed training is not supported by %s. "
"Please set train_instance_count=1" % algorithm_name
"Please set instance_count=1" % algorithm_name
)

def set_hyperparameters(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sagemaker/amazon/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Please find an example code snippet for illustration:
.. code:: python

from sagemaker import PCA
pca_estimator = PCA(role='SageMakerRole', train_instance_count=1, train_instance_type='ml.m4.xlarge', num_components=3)
pca_estimator = PCA(role='SageMakerRole', instance_count=1, instance_type='ml.m4.xlarge', num_components=3)

import numpy as np
records = pca_estimator.record_set(np.arange(10).reshape(2,5))
Expand Down
16 changes: 8 additions & 8 deletions src/sagemaker/amazon/amazon_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class AmazonAlgorithmEstimatorBase(EstimatorBase):
def __init__(
self,
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
data_location=None,
enable_network_isolation=False,
**kwargs
Expand All @@ -66,9 +66,9 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if it needs to access an AWS resource.
train_instance_count (int): Number of Amazon EC2 instances to use
instance_count (int): Number of Amazon EC2 instances to use
for training.
train_instance_type (str): Type of EC2 instance to use for training,
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.c4.xlarge'.
data_location (str or None): The s3 prefix to upload RecordSet
objects to, expressed as an S3 url. For example
Expand All @@ -89,8 +89,8 @@ def __init__(
"""
super(AmazonAlgorithmEstimatorBase, self).__init__(
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
enable_network_isolation=enable_network_isolation,
**kwargs
)
Expand Down Expand Up @@ -266,7 +266,7 @@ def record_set(self, train, labels=None, channel="train", encrypt=False):
the list of objects created and also stored in S3.

The number of S3 objects created is controlled by the
``train_instance_count`` property on this Estimator. One S3 object is
``instance_count`` property on this Estimator. One S3 object is
created per training instance.

Args:
Expand All @@ -291,7 +291,7 @@ def record_set(self, train, labels=None, channel="train", encrypt=False):
key_prefix = key_prefix.lstrip("/")
logger.debug("Uploading to bucket %s and key_prefix %s", bucket, key_prefix)
manifest_s3_file = upload_numpy_to_s3_shards(
self.train_instance_count, s3, bucket, key_prefix, train, labels, encrypt
self.instance_count, s3, bucket, key_prefix, train, labels, encrypt
)
logger.debug("Created manifest file %s", manifest_s3_file)
return RecordSet(
Expand Down
12 changes: 5 additions & 7 deletions src/sagemaker/amazon/factorization_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class FactorizationMachines(AmazonAlgorithmEstimatorBase):
def __init__(
self,
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
num_factors,
predictor_type,
epochs=None,
Expand Down Expand Up @@ -150,9 +150,9 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if accessing AWS resource.
train_instance_count (int): Number of Amazon EC2 instances to use
instance_count (int): Number of Amazon EC2 instances to use
for training.
train_instance_type (str): Type of EC2 instance to use for training,
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.c4.xlarge'.
num_factors (int): Dimensionality of factorization.
predictor_type (str): Type of predictor 'binary_classifier' or
Expand Down Expand Up @@ -212,9 +212,7 @@ def __init__(
:class:`~sagemaker.estimator.amazon_estimator.AmazonAlgorithmEstimatorBase` and
:class:`~sagemaker.estimator.EstimatorBase`.
"""
super(FactorizationMachines, self).__init__(
role, train_instance_count, train_instance_type, **kwargs
)
super(FactorizationMachines, self).__init__(role, instance_count, instance_type, **kwargs)

self.num_factors = num_factors
self.predictor_type = predictor_type
Expand Down
10 changes: 5 additions & 5 deletions src/sagemaker/amazon/ipinsights.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class IPInsights(AmazonAlgorithmEstimatorBase):
def __init__(
self,
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
num_entity_vectors,
vector_dim,
batch_metrics_publish_interval=None,
Expand Down Expand Up @@ -94,9 +94,9 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if accessing AWS resource.
train_instance_count (int): Number of Amazon EC2 instances to use
instance_count (int): Number of Amazon EC2 instances to use
for training.
train_instance_type (str): Type of EC2 instance to use for training,
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.m5.xlarge'.
num_entity_vectors (int): Required. The number of embeddings to
train for entities accessing online resources. We recommend 2x
Expand Down Expand Up @@ -126,7 +126,7 @@ def __init__(
:class:`~sagemaker.estimator.amazon_estimator.AmazonAlgorithmEstimatorBase` and
:class:`~sagemaker.estimator.EstimatorBase`.
"""
super(IPInsights, self).__init__(role, train_instance_count, train_instance_type, **kwargs)
super(IPInsights, self).__init__(role, instance_count, instance_type, **kwargs)
self.num_entity_vectors = num_entity_vectors
self.vector_dim = vector_dim
self.batch_metrics_publish_interval = batch_metrics_publish_interval
Expand Down
10 changes: 5 additions & 5 deletions src/sagemaker/amazon/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class KMeans(AmazonAlgorithmEstimatorBase):
def __init__(
self,
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
k,
init_method=None,
max_iterations=None,
Expand Down Expand Up @@ -103,9 +103,9 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if accessing AWS resource.
train_instance_count (int): Number of Amazon EC2 instances to use
instance_count (int): Number of Amazon EC2 instances to use
for training.
train_instance_type (str): Type of EC2 instance to use for training,
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.c4.xlarge'.
k (int): The number of clusters to produce.
init_method (str): How to initialize cluster locations. One of
Expand Down Expand Up @@ -142,7 +142,7 @@ def __init__(
:class:`~sagemaker.estimator.amazon_estimator.AmazonAlgorithmEstimatorBase` and
:class:`~sagemaker.estimator.EstimatorBase`.
"""
super(KMeans, self).__init__(role, train_instance_count, train_instance_type, **kwargs)
super(KMeans, self).__init__(role, instance_count, instance_type, **kwargs)
self.k = k
self.init_method = init_method
self.max_iterations = max_iterations
Expand Down
10 changes: 5 additions & 5 deletions src/sagemaker/amazon/knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class KNN(AmazonAlgorithmEstimatorBase):
def __init__(
self,
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
k,
sample_size,
predictor_type,
Expand Down Expand Up @@ -105,8 +105,8 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if accessing AWS resource.
train_instance_count:
train_instance_type (str): Type of EC2 instance to use for training,
instance_count:
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.c4.xlarge'.
k (int): Required. Number of nearest neighbors.
sample_size (int): Required. Number of data points to be sampled
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(
:class:`~sagemaker.estimator.EstimatorBase`.
"""

super(KNN, self).__init__(role, train_instance_count, train_instance_type, **kwargs)
super(KNN, self).__init__(role, instance_count, instance_type, **kwargs)
self.k = k
self.sample_size = sample_size
self.predictor_type = predictor_type
Expand Down
10 changes: 5 additions & 5 deletions src/sagemaker/amazon/lda.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LDA(AmazonAlgorithmEstimatorBase):
def __init__(
self,
role,
train_instance_type,
instance_type,
num_topics,
alpha0=None,
max_restarts=None,
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if accessing AWS resource.
train_instance_type (str): Type of EC2 instance to use for training,
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.c4.xlarge'.
num_topics (int): The number of topics for LDA to find within the
data.
Expand All @@ -114,14 +114,14 @@ def __init__(
:class:`~sagemaker.estimator.EstimatorBase`.
"""
# this algorithm only supports single instance training
if kwargs.pop("train_instance_count", 1) != 1:
if kwargs.pop("instance_count", 1) != 1:
print(
"LDA only supports single instance training. Defaulting to 1 {}.".format(
train_instance_type
instance_type
)
)

super(LDA, self).__init__(role, 1, train_instance_type, **kwargs)
super(LDA, self).__init__(role, 1, instance_type, **kwargs)
self.num_topics = num_topics
self.alpha0 = alpha0
self.max_restarts = max_restarts
Expand Down
14 changes: 6 additions & 8 deletions src/sagemaker/amazon/linear_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class LinearLearner(AmazonAlgorithmEstimatorBase):
def __init__(
self,
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
predictor_type,
binary_classifier_model_selection_criteria=None,
target_recall=None,
Expand Down Expand Up @@ -214,9 +214,9 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if accessing AWS resource.
train_instance_count (int): Number of Amazon EC2 instances to use
instance_count (int): Number of Amazon EC2 instances to use
for training.
train_instance_type (str): Type of EC2 instance to use for training,
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.c4.xlarge'.
predictor_type (str): The type of predictor to learn. Either
"binary_classifier" or "multiclass_classifier" or "regressor".
Expand Down Expand Up @@ -325,9 +325,7 @@ def __init__(
:class:`~sagemaker.estimator.amazon_estimator.AmazonAlgorithmEstimatorBase` and
:class:`~sagemaker.estimator.EstimatorBase`.
"""
super(LinearLearner, self).__init__(
role, train_instance_count, train_instance_type, **kwargs
)
super(LinearLearner, self).__init__(role, instance_count, instance_type, **kwargs)
self.predictor_type = predictor_type
self.binary_classifier_model_selection_criteria = binary_classifier_model_selection_criteria
self.target_recall = target_recall
Expand Down Expand Up @@ -418,7 +416,7 @@ def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):

# mini_batch_size can't be greater than number of records or training job fails
default_mini_batch_size = min(
self.DEFAULT_MINI_BATCH_SIZE, max(1, int(num_records / self.train_instance_count))
self.DEFAULT_MINI_BATCH_SIZE, max(1, int(num_records / self.instance_count))
)
mini_batch_size = mini_batch_size or default_mini_batch_size
super(LinearLearner, self)._prepare_for_training(
Expand Down
10 changes: 5 additions & 5 deletions src/sagemaker/amazon/ntm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class NTM(AmazonAlgorithmEstimatorBase):
def __init__(
self,
role,
train_instance_count,
train_instance_type,
instance_count,
instance_type,
num_topics,
encoder_layers=None,
epochs=None,
Expand Down Expand Up @@ -113,8 +113,8 @@ def __init__(
endpoints use this role to access training data and model
artifacts. After the endpoint is created, the inference code
might use the IAM role, if accessing AWS resource.
train_instance_count:
train_instance_type (str): Type of EC2 instance to use for training,
instance_count:
instance_type (str): Type of EC2 instance to use for training,
for example, 'ml.c4.xlarge'.
num_topics (int): Required. The number of topics for NTM to find
within the data.
Expand Down Expand Up @@ -147,7 +147,7 @@ def __init__(
:class:`~sagemaker.estimator.EstimatorBase`.
"""

super(NTM, self).__init__(role, train_instance_count, train_instance_type, **kwargs)
super(NTM, self).__init__(role, instance_count, instance_type, **kwargs)
self.num_topics = num_topics
self.encoder_layers = encoder_layers
self.epochs = epochs
Expand Down
Loading