sagemaker.core.config.config_manager#

Classes

class sagemaker.core.config.config_manager.SageMakerConfig[source]#

Bases: object

ENV_VARIABLE_ADMIN_CONFIG_OVERRIDE = 'SAGEMAKER_ADMIN_CONFIG_OVERRIDE'#
ENV_VARIABLE_USER_CONFIG_OVERRIDE = 'SAGEMAKER_USER_CONFIG_OVERRIDE'#
S3_PREFIX = 's3://'#
static get_config_value(key_path, config)[source]#

Placeholder Docstring

static get_nested_value(dictionary: dict, nested_keys: List[str])[source]#

Returns a nested value from the given dictionary, and None if none present.

Raises

ValueError if the dictionary structure does not match the nested_keys

get_resolved_config_value(attribute, resource_defaults, global_defaults)[source]#
get_sagemaker_config_value(sagemaker_session, key, sagemaker_config: dict | None = None)[source]#

Returns the value that corresponds to the provided key from the configuration file.

Parameters:
  • key – Key Path of the config file entry.

  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions.

  • sagemaker_config (dict) – The sdk defaults config that is normally accessed through a Session object by doing session.sagemaker_config. (default: None) This parameter will be checked for the config value if (and only if) sagemaker_session is None. This parameter exists for the rare cases where no Session provided but a default Session cannot be initialized before config injection is needed. In that case, the config dictionary may be loaded and passed here before a default Session object is created.

Returns:

The corresponding default value in the configuration file.

Return type:

object

load_default_configs_for_resource_name(resource_name: str)[source]#
load_local_mode_config() dict | None[source]#
load_sagemaker_config(additional_config_paths: List[str] | None = None, s3_resource=None, repeat_log: bool = False) dict[source]#
resolve_class_attribute_from_config(clazz: type | None, instance: object | None, attribute: str, config_path: str, default_value=None, sagemaker_session=None)[source]#

Utility method that merges config values to data classes.

Takes an instance of a class and, if not already set, sets the instance’s attribute to a value fetched from the sagemaker_config or the default_value.

Uses this order of prioritization to determine what the value of the attribute should be: 1. current value of attribute 2. config value 3. default_value 4. does not set it

Parameters:
  • clazz (Optional[type]) – Class of ‘instance’. Used to generate a new instance if the instance is None. If None is provided here, no new object will be created if ‘instance’ doesnt exist. Note: if provided, the constructor should set default values to None; Otherwise, the constructor’s non-None default will be left as-is even if a config value was defined.

  • instance (Optional[object]) – instance of the Class ‘clazz’ that has an attribute of ‘attribute’ to set

  • attribute (str) – attribute of the instance to set if not already set

  • config_path (str) – a string denoting the path to use to lookup the config value in the sagemaker config

  • default_value – the value to use if not present elsewhere

  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None).

Returns:

The updated class instance that should be used by the caller instead of the ‘instance’ parameter that was passed in.

resolve_nested_dict_value_from_config(dictionary: dict, nested_keys: List[str], config_path: str, default_value: object | None = None, sagemaker_session=None)[source]#

Utility method that sets the value of a key path in a nested dictionary .

This method takes a dictionary and, if not already set, sets the value for the provided list of nested keys to the value fetched from the sagemaker_config or the default_value.

Uses this order of prioritization to determine what the value of the attribute should be: (1) current value of nested key, (2) config value, (3) default_value, (4) does not set it

Parameters:
  • dictionary – The dict to update.

  • nested_keys – The paths of keys where the value should be checked and set if needed.

  • config_path (str) – A string denoting the path used to find the config value in the

  • config. (sagemaker)

  • default_value – The value to use if not present elsewhere.

  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None).

Returns:

The updated dictionary that should be used by the caller instead of the ‘dictionary’ parameter that was passed in.

resolve_value_from_config(direct_input=None, config_path: str | None = None, default_value=None, sagemaker_session=None, sagemaker_config: dict | None = None)[source]#

Decides which value for the caller to use.

Note: This method incorporates information from the sagemaker config.

Uses this order of prioritization: 1. direct_input 2. config value 3. default_value 4. None

Parameters:
  • direct_input – The value that the caller of this method starts with. Usually this is an input to the caller’s class or method.

  • config_path (str) – A string denoting the path used to lookup the value in the sagemaker config.

  • default_value – The value used if not present elsewhere.

  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None).

  • sagemaker_config (dict) – The sdk defaults config that is normally accessed through a Session object by doing session.sagemaker_config. (default: None) This parameter will be checked for the config value if (and only if) sagemaker_session is None. This parameter exists for the rare cases where the user provided no Session but a default Session cannot be initialized before config injection is needed. In that case, the config dictionary may be loaded and passed here before a default Session object is created.

Returns:

The value that should be used by the caller

static set_nested_value(dictionary: dict, nested_keys: List[str], value_to_set: object)[source]#

Sets a nested value in a dictionary.

This sets a nested value inside the given dictionary and returns the new dictionary. Note: if provided an unintended list of nested keys, this can overwrite an unexpected part of the dict. Recommended to use after a check with get_nested_value first

update_list_of_dicts_with_values_from_config(input_list, config_key_path, required_key_paths: List[str] | None = None, union_key_paths: List[List[str]] | None = None, sagemaker_session=None)[source]#

Updates a list of dictionaries with missing values that are present in Config.

In some cases, config file might introduce new parameters which requires certain other parameters to be provided as part of the input list. Without those parameters, the underlying service will throw an exception. This method provides the capability to specify required key paths.

In some other cases, config file might introduce new parameters but the service API requires either an existing parameter or the new parameter that was supplied by config but not both

Parameters:
  • input_list – The input list that was provided as a method parameter.

  • config_key_path – The Key Path in the Config file that corresponds to the input_list

  • parameter.

  • required_key_paths (List[str]) – List of required key paths that should be verified in the

  • missing (merged output. If a required key path is)

  • that (we will not perform the merge for)

  • item.

  • union_key_paths (List[List[str]]) – List of List of Key paths for which we need to verify

  • exist. (whether exactly zero/one of the parameters)

  • example (For) – If the resultant dictionary can have either ‘X1’ or ‘X2’ as parameter or

  • both (neither but not)

  • [['X1' (then pass)

  • 'X2']]

  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None).

Returns:

No output. In place merge happens.

update_nested_dictionary_with_values_from_config(source_dict, config_key_path, sagemaker_session=None) dict[source]#

Updates a nested dictionary with missing values that are present in Config.

Parameters:
  • source_dict – The input nested dictionary that was provided as method parameter.

  • config_key_path – The Key Path in the Config file which corresponds to this

  • parameter. (source_dict)

  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None).

Returns:

The merged nested dictionary that is updated with missing values that are present in the Config file.

Return type:

dict

static validate_sagemaker_config(sagemaker_config: dict | None = None)[source]#