sagemaker.train.base_trainer#
Classes
|
Abstract base class for all SageMaker training workflows. |
- class sagemaker.train.base_trainer.BaseTrainer(sagemaker_session: Session | None = None, role: str | None = None, base_job_name: str | None = None, tags: List[Tag] | None = None, hyperparameters: Dict[str, Any] | None = None, output_data_config: OutputDataConfig | None = None, input_data_config: List[Channel | InputData] | None = None, environment: Dict[str, str] | None = None, training_image: str | None = None, base_model_name: str | None = None, disable_output_compression: bool | None = False)[source]#
Bases:
ABCAbstract base class for all SageMaker training workflows.
This class provides the common interface and shared functionality for all trainer implementations including SFT, DPO, RLVR, and RLAIF trainers. It defines the standard parameters and abstract methods that concrete trainer classes must implement.
- Parameters:
sagemaker_session (Optional[Session]) – The SageMaker session for managing API calls and resources. If not specified, a default session will be created.
role (Optional[str]) – The IAM role ARN for the training job execution. If not specified, the default SageMaker execution role will be used.
base_job_name (Optional[str]) – The base name for training jobs. A unique suffix will be appended. If not specified, a default name will be generated based on the trainer type.
tags (Optional[List[Tag]]) – List of tags to apply to the training job for resource management and billing.
hyperparameters (Optional[Dict[str, Any]]) – Dictionary of hyperparameters for the training job. Trainer-specific defaults will be applied if not specified.
output_data_config (Optional[shapes.OutputDataConfig]) – Configuration for training job outputs including S3 paths and encryption. If not specified, default output configuration will be used.
input_data_config (Optional[List[Union[Channel, InputData]]]) – List of input data channels for the training job. Can include training and validation datasets.
environment (Optional[Dict[str, str]]) – Environment variables to set in the training container.
training_image (Optional[str]) – Custom training container image URI. If not provided, the image is auto-resolved from the model’s recipe metadata in SageMaker Hub.
- base_job_name: str | None = None#
- environment: Dict[str, str] | None = None#
- get_resolved_recipe() Dict[str, Any][source]#
Return the fully resolved recipe configuration.
Shows the final merged result of base defaults + user recipe + overrides after interpolation resolution and validation. Callable before or after train().
When neither
recipenoroverrideswere provided at construction time but hyperparameters have been set directly (e.g.trainer.hyperparameters.x = val), those user-set values are treated as implicit overrides so the resolved recipe still reflects the user’s intent.- Returns:
Deep copy of the resolved recipe configuration.
- Return type:
dict
- Raises:
ValueError – If no recipe, overrides, or direct hyperparameter assignments were provided.
- hyperparameters: Dict[str, Any] | None = None#
- latest_training_job: TrainingJob | None = None#
- output_data_config: OutputDataConfig | None = None#
- role: str | None = None#
- abstract train(input_data_config: List[InputData], wait: bool = True, logs: bool = True, wait_timeout: int | None = None)[source]#
Common training method that calls the specific implementation.
- training_image: str | None = None#