Skip to content

Commit 6db012f

Browse files
author
Mohamed Zeidan
committed
fix: preserve content_type when HyperparameterTuner converts InputData to Channel (#5632)
1 parent 7ac2708 commit 6db012f

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
@@ -1424,10 +1424,12 @@ def _build_training_job_definition(self, inputs):
14241424
# List of InputData or Channel objects
14251425
for inp in inputs:
14261426
if isinstance(inp, InputData):
1427-
# Convert InputData to Channel
1427+
# Convert InputData to Channel. Preserve content_type so built-in
1428+
# algorithms (e.g. XGBoost) know the data format (issue #5632).
14281429
input_data_config.append(
14291430
Channel(
14301431
channel_name=inp.channel_name,
1432+
content_type=inp.content_type,
14311433
data_source=DataSource(
14321434
s3_data_source=S3DataSource(
14331435
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
@@ -581,6 +581,35 @@ def test_build_training_job_definition_includes_internal_channels(self):
581581
assert "validation" in channel_names, "User 'validation' channel should be included"
582582
assert len(channel_names) == 4, "Should have exactly 4 channels"
583583

584+
def test_build_training_job_definition_preserves_content_type(self):
585+
"""Regression for #5632.
586+
587+
Converting an InputData to a Channel must carry over content_type, otherwise built-in
588+
algorithms fail because the container doesn't know the data format.
589+
"""
590+
from sagemaker.core.training.configs import InputData
591+
592+
tuner = HyperparameterTuner(
593+
model_trainer=_create_mock_model_trainer(),
594+
objective_metric_name="validation:auc",
595+
hyperparameter_ranges=_create_single_hp_range(),
596+
)
597+
598+
definition = tuner._build_training_job_definition(
599+
[
600+
InputData(
601+
channel_name="train",
602+
data_source="s3://bucket/train/train.csv",
603+
content_type="csv",
604+
)
605+
]
606+
)
607+
608+
train_channel = next(
609+
ch for ch in definition.input_data_config if ch.channel_name == "train"
610+
)
611+
assert train_channel.content_type == "csv"
612+
584613
def test_build_training_job_definition_includes_spot_params(self):
585614
"""Test that _build_training_job_definition includes spot parameters."""
586615
tuner = HyperparameterTuner(

0 commit comments

Comments
 (0)