Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions sagemaker-train/src/sagemaker/train/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def _get_unique_name(base, max_length=63):
str: The unique name
"""
current_time = datetime.now().strftime("%Y%m%d%H%M%S")
base = base.replace("_", "-")
# Truncate the base, not the timestamp, so the name stays unique
base = base.replace("_", "-")[: max_length - len(current_time) - 1]
unique_name = f"{base}-{current_time}"
unique_name = unique_name[:max_length] # Truncate to max_length
return unique_name


Expand Down
11 changes: 11 additions & 0 deletions sagemaker-train/tests/unit/train/test_model_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2774,3 +2774,14 @@ def test_pipeline_and_interactive_emit_identical_tags(model_trainer):
pipeline_tags = _pipeline_trainer([TAG])._create_training_job_args()["Tags"]

assert pipeline_tags == _train_wire_tags(model_trainer)


@patch("sagemaker.train.utils.datetime")
def test_get_unique_name_keeps_timestamp_for_long_base_name(mock_datetime):
from datetime import datetime

from sagemaker.train.utils import _get_unique_name

mock_datetime.now.return_value = datetime(2026, 9, 26, 12, 34, 56)

assert _get_unique_name("a" * 60) == "a" * 48 + "-20260926123456"
Loading