cursus.steps.scripts.dummy_training

DummyTraining Processing Script

This script validates, unpacks a pretrained model.tar.gz file, conditionally adds a hyperparameters.json file inside it, then repacks it and outputs to the destination. It serves as a dummy training step that skips actual training and integrates with downstream MIMS packaging and payload steps.

Hyperparameters Handling:
  • If model.tar.gz already contains hyperparameters.json (e.g., from PyTorch/XGBoost training): * Keeps the original hyperparameters from the model * Ignores any hyperparameters provided via input channel

  • If model.tar.gz does NOT contain hyperparameters.json: * Requires hyperparameters.json from input channel * Injects it into the model archive

  • Fails only if BOTH conditions are true: * Model archive doesn’t contain hyperparameters.json * No hyperparameters.json provided via input channel

validate_model(input_path)[source]

Validate the model file format and structure.

Parameters:

input_path (Path) – Path to the input model.tar.gz file

Returns:

True if validation passes, False otherwise

Raises:
Return type:

bool

ensure_directory(directory)[source]

Ensure a directory exists, creating it if necessary.

extract_tarfile(tar_path, extract_path)[source]

Extract a tar file to the specified path.

create_tarfile(output_tar_path, source_dir)[source]

Create a tar file from the contents of a directory.

copy_file(src, dst)[source]

Copy a file and ensure the destination directory exists.

process_model_with_hyperparameters(model_path, hyperparams_path, output_dir)[source]

Process the model.tar.gz by unpacking it and conditionally adding hyperparameters.json.

The hyperparameters.json file is only added if: 1. It doesn’t already exist in the model archive 2. An input hyperparameters_path is provided

Parameters:
  • model_path (Path) – Path to the input model.tar.gz file

  • hyperparams_path (Path | None) – Optional path to the hyperparameters.json file (None if not provided)

  • output_dir (Path) – Directory to save the processed model

Returns:

Path to the processed model.tar.gz

Raises:
  • FileNotFoundError – If model doesn’t exist, or if hyperparameters are missing from both model and input

  • Exception – For processing errors

Return type:

Path

find_model_file(input_paths)[source]

Find model.tar.gz file with fallback search.

Priority: 1. Pre-configured path from input_paths (either input channel or /opt/ml/code/models) 2. Final fallback: model.tar.gz relative to script location

Parameters:

input_paths (Dict[str, str]) – Dictionary of input paths from container

Returns:

Path to model file if found, None otherwise

Return type:

Path | None

find_hyperparams_file(input_paths)[source]

Find hyperparameters.json file at the specified path.

The input_paths[“hyperparameters_s3_uri”] is pre-configured in __main__ to point to either: - /opt/ml/processing/input/hyperparameters_s3_uri (if dependency injection provided) - /opt/ml/code/hyperparams/ (SOURCE fallback)

Parameters:

input_paths (Dict[str, str]) – Dictionary of input paths from container

Returns:

Path to hyperparameters file if found, None otherwise

Return type:

Path | None

main(input_paths, output_paths, environ_vars, job_args=None)[source]

Main entry point for the DummyTraining script.

Reads model and hyperparameters with flexible input modes: - Mode 1 (INTERNAL): From input channels (model_artifacts_input, hyperparameters_s3_uri) - Mode 2 (SOURCE): From source directory (fallback)

Parameters:
  • input_paths (Dict[str, str]) – Dictionary of input paths with logical names - “model_artifacts_input”: Optional path to model.tar.gz - “hyperparameters_s3_uri”: Optional path to hyperparameters.json

  • output_paths (Dict[str, str]) – Dictionary of output paths with logical names - “model_output”: Output directory for processed model

  • environ_vars (Dict[str, str]) – Dictionary of environment variables

  • job_args (Namespace | None) – Command line arguments (optional)

Returns:

Path to the processed model.tar.gz output

Return type:

Path