Skip to content

Commit 9e06f41

Browse files
author
Namrata Madan
committed
fix: training job name to match ease regex
1 parent cb91c9a commit 9e06f41

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/sagemaker/remote_function/job.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from __future__ import absolute_import
1515

1616
import os
17+
import re
1718
from typing import Dict, List, Tuple
1819

1920
from sagemaker.session import get_execution_role, _logs_for_job, Session
@@ -125,7 +126,11 @@ def start(job_settings: _JobSettings, func, func_args, func_kwargs):
125126
126127
Returns: the _Job object.
127128
"""
128-
job_name = name_from_base(func.__name__)
129+
# remove all special characters in the beginning of function name
130+
job_name_prefix = re.sub(r"^[^a-zA-Z0-9]+", "", func.__name__)
131+
# convert all remaining special characters to '-'
132+
job_name_prefix = re.sub(r"[^a-zA-Z0-9-]", "-", job_name_prefix)
133+
job_name = name_from_base(job_name_prefix)
129134

130135
s3_base_uri = s3_path_join(job_settings.s3_root_uri, job_name)
131136

tests/unit/sagemaker/remote_function/test_job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_start(session, mock_stored_function, mock_runtime_manager):
106106

107107
job = _Job.start(job_settings, job_function, func_args=(1, 2), func_kwargs={"c": 3, "d": 4})
108108

109-
assert job.job_name.startswith("job_function")
109+
assert job.job_name.startswith("job-function")
110110

111111
assert mock_stored_function.called_once_with(
112112
sagemaker_session=session(), s3_base_uri=f"{S3_URI}/{job.job_name}", s3_kms_key=None
@@ -168,7 +168,7 @@ def test_start_with_complete_job_settings(session, mock_stored_function, mock_ru
168168

169169
job = _Job.start(job_settings, job_function, func_args=(1, 2), func_kwargs={"c": 3, "d": 4})
170170

171-
assert job.job_name.startswith("job_function")
171+
assert job.job_name.startswith("job-function")
172172

173173
assert mock_stored_function.called_once_with(
174174
sagemaker_session=session(), s3_base_uri=f"{S3_URI}/{job.job_name}", s3_kms_key=None

0 commit comments

Comments
 (0)