sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment#

An entry point for runtime environment. This must be kept independent of SageMaker PySDK

Functions

log_env_variables(env_vars_dict)

Log Environment Variables from the environment and an env_vars_dict.

log_key_value(key, value)

Log a key-value pair, masking sensitive values if necessary.

main([sys_args])

Entry point for bootstrap script

mask_sensitive_info(data)

Recursively mask sensitive information in a dictionary.

num_cpus()

Return the number of CPUs available in the current container.

num_gpus()

Return the number of GPUs available in the current container.

num_neurons()

Return the number of neuron cores available in the current container.

safe_serialize(data)

Serialize the data without wrapping strings in quotes.

set_env(resource_config[, distribution, ...])

Set environment variables for the training job container.

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.log_env_variables(env_vars_dict: Dict[str, Any])[source]#

Log Environment Variables from the environment and an env_vars_dict.

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.log_key_value(key: str, value: str)[source]#

Log a key-value pair, masking sensitive values if necessary.

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.main(sys_args=None)[source]#

Entry point for bootstrap script

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.mask_sensitive_info(data)[source]#

Recursively mask sensitive information in a dictionary.

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.num_cpus() int[source]#

Return the number of CPUs available in the current container.

Returns:

Number of CPUs available in the current container.

Return type:

int

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.num_gpus() int[source]#

Return the number of GPUs available in the current container.

Returns:

Number of GPUs available in the current container.

Return type:

int

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.num_neurons() int[source]#

Return the number of neuron cores available in the current container.

Returns:

Number of Neuron Cores available in the current container.

Return type:

int

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.safe_serialize(data)[source]#

Serialize the data without wrapping strings in quotes.

This function handles the following cases: 1. If data is a string, it returns the string as-is without wrapping in quotes. 2. If data is serializable (e.g., a dictionary, list, int, float), it returns

the JSON-encoded string using json.dumps().

  1. If data cannot be serialized (e.g., a custom object), it returns the string representation of the data using str(data).

Parameters:

data (Any) – The data to serialize.

Returns:

The serialized JSON-compatible string or the string representation of the input.

Return type:

str

sagemaker.train.remote_function.runtime_environment.bootstrap_runtime_environment.set_env(resource_config: Dict[str, Any], distribution: str | None = None, user_nproc_per_node: bool | None = None, output_file: str = '/opt/ml/input/sm_training.env')[source]#

Set environment variables for the training job container.

Parameters:
  • resource_config (Dict[str, Any]) – Resource configuration for the training job.

  • output_file (str) – Output file to write the environment variables.