Skip to content

Orchestrate: Instantiate

Resolves every {class_path, init_args} block in a rendered config into a live Python object. Nested blocks recurse; filter_kwargs(klass, init_args) drops kwargs the target class doesn't accept so jsonnet stays flexible. A VRAMDriftCallback is appended automatically when CUDA is available.

graphids.orchestrate.instantiate

instantiate

Instantiation — Layer 3 of the orchestrate stack.

build_run is the only public entry point. It composes model + datamodule + trainer + callbacks + loggers from a rendered config dict into an InstantiatedRun. Every {class_path, init_args} block is resolved via importlib, with signature-filtered kwargs so jsonnet can pass fields the target class doesn't accept without raising.

build_run

build_run(rendered: dict[str, Any], *, validated: ValidatedConfig | None = None, seed_all: bool = True) -> InstantiatedRun

Instantiate trainer + model + datamodule from a rendered config dict.

The single public entry point for orchestration. Deep-copies rendered before walking it so callers can reuse the dict, runs :func:graphids.config.schemas.validate_config if validated is not already supplied, seeds torch/numpy/python RNGs from seed_everything unless opted out, then resolves every {class_path, init_args} block via importlib with signature-filtered kwargs.

Source code in graphids/orchestrate/instantiate.py
def build_run(
    rendered: dict[str, Any],
    *,
    validated: ValidatedConfig | None = None,
    seed_all: bool = True,
) -> InstantiatedRun:
    """Instantiate trainer + model + datamodule from a rendered config dict.

    The single public entry point for orchestration. Deep-copies
    ``rendered`` before walking it so callers can reuse the dict, runs
    :func:`graphids.config.schemas.validate_config` if ``validated`` is
    not already supplied, seeds torch/numpy/python RNGs from
    ``seed_everything`` unless opted out, then resolves every
    ``{class_path, init_args}`` block via ``importlib`` with
    signature-filtered kwargs.
    """
    merged = copy.deepcopy(rendered)
    if validated is None:
        validate_config(merged)
    if seed_all:
        seed_everything(merged["seed_everything"])

    return InstantiatedRun(
        model=_build_model(merged),
        datamodule=_build_block(merged["data"]),
        trainer=_build_trainer(merged),
    )