espnet3.utils.stage_configs.inherit
espnet3.utils.stage_configs.inherit
espnet3.utils.stage_configs.inherit(exp_dir: Path | None, system_cls: type, stage: str, own: DictConfig, , in_memory: Mapping[str, Mapping] | None = None) → DictConfig
Earlier stages’ configs, in stage order, then own’s keys on top.
Walks system_cls.stages in declared order up to (not including) stage. For each earlier stage, its top-level keys come from in_memory[stage_name] when given (the same run’s own keys, already resolved, before that stage has baked anything), else from <exp_dir>/config/<stage_name>.yaml when that file exists (a –exp_dir run inheriting from an earlier run). A later stage’s keys win over an earlier one’s, and own wins over all of them. The merge is whole-top-level-key replacement, not a deep merge: a key present in own always fully replaces the same key inherited from an earlier stage.
- Parameters:
- exp_dir – The experiment directory holding config/<stage>.yaml for earlier stages, or None when none of them has one (no in_memory entry and no baked file for any earlier stage).
- system_cls – The system class stage belongs to; its declared stages gives the inheritance order.
- stage – The stage about to run. Only stages declared before it are considered; stage itself contributes nothing inherited.
- own – This stage’s own config (its default plus whatever the caller loaded), not yet merged with anything inherited.
- in_memory – Mapping from an earlier stage’s name to its own top-level keys, already resolved, for a stage that has not (yet) baked a file this run. Checked before the baked file.
- Returns: A new config: earlier stages’ keys (in_memory or baked file), then own’s own keys layered on top.
- Return type: DictConfig
Examples
>>> import tempfile
>>> from espnet3.contract.stages import StageSpec
>>> class ExampleSystem:
... stages = (
... StageSpec(name="train", config="training"),
... StageSpec(name="infer", config="inference"),
... )
>>> with tempfile.TemporaryDirectory() as exp_dir:
... config_dir = Path(exp_dir) / "config"
... config_dir.mkdir()
... _ = (config_dir / "train.yaml").write_text("exp_dir: " + exp_dir)
... own = OmegaConf.create({"inference_dir": "infer"})
... merged = inherit(exp_dir, ExampleSystem, "infer", own)
... merged.exp_dir == exp_dir and merged.inference_dir == "infer"
True
>>> own2 = OmegaConf.create({"inference_dir": "infer2"})
>>> merged2 = inherit(
... None, ExampleSystem, "infer", own2,
... in_memory={"train": {"exp_dir": "./exp/live"}},
... )
>>> merged2.exp_dir
'./exp/live'