Skip to content

Surrogate models

kd.models moves a trained surrogate field model between processes as one file. Model.train_surrogate returns the trained module; save_field_model writes it under the kd-surrogate-v1 payload tag and load_field_model reads it back with the same torch_module_artifact digest, so a file written once can be injected into every segment of a lineage without the resume gate judging the model changed.

These names are imported from the subpackage rather than the package root: from kd.models import save_field_model, load_field_model.

save_field_model

save_field_model(
    model: FieldModel, path: str | Path
) -> Path

Write model as a kd-surrogate-v1 file and return its path.

load_field_model

load_field_model(path: str | Path) -> FieldModel

Rebuild the FieldModel a kd-surrogate-v1 file describes.

Raises:

  • ValueError

    The payload is not a kd-surrogate-v1 mapping, has a missing or unexpected key, names an unsupported dtype, or its state_dict does not fit the declared architecture (the strict load's own message, naming the offending tensors, is kept).