The `sagemaker-training` library provides the core toolkit that runs inside Amazon SageMaker training containers. It handles downloading input data, parsing hyperparameters, executing user training scripts, and uploading model artifacts. It's currently at version 5.1.1 and has a relatively active release cadence, with minor versions released every few weeks/months and major versions less frequently.
pip install sagemaker-trainingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a typical SageMaker training script entry point. It uses `sagemaker_training.environment` to retrieve hyperparameters and input/output paths, which are crucial for running user code within a SageMaker training container. The script should be placed at the root of your training code archive.
Ensure all your dependencies, including those brought by SageMaker's base images, are compatible with `protobuf>=5.0.0`. You may need to pin specific versions of conflicting libraries or use a different base image if conflicts persist.
When testing locally, either mock the `sagemaker_training.environment` calls or ensure you set up dummy SageMaker environment variables (e.g., `SM_MODEL_DIR`, `SM_INPUT_DATA_CONFIG`, `SM_HYPERPARAMETERS`) for your test environment.
Regularly update `boto3` to the latest compatible version. If you encounter S3-related issues, verify that `boto3` versions are consistent across your environment and the toolkit, and consider explicitly pinning a compatible `boto3` version in your `requirements.txt`.
Ensure your SageMaker estimator configuration or Dockerfile ENTRYPOINT/CMD correctly points to your training script. The `source_dir` argument in SageMaker SDK estimators handles this automatically for Python scripts.
Run `pip install sagemaker-training` in your environment. If using a custom Dockerfile, add `RUN pip install sagemaker-training`.
Verify all `protobuf` installations. Ensure all libraries in your environment are compatible with `protobuf>=5.0.0`. You may need to upgrade other dependencies or explicitly pin `protobuf` to a specific v5+ version (e.g., `protobuf>=5.28.1`).
Always use `.get()` with a default value when accessing hyperparameters (e.g., `hyperparameters.get('your_hyperparameter', default_value)`). Double-check that the hyperparameter name passed to the SageMaker estimator matches the key used in your script.Ensure your SageMaker estimator's `inputs` argument correctly maps your S3 data to the expected channel name (e.g., 'training'). Verify the file exists in your S3 bucket and that your script uses the correct path derived from `env.channel_input_dirs['channel_name']`.