sagemaker.train.recipe_resolver#
Recipe resolution with 3-level override precedence for Nova model training.
Functions
|
Flatten a resolved recipe dict into a single-level key-value map. |
|
Render a Hub recipe template by filling {{placeholder}} values. |
Classes
|
Resolves a 3-level recipe configuration for Nova model training. |
- class sagemaker.train.recipe_resolver.RecipeResolver(recipe_template: Dict[str, Any], override_spec: Dict[str, Any], user_recipe_path: str | None = None, overrides: Dict[str, Any] | None = None, protected_keys: Set[str] | None = None, full_recipe_template: Dict[str, Any] | None = None, compute: Compute | HyperPodCompute | None = None)[source]#
Bases:
objectResolves a 3-level recipe configuration for Nova model training.
- Precedence (highest wins):
Programmatic overrides (dict)
User recipe (YAML file)
Base defaults (rendered from Hub template + override-params spec)
Immutable after construction — all inputs are deep-copied. resolve() is idempotent: second call returns cached result.
- sagemaker.train.recipe_resolver.flatten_resolved_recipe(resolved: Dict[str, Any]) Dict[str, Any][source]#
Flatten a resolved recipe dict into a single-level key-value map.
Recursively walks all nested dicts and extracts scalar leaf values keyed by their leaf key name. Used by trainers and evaluators to apply resolved recipe values as flat hyperparameters to the SageMaker training API.
- For nested structures like:
- training_config:
- lr_scheduler:
warmup_steps: 15 min_lr: 1e-6
This produces: {“warmup_steps”: 15, “min_lr”: 1e-6}
If duplicate leaf keys exist at different nesting levels, the last one encountered wins (depth-first traversal).
- Parameters:
resolved – The resolved recipe dict (nested by section).
- Returns:
Flat dict of all scalar leaf key-value pairs across all sections.
- sagemaker.train.recipe_resolver.render_template(template: Dict[str, Any], override_spec: Dict[str, Any]) Tuple[Dict[str, Any], Dict[str, str]][source]#
Render a Hub recipe template by filling {{placeholder}} values.
- Parameters:
template – Hub recipe template dict containing ‘{{key}}’ placeholders.
override_spec – Flat dict mapping spec keys to their metadata (including ‘default’, ‘type’, ‘min’, ‘max’, ‘enum’).
- Returns:
Tuple of (rendered_dict, key_path_map) where key_path_map maps flat spec keys to their dotpath location in the recipe structure. e.g. {“learning_rate”: “training_config.learning_rate”}