opentau.configs.refs
Resolve $ref includes inside JSON config files.
Lets a JSON config split itself across multiple files. Anywhere a JSON value
is expected, an object of the form {"$ref": "path/to/other.json"} loads
that file’s content and inlines it. Sibling keys deep-merge over the loaded
content (sibling values win on conflict), enabling small, targeted overrides
of a referenced fragment.
Example:
// main.json
{
"dataset_mixture": {
"$ref": "mixtures/big_mixture.json",
"weights": [0.5, 0.5]
}
}
Rules:
$refvalue must be a string. Relative paths resolve against the file that contains the$ref(not CWD).Refs may appear at any depth, in dicts or list elements.
Refs may chain (a referenced file may itself contain
$refkeys); cycles raiseRefError.Sibling keys are only allowed when the referenced content is a JSON object.
Currently only whole-file references are supported (no JSON-pointer fragments). HuggingFace Hub paths are not resolved here — only local files.
Path resolution follows symlinks (
Path.resolve()). HuggingFace cache snapshots are symlinks into a content-addressed blob directory, so a relative$refinside an HF-cached config will resolve against that flat blob dir — not the snapshot dir — and is unlikely to find the target. Use absolute paths or copy the config out of the HF cache before adding$refincludes.
Functions
|
Load a JSON file and recursively resolve all |
|
Resolve |
Exceptions
Raised when |
- exception opentau.configs.refs.RefError[source]
Bases:
ExceptionRaised when
$refresolution fails.
- opentau.configs.refs.resolve_refs(config_path: str | Path) Any[source]
Load a JSON file and recursively resolve all
$refincludes.- Parameters:
config_path – Path to the root JSON file.
- Returns:
The fully resolved JSON tree (typically a dict, but may be a list or scalar depending on what the file and its includes contain).
- Raises:
RefError – If a referenced file is missing, contains invalid JSON, forms a cycle, has a non-string
$refvalue, or has sibling keys alongside a$refwhose target is not a JSON object.