Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`HyperparameterTuner` drops `ModelTrainer` checkpoint and retry configuration

Abierto Apto para principiantes
#6,500 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@mohamedzeidan2021 ya está trabajando en esto.

Desde el 20/10/2026.

  • #6511 de @mohamedzeidan2021 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
aws, python

Línea de trabajo

Empieza en HyperparameterTuner._build_training_job_definition() e inspecciona cómo construye definition_kwargs a partir de ModelTrainer. Compara los campos con HyperParameterTrainingJobDefinition y con las pruebas existentes para las definiciones del tuner. Se considera terminado cuando se conservan los ajustes de checkpoint y reintento si se proporcionan, y se omiten correctamente si faltan, incluido el entrenamiento spot administrado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

PySDK Version

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

Describe the bug

HyperparameterTuner builds a
HyperParameterTrainingJobDefinition from its ModelTrainer.

The generated shape supports checkpoint_config and retry_strategy.
However, _build_training_job_definition() does not copy either value from
the trainer.

As a result, tuned training jobs lose:

  • The checkpoint S3 location and local checkpoint path.
  • The training retry strategy.

This behavior is especially risky for managed spot tuning. An interrupted job
cannot resume from the configured checkpoint, and transient failures do not use
the configured retry count.

This defect is present in SageMaker Python SDK v3.25.0.

To reproduce

Run this script. It does not call a live AWS service.

from unittest.mock import patch

import boto3
from sagemaker.core.parameter import IntegerParameter
from sagemaker.core.training.configs import (
    CheckpointConfig,
    Compute,
    OutputDataConfig,
    RetryStrategy,
)
from sagemaker.core.workflow.pipeline_context import PipelineSession
from sagemaker.train import ModelTrainer
from sagemaker.train.tuner import HyperparameterTuner

role = "arn:aws:iam::123456789012:role/example"
boto_session = boto3.Session(
    aws_access_key_id="test",
    aws_secret_access_key="test",
    region_name="us-east-2",
)
pipeline_session = PipelineSession(boto_session=boto_session)

with patch(
    "sagemaker.train.defaults.resolve_and_validate_role",
    return_value=role,
):
    trainer = ModelTrainer(
        training_image="123456789012.dkr.ecr.us-east-2.amazonaws.com/example:latest",
        role=role,
        sagemaker_session=pipeline_session,
        compute=Compute(
            instance_type="ml.m5.large",
            instance_count=1,
            enable_managed_spot_training=True,
        ),
        checkpoint_config=CheckpointConfig(
            s3_uri="s3://example-bucket/checkpoints/",
            local_path="/opt/ml/checkpoints",
        ),
        output_data_config=OutputDataConfig(
            s3_output_path="s3://example-bucket/output/",
        ),
    ).with_retry_strategy(
        RetryStrategy(maximum_retry_attempts=10)
    )

tuner = HyperparameterTuner(
    model_trainer=trainer,
    objective_metric_name="validation:accuracy",
    objective_type="Maximize",
    hyperparameter_ranges={
        "epochs": IntegerParameter(1, 5),
    },
    max_jobs=2,
    max_parallel_jobs=1,
)

definition = tuner._build_training_job_definition([])

print("Trainer checkpoint:", trainer.checkpoint_config)
print("Tuning checkpoint:", definition.checkpoint_config)
print("Trainer retry:", trainer.retry_strategy)
print("Tuning retry:", definition.retry_strategy)

assert definition.checkpoint_config == trainer.checkpoint_config
assert definition.retry_strategy == trainer.retry_strategy

Both assertions fail because the tuning definition fields remain unassigned.

Expected behavior

The tuning job definition must preserve the trainer's checkpoint and retry
configuration.

Screenshots or logs

The generated shape accepts both fields:

HyperParameterTrainingJobDefinition(
    # ...
    checkpoint_config=...,
    retry_strategy=...,
)

HyperparameterTuner._build_training_job_definition() does not pass them in
definition_kwargs.

System information

  • SageMaker Python SDK version: 3.25.0
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): Framework-independent
  • Framework version: Not applicable
  • Python version: 3.12
  • CPU or GPU: CPU
  • Custom Docker image (Y/N): Reproduces with either

Additional context

A possible fix is to add the assigned trainer values to
definition_kwargs:

if model_trainer.checkpoint_config is not None:
    definition_kwargs["checkpoint_config"] = model_trainer.checkpoint_config

if model_trainer.retry_strategy is not None:
    definition_kwargs["retry_strategy"] = model_trainer.retry_strategy

Tests must cover normal and managed spot trainers, explicit values, and omitted
values.

Lenguaje dominante
Python
Estrellas
2.3k
Forks
1.3k
Merge medio
2 d 16 h
PR fusionados (30 d)
88

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws/sagemaker-python-sdk

Todos los issues de aws/sagemaker-python-sdk

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.