perf(manifests): load built-in catalog without discovery - #2232
Draft
Pouyanpi wants to merge 2 commits into
Draft
Conversation
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Contributor
|
Staged Fern docs preview: https://nvidia-preview-pr-2232.docs.buildwithfern.com/nemo/guardrails |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Description
Goal
Materialize the built-in rail catalog from a generated, packaged manifest artifact instead of recursively scanning
nemoguardrails/libraryand importing every built-inrail.pymodule.Why
The built-in catalog is immutable for a given package build, but the current runtime reconstructs it from source on every fresh process. That requires a recursive filesystem scan and imports 33 manifest modules while
RailsConfigbuilds its typed schema. This work is unnecessary at runtime, adds cold-start latency to every application, and couples catalog availability to a source-tree layout.This change:
nemoguardrails/manifests/builtin_rails.jsondeterministically from source manifests;importlib.resources;RailCatalog.discover_built_ins()for generation and source-conformance tests;The generated artifact is never edited manually. A stale, malformed, or missing artifact fails with the exact regeneration command. Tests require it to match source discovery exactly and verify that runtime loading performs no recursive scan or built-in
rail.pyimport.Performance
Fresh subprocesses were alternated between the parent commit and this PR for each sample: 2 warmups and 20 measured samples per metric on the current machine.
The catalog target of 2 ms or less is met. Single-rail construction still performs the library-wide Colang scan; that independent bottleneck is addressed by the follow-up PR.
Areas for careful review
No user-facing documentation change is required because runtime behavior, public APIs, and configuration syntax are unchanged.
Related Issue(s)
Replace both placeholders with the shared triaged, assigned issue before submission.
Verification
make test TEST='tests/manifests tests/rails/llm/test_builtin_rail_manifests.py' WORKERS=1— 110 passed.make check-builtin-rail-catalogpassed.rail.pymodules.uv buildproduced the source distribution and wheel.nemoguardrails/manifests/builtin_rails.json.make pre-commitpassed on the completed stack containing this commit.make testpassed on the completed stack: 6,160 passed, 178 skipped.AI Assistance
Codex assisted with implementation, tests, benchmarking, and this draft. The PR author must review the changes and check the second box before submission.
Checklist