chore(config): move shared config primitives into runtime package#123
Open
samet-akcay wants to merge 3 commits into
Open
chore(config): move shared config primitives into runtime package#123samet-akcay wants to merge 3 commits into
samet-akcay wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a runtime-owned physicalai.config package to centralize shared configuration primitives (notably ComponentSpec) so both runtime and training code can depend on a torch-free implementation, while preserving backward compatibility via re-exports from physicalai.inference.manifest.
Changes:
- Added new
physicalai.configpackage (Config base, ComponentSpec, instantiation + serialization helpers). - Moved
ComponentSpecout ofphysicalai.inference.manifestand updated inference code to import it fromphysicalai.config. - Added a unit test asserting the legacy
physicalai.inference.manifest.ComponentSpecimport remains compatible.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/inference/test_manifest.py | Updates imports and adds a test asserting ComponentSpec is re-exported from the legacy path. |
| src/physicalai/inference/runners/factory.py | Switches runner-spec validation to use physicalai.config.ComponentSpec. |
| src/physicalai/inference/model.py | Removes runtime import of ComponentSpec from manifest; keeps type-only reference to the shared primitive. |
| src/physicalai/inference/manifest.py | Removes local ComponentSpec definition and imports ComponentSpec from physicalai.config to maintain compatibility. |
| src/physicalai/inference/component_factory.py | Updates doc/type references to point to physicalai.config.ComponentSpec. |
| src/physicalai/config/init.py | Exposes the new shared config primitives as a public package API. |
| src/physicalai/config/base.py | Adds dataclass-backed Config helper for dict/YAML roundtrips. |
| src/physicalai/config/component.py | Adds the shared ComponentSpec Pydantic model. |
| src/physicalai/config/instantiate.py | Adds generic instantiation utilities for {class_path, init_args}-style configs. |
| src/physicalai/config/mixin.py | Adds FromConfig mixin + decorator for config-based constructors. |
| src/physicalai/config/serializable.py | Adds dataclass (de)serialization helpers with basic type-hint reconstruction. |
Comments suppressed due to low confidence (2)
src/physicalai/config/instantiate.py:58
- After
config = config[key],configis no longer guaranteed to be a dict. The subsequentif "class_path" in config:and laterconfig.keys()usages will raiseTypeError/AttributeErrorif the selected value is not a mapping. Add anisinstance(config, dict)check (and a clearValueError) after extractingkeyto enforce the expected shape.
if key is not None:
if key not in config:
msg = f"Configuration must contain '{key}' key. Got keys: {list(config.keys())}"
raise ValueError(msg)
config = config[key]
if "class_path" in config:
cls = _import_class(config["class_path"])
src/physicalai/config/instantiate.py:115
yaml.safe_load()can returnNone(empty file) or a non-dict top-level value; passing that directly intoinstantiate_obj_from_dict()will crash with a non-obviousTypeError(e.g.'NoneType' is not iterable). Consider validating that the loaded config is a dict (or defaultingNoneto{}) and raising a helpful error if not.
"""Instantiate an object from a YAML/JSON configuration file."""
with Path(file_path).open("r", encoding="utf-8") as f:
config = yaml.safe_load(f)
return instantiate_obj_from_dict(config, key=key, target_cls=target_cls)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Just reading through https://jsonargparse.readthedocs.io/en/stable/ and feel like we could re-write all of this stuff using just jsonargparse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
physicalai.configpackage for shared configuration utilitiesComponentSpecout ofphysicalai.inference.manifestwhile keeping the old import path as a compatibility re-exportWhy
Config, ComponentSpecand the generic config helpers need to live in the torch-free runtime package so both the runtime repo and the training library can use the same primitive. This keeps configuration ownership in one place and removes the long-term duplicatephysicalai.config` implementation.Compatibility
This PR keeps the existing import path working:
New code can use:
This is the first half of the migration. The paired training-library PR removes the duplicate
library/src/physicalai/configpackage and switches library imports to the runtime-ownedphysicalai.configmodule.