Skip to content

Add composable $import system for recipe YAML configs#1253

Draft
shengliangxu wants to merge 14 commits intomainfrom
shengliangx/composable-recipes
Draft

Add composable $import system for recipe YAML configs#1253
shengliangxu wants to merge 14 commits intomainfrom
shengliangx/composable-recipes

Conversation

@shengliangxu
Copy link
Copy Markdown
Collaborator

What does this PR do?

Type of change: New feature

Introduce a composable import system for recipe YAML files, allowing reusable config snippets to be defined once and referenced across multiple recipes via explicit $import markers.

Problem

The 6 built-in PTQ recipes duplicated the same numeric format definitions (e.g., FP8 E4M3, NVFP4 E2M1 blockwise) and the same 14-entry standard exclusion list across every file. Changing a shared pattern required editing all recipes.

Solution

Recipes can now declare an imports section mapping short names to config snippet files. The {$import: name} marker is resolved at load time:

imports:
  base_disable_all: configs/ptq/base_disable_all
  fp8: configs/numerics/fp8

quantize:
  algorithm: max
  quant_cfg:
    - $import: base_disable_all         # list splice
    - quantizer_name: '*weight_quantizer'
      cfg:
        $import: fp8                    # dict value replacement
        axis: 0                         # extend with extra keys
    - $import: default_disabled         # multi-entry list splice

$import semantics:
- Dict value: replaced with snippet content. Supports multiple imports ($import: [a, b]) and inline extension keys. Key conflicts raise errors.
- List element: snippet (must be a YAML list) is spliced into the surrounding list.
- Recursive: snippets can themselves have imports. Circular imports are detected.
- Scoped: each file's import names are independent — no cross-file name conflicts.

recipes docs are updated too


Testing

tests/unit/recipe/test_loader.py

15+ new tests covering: basic resolution, reuse, multiple snippets, inline cfg unaffected, unknown reference, empty path, not-a-dict, single-element list splice, multi-entry list splice, non-list error, entry sibling key error, cfg extend, cfg conflict, multi-import, multi-import conflict, multi-import with extend, recursive resolution, circular import detection, cross-file name scoping, directory format

All new tests pass. Existing recipe loader tests and built-in recipe smoke tests continue to pass with the converted recipes.

Before your PR is "Ready for review"

- Is this change backward compatible?: ✅ (recipes without imports load unchanged)
- Did you write any new necessary tests?: 
- Did you update Changelog?: ✅ (should be added before merge)

Commit description:

Introduce an import mechanism that lets recipe YAML files reference reusable
config snippets by name, reducing duplication across recipes.

Syntax:
  imports:
    fp8: configs/numerics/fp8
    base_disable_all: configs/ptq/base_disable_all

  quant_cfg:
    - base_disable_all # string entry → replaced with imported dict or spliced
list
    - quantizer_name: '*weight_quantizer'
      cfg: fp8 # string cfg → replaced with imported dict

Features:
- Dict-based imports (keys are names, values are config paths) — no name conflicts
- Three resolution modes: string cfg value, string list entry (dict), string list entry (list
 splice)
- Recursive resolution with circular import detection
- Path resolution via load_config (built-in library first, then filesystem)
- Works with both single-file and directory recipe formats

New reusable config snippets (modelopt_recipes/configs/):
- numerics/fp8.yml, nvfp4_dynamic.yml, nvfp4_static.yml
- ptq/base_disable_all.yaml, default_disabled_quantizers.yaml

All 6 built-in PTQ recipes converted to use imports, reducing each by ~30 lines.

Pre-commit hook updated to skip configs/ directory and allow string entries in
quant_cfg. load_config() now accepts YAML lists for list-valued snippets.

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Apr 14, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ced2ebe-2d6b-4c9e-858c-bd7683a4027e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch shengliangx/composable-recipes

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://NVIDIA.github.io/Model-Optimizer/pr-preview/pr-1253/

Built to branch gh-pages at 2026-04-14 22:25 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant