Skip to content

Commit d049017

Browse files
mohamedzeidan2021Mohamed Zeidan
andauthored
fix: preserve content_type when HyperparameterTuner converts InputData to Channel (#5632) (#6321)
Co-authored-by: Mohamed Zeidan <zeidmo@amazon.com>
1 parent db591b8 commit d049017

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎sagemaker-train/src/sagemaker/train/tuner.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,12 @@ def _build_training_job_definition(self, inputs):
14281428
# List of InputData or Channel objects
14291429
for inp in inputs:
14301430
if isinstance(inp, InputData):
1431-
# Convert InputData to Channel
1431+
# Convert InputData to Channel. Preserve content_type so built-in
1432+
# algorithms (e.g. XGBoost) know the data format (issue #5632).
14321433
input_data_config.append(
14331434
Channel(
14341435
channel_name=inp.channel_name,
1436+
content_type=inp.content_type,
14351437
data_source=DataSource(
14361438
s3_data_source=S3DataSource(
14371439
s3_data_type="S3Prefix",

‎sagemaker-train/tests/unit/train/test_tuner.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,35 @@ def test_build_training_job_definition_includes_internal_channels(self):
653653
assert "validation" in channel_names, "User 'validation' channel should be included"
654654
assert len(channel_names) == 4, "Should have exactly 4 channels"
655655

656+
def test_build_training_job_definition_preserves_content_type(self):
657+
"""Regression for #5632.
658+
659+
Converting an InputData to a Channel must carry over content_type, otherwise built-in
660+
algorithms fail because the container doesn't know the data format.
661+
"""
662+
from sagemaker.core.training.configs import InputData
663+
664+
tuner = HyperparameterTuner(
665+
model_trainer=_create_mock_model_trainer(),
666+
objective_metric_name="validation:auc",
667+
hyperparameter_ranges=_create_single_hp_range(),
668+
)
669+
670+
definition = tuner._build_training_job_definition(
671+
[
672+
InputData(
673+
channel_name="train",
674+
data_source="s3://bucket/train/train.csv",
675+
content_type="csv",
676+
)
677+
]
678+
)
679+
680+
train_channel = next(
681+
ch for ch in definition.input_data_config if ch.channel_name == "train"
682+
)
683+
assert train_channel.content_type == "csv"
684+
656685
def test_build_training_job_definition_includes_spot_params(self):
657686
"""Test that _build_training_job_definition includes spot parameters."""
658687
tuner = HyperparameterTuner(

0 commit comments

Comments
 (0)