Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

HyperparameterTuner drops content_type when converting InputData to Channel

已关闭
#5,632 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
aws, python

调研方向

从 sagemaker/train/tuner.py 中的 _create_hyperparameter_tuning_job 开始,重点查看第 1362-1373 行,并跟踪 InputData 到 Channel 的转换。使用 XGBoost 重现所提供的 HyperparameterTuner 用例;当生成的 Channel 保留 content_type,且训练作业不再因 validate_data_file_path 错误而失败时,工作即完成。

由索引模型根据 Issue 内容生成。

描述

PySDK Version

  • PySDK V2 (2.x)
  • PySDK V3 (3.x)

Describe the bug
When HyperparameterTuner.tune() receives InputData objects as inputs, it converts them to Channel objects internally but drops the content_type field during conversion. This causes built-in algorithms (e.g., XGBoost) to fail with validate_data_file_path errors because the container doesn't know the data format.

To reproduce

from sagemaker.train.configs import InputData
from sagemaker.train.tuner import HyperparameterTuner

train_input = InputData(
    channel_name="train",
    data_source="s3://my-bucket/train/train.csv",
    content_type="csv",  # <-- this gets dropped
)

tuner = HyperparameterTuner(
    model_trainer=model_trainer,
    objective_metric_name="validation:auc",
    hyperparameter_ranges=hyperparameter_ranges,
    objective_type="Maximize",
    max_jobs=12,
    max_parallel_jobs=3,
    strategy="Bayesian",
)

tuner.tune(inputs=[train_input])
# All training jobs fail with:
# AlgorithmError: validate_data_file_path(train_path, content_type)

Root Cause
In sagemaker/train/tuner.py, the _create_hyperparameter_tuning_job method converts InputData → Channel without passing content_type:


# tuner.py lines 1362-1373
```python
if isinstance(inp, InputData):
    input_data_config.append(Channel(
        channel_name=inp.channel_name,
        data_source=DataSource(
            s3_data_source=S3DataSource(
                s3_data_type="S3Prefix",
                s3_uri=inp.data_source,
                s3_data_distribution_type="FullyReplicated"
            )
        )
        # content_type is missing here!
    ))

Suggested Fix

if isinstance(inp, InputData):
    input_data_config.append(Channel(
        channel_name=inp.channel_name,
        content_type=inp.content_type,  # <-- add this
        data_source=DataSource(
            s3_data_source=S3DataSource(
                s3_data_type="S3Prefix",
                s3_uri=inp.data_source,
                s3_data_distribution_type="FullyReplicated"
            )
        )
    ))

Workaround
Pass Channel objects directly instead of InputData:

from sagemaker.core.shapes import Channel, DataSource, S3DataSource

train_input = Channel(
    channel_name="train",
    content_type="csv",
    data_source=DataSource(
        s3_data_source=S3DataSource(
            s3_data_type="S3Prefix",
            s3_uri="s3://my-bucket/train/train.csv",
            s3_data_distribution_type="FullyReplicated",
        )
    ),
)

tuner.tune(inputs=[train_input])  # works correctly

Environment
SageMaker Python SDK version: 3.0.1
Python version: 3.12
Built-in algorithm: XGBoost 1.7-1

主要语言
Python
星标
2.3k
派生
1.3k
平均合并
3 天 7 小时
30 天内合并 PR
86

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aws/sagemaker-python-sdk 的其他 Issue

查看 aws/sagemaker-python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。