Skip to content

[Tests]: Precommit Check for Spec-Dec Recipes - #1527

Merged
h-guo18 merged 2 commits into
mainfrom
haoguo/recipe-precommit-checks
Jun 12, 2026
Merged

[Tests]: Precommit Check for Spec-Dec Recipes#1527
h-guo18 merged 2 commits into
mainfrom
haoguo/recipe-precommit-checks

Conversation

@h-guo18

@h-guo18 h-guo18 commented May 21, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new tests / tooling

Adds pre-commit validation for speculative-decoding recipes (the existing check-modelopt-recipes hook only ran on PTQ) and for launcher YAML references into the recipe library.

  • tools/precommit/check_modelopt_recipes.py: accept speculative_eagle / speculative_dflash / speculative_medusa in addition to ptq, so per-model spec-dec recipes (e.g. modelopt_recipes/models/Qwen3-8B/dflash.yaml) get full Pydantic validation via load_recipe() at commit time.
  • tools/precommit/check_launcher_yaml.py (new): scans every tools/launcher/examples/**/*.yaml for --config <path> and data.chat_template=<path> references, verifies the resolved files exist, and runs load_recipe() on any path under modelopt_recipes/. Skips <<global_vars.x>> interpolation. pass_filenames: false so recipe-side edits also re-validate all launcher references.

Usage

pre-commit run check-modelopt-recipes --all-files
pre-commit run check-launcher-yaml --all-files

Testing

Smoke-tested both hooks manually:

Scenario Result
spec-dec recipe with dflash_block_size: not_an_int exit 1, Pydantic int_parsing error
launcher YAML with non-existent --config path exit 1, source file + resolved path reported
launcher YAML with non-existent data.chat_template path exit 1
Current repo state (all valid) exit 0

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅ (hooks themselves are the tests)
  • Did you update Changelog?: N/A
  • Did you get Claude approval on this PR?: ❌ pending

Additional Information

Motivated by the per-model recipe migration in #TBD — without these hooks, broken --config paths and recipe schema typos surface only at CI or runtime.

Summary by CodeRabbit

  • Chores
    • Added an automated pre-commit check that validates launcher example YAMLs, reporting parse errors and missing or invalid references.
    • Expanded recipe validation to cover additional recipe types beyond PTQ, improving detection of invalid recipe formats and metadata.
@copy-pr-bot

copy-pr-bot Bot commented May 21, 2026

Copy link
Copy Markdown

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

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new pre-commit hook that scans launcher example YAMLs, extracts and resolves --config and .chat_template= arguments, verifies referenced files exist, and invokes modelopt.recipe.loader.load_recipe() for configs under modelopt_recipes/. Also broadens recipe-file detection to include speculative-decoding recipe types alongside PTQ; the new hook is registered in .pre-commit-config.yaml without pass_filenames: false.

Changes

Pre-commit validation system enhancements

Layer / File(s) Summary
Launcher YAML validation hook
tools/precommit/check_launcher_yaml.py, .pre-commit-config.yaml
New pre-commit hook scans tools/launcher/examples/*.yaml (or all examples if the hook script changed), safely parses pipeline tasks, extracts --config <path> and .chat_template=<path> references, resolves launcher-relative/submodule paths, checks file existence, and calls modelopt.recipe.loader.load_recipe() for modelopt_recipes/* configs. The hook is registered in .pre-commit-config.yaml (no pass_filenames: false setting).
Recipe type expansion
tools/precommit/check_modelopt_recipes.py
Adds _SUPPORTED_RECIPE_TYPES (PTQ plus speculative-decoding types such as EAGLE, DFlash, Medusa), updates _is_recipe_file() to accept these types for single-file recipes, and documents that directory-format metadata detection remains PTQ-only and that quant_cfg must be a list-of-dicts with quantizer_name keys.

sequenceDiagram
  participant PreCommit as PreCommitHook
  participant Scanner as LauncherScanner
  participant Parser as YAMLParser
  participant Resolver as PathResolver
  participant FS as Filesystem
  participant Loader as RecipeLoader
  PreCommit->>Scanner: select tools/launcher/examples/*.yaml (or all when hook changed)
  Scanner->>Parser: safe_load each YAML pipeline/tasks
  Parser->>Resolver: extract --config and .chat_template paths
  Resolver->>FS: resolve repo/submodule paths
  FS->>Loader: call modelopt.recipe.loader.load_recipe for modelopt_recipes/* configs
  Loader-->>PreCommit: return validation errors or success
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[Tests]: Precommit Check for Spec-Dec Recipes' partially relates to the changeset. It highlights the spec-dec recipe validation aspect but omits the significant new launcher YAML checking functionality, which is a substantial part of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed Scanned changed Python files for SECURITY.md anti-patterns (torch.load weights_only=False, numpy.load allow_pickle=True, trust_remote_code=True, eval/exec, # nosec) and found none.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch haoguo/recipe-precommit-checks

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

@h-guo18 h-guo18 changed the title [Tests]: Precommit Check for Spec-Dec Recipes May 21, 2026
@h-guo18 h-guo18 changed the title [Test]: Precommit Check for Spec-Dec Recipes May 21, 2026
@h-guo18
h-guo18 marked this pull request as ready for review May 21, 2026 21:32
@h-guo18
h-guo18 requested a review from a team as a code owner May 21, 2026 21:32
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.65%. Comparing base (46eddab) to head (df6bb49).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1527      +/-   ##
==========================================
- Coverage   67.73%   67.65%   -0.08%     
==========================================
  Files         511      511              
  Lines       56169    56256      +87     
==========================================
+ Hits        38044    38060      +16     
- Misses      18125    18196      +71     
Flag Coverage Δ
unit 54.33% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@shengliangxu

Copy link
Copy Markdown
Collaborator

A bit confused by the scope: is the change for general launcher yaml check or for spec-dec specific recipes check?

@h-guo18

h-guo18 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

A bit confused by the scope: is the change for general launcher yaml check or for spec-dec specific recipes check?

Both. It adds checks for spec-dec recipes and all yamls that appears in the general launcher.

Comment thread .pre-commit-config.yaml Outdated
entry: python tools/precommit/check_launcher_yaml.py
language: system
files: ^(tools/launcher/examples/.*\.yaml|modelopt_recipes/.*\.yaml|tools/precommit/check_launcher_yaml\.py)$
pass_filenames: false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, so this behaviour is not expected:

It seems the precommit check script gets activated once there are modifications to any file in the above pattern, but then it will scan all the files even for files that have no modifications.

We should scope to only modified files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Now this hook only scan the changed yaml files under tools/launcher.

Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
@h-guo18
h-guo18 force-pushed the haoguo/recipe-precommit-checks branch from b9296fc to c306d15 Compare June 11, 2026 01:49
Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tools/precommit/check_launcher_yaml.py (1)

163-164: 💤 Low value

Verify performance impact of full re-scan on script edits.

When this script is modified, all launcher YAMLs are re-scanned. If the examples/ directory grows large, this could slow down commits that touch this file. Consider whether this safety mechanism's value justifies the performance trade-off.

For now, this is a reasonable design—edits to validation logic should exercise the full test surface—but worth monitoring if the launcher YAML set grows significantly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/precommit/check_launcher_yaml.py` around lines 163 - 164, The current
guard (if path == this_file: return _all_launcher_yamls()) forces a full re-scan
of all launcher YAMLs when this script is edited; measure the commit-time cost
by timing _all_launcher_yamls() on a large examples/ tree and, if expensive,
implement a faster alternative: either add an opt-in config/env flag (e.g.,
SKIP_FULL_RESCAN) to short-circuit the full scan for local edits, or replace the
unconditional full scan with an incremental selection using git-changed-file
logic to compute only affected launcher files, and ensure the change is wired
into the same branch where path, this_file, and _all_launcher_yamls() are
referenced so behavior is preserved when desired.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tools/precommit/check_launcher_yaml.py`:
- Around line 163-164: The current guard (if path == this_file: return
_all_launcher_yamls()) forces a full re-scan of all launcher YAMLs when this
script is edited; measure the commit-time cost by timing _all_launcher_yamls()
on a large examples/ tree and, if expensive, implement a faster alternative:
either add an opt-in config/env flag (e.g., SKIP_FULL_RESCAN) to short-circuit
the full scan for local edits, or replace the unconditional full scan with an
incremental selection using git-changed-file logic to compute only affected
launcher files, and ensure the change is wired into the same branch where path,
this_file, and _all_launcher_yamls() are referenced so behavior is preserved
when desired.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b604c63a-0d87-4d16-b317-abc543e0b365

📥 Commits

Reviewing files that changed from the base of the PR and between c306d15 and df6bb49.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml
  • tools/precommit/check_launcher_yaml.py
@h-guo18
h-guo18 requested a review from shengliangxu June 11, 2026 20:16

@shengliangxu shengliangxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@h-guo18
h-guo18 merged commit cfc823d into main Jun 12, 2026
37 checks passed
@h-guo18
h-guo18 deleted the haoguo/recipe-precommit-checks branch June 12, 2026 00:40
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-12 00:40 UTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants