Offline SageMaker local mode — CatBoost training

Trains against a moto-backed S3/STS endpoint through the sagemaker-local library (no AWS). The job runs in a local Docker container.

Dataset: diabetes (regression), loaded inside the container from scikit-learn. The built sagemaker-local:latest image already includes catboost 1.2.7.

Cell 02Code
import os
from dataclasses import replace

from sagemaker.deserializers import JSONDeserializer
from sagemaker.estimator import Estimator
from sagemaker.serializers import JSONSerializer
from sagemaker_local.config import config_from_env
from sagemaker_local.session import make_local_session

cfg = replace(
    config_from_env(),
    bucket="sagemaker-catboost",
    image_tag="sagemaker-catboost:train",
)
boto_session, sm_session = make_local_session(cfg)

Train

est.fit() runs synchronously in a local container; train.py loads diabetes and writes model.joblib to /opt/ml/model.

The generic Estimator (bring-your-own-container) points at the local image through image_uri, so no AWS image is pulled.

Cell 04Code
est = Estimator(
    entry_point="train.py",
    source_dir=os.path.join(
        os.environ.get("SAGEMAKER_LOCAL_REPO_PATH", "/workspace"),
        "projects",
        "sagemaker_catboost",
        "src",
        "sagemaker_catboost",
    ),
    image_uri=cfg.image_tag,
    role=cfg.role_arn,
    instance_type="local",
    instance_count=1,
    sagemaker_session=sm_session,
    output_path=f"s3://{cfg.bucket}/models",
    hyperparameters={"dataset": "diabetes"},
)
est.fit()

Deploy & predict

Inputs are 2-D JSON arrays so the default serving input handler parses them correctly.

Cell 06Code
predictor = est.deploy(
    initial_instance_count=1,
    instance_type="local",
    serializer=JSONSerializer(),
    deserializer=JSONDeserializer(),
)
sample = [0.05, 0.08, 0.0, 0.02, 0.04, 0.06, 0.0, 0.0, 0.03, 0.05]
result = predictor.predict([sample])
print("predicted disease progression:", result)

Cleanup

Delete the endpoint so the serving container is released and port 8080 is freed.

Cell 08Code
predictor.delete_endpoint()