Skip to content
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

Generate unique SageMaker training job name based on pipeline and ste… #1505

Merged
merged 7 commits into from
May 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# permissions and limitations under the License.
"""Implementation of the Sagemaker Step Operator."""

import random
import string
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Type, cast

import sagemaker
Expand Down Expand Up @@ -179,9 +181,14 @@ def launch(
image_name, self.config.role, **estimator_args
)

# SageMaker allows 63 characters at maximum for job name - ZenML uses 60 for safety margin.
step_name = Client().get_run_step(info.step_run_id).name
training_job_name = f"{info.pipeline.name}-{step_name}"[:55]
suffix = "".join(random.choices(string.ascii_lowercase, k=4))
unique_training_job_name = f"{training_job_name}-{suffix}"

# Sagemaker doesn't allow any underscores in job/experiment/trial names
job_name = f"{info.run_name}-{info.pipeline_step_name}"
job_name = job_name.replace("_", "-")
sanitized_training_job_name = unique_training_job_name.replace("_", "-")
strickvl marked this conversation as resolved.
Show resolved Hide resolved

# Construct training input object, if necessary
inputs = None
Expand All @@ -201,12 +208,12 @@ def launch(
if settings.experiment_name:
experiment_config = {
"ExperimentName": settings.experiment_name,
"TrialName": job_name,
"TrialName": sanitized_training_job_name,
}

estimator.fit(
wait=True,
inputs=inputs,
experiment_config=experiment_config,
job_name=job_name,
job_name=sanitized_training_job_name,
)