Skip to content

testing doctest - #2652

Draft
grzegorz-k-karch wants to merge 2 commits into
mainfrom
gkarch/doctest
Draft

grzegorz-k-karch wants to merge 2 commits into
mainfrom
gkarch/doctest

Conversation

@grzegorz-k-karch

@grzegorz-k-karch grzegorz-k-karch commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

!! Draft description below, not yet reviewed by PR author, so don't bother reviewing it yourself

What does this PR do?

Type of change: New tests

Adds an opt-in pytest framework that executes reader-visible Markdown shell fences, helping catch documentation regressions without maintaining separate copies of example commands.

Hidden HTML comments define scenarios, resource profiles, timeouts, Python setup and artifact verification. The runner preserves shell state between fences, captures output, reports Markdown file/line locations, and cleans up subprocess groups. Unmarked fences never execute.

The pilot covers recipe listing and the PTQ → QAT → export workflow in examples/llm_qat/README.md, using a tiny local Qwen3 checkpoint and synthetic data while retaining real NVFP4 quantization and FSDP2 training. It also adds the missing working-directory change and ensures README changes trigger the existing example CI lane.

Usage

From the repository root:

# Offline CPU framework tests
python -m pytest tests/unit/doc_tests \
  --confcutdir=tests/unit/doc_tests -o addopts='' -q

# Collect annotated README scenarios without executing them
python -m pytest tests/examples/llm_qat/test_readme.py \
  --collect-only --no-cov

# Single-GPU acceptance
CUDA_VISIBLE_DEVICES=0 python -m pytest \
  tests/examples/llm_qat/test_readme.py --no-cov -s

# Two-GPU FSDP2 acceptance
CUDA_VISIBLE_DEVICES=0,1 MODELOPT_DOC_TEST_GPUS=2 \
  python -m pytest tests/examples/llm_qat/test_readme.py --no-cov -s

See tests/_test_utils/doc_tests/README.md for the annotation contract and container setup.

Testing

  • 27 CPU tests passed, covering opt-in execution, malformed directives, shell state persistence, checkout imports, error locations, timeouts and subprocess cleanup. Also passed with repository-wide pytest fixtures enabled.
  • One- and two-GPU acceptance passed on H100 80GB GPUs: recipe listing and the complete QAT scenario.
  • Artifact verification confirmed saved ModelOpt state, two completed optimizer steps, finite losses, changed trained weights, and packed NVFP4 export.
  • README collection, all applicable pre-commit hooks, and git diff --check passed.

GPU validation used the PyTorch 26.07 container’s matching Torch/FlashAttention binaries in a temporary environment. The existing development virtual environment had an incompatible FlashAttention binary.

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices.

  • 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 — no copied third-party code or new project dependency.
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: N/A — test infrastructure and documentation changes.
  • Did you get Claude approval on this PR?: ❌ — pending /claude review.

Additional Information

The smoke tests establish that the documented commands compose and produce real artifacts. They do not establish full-model accuracy, convergence, memory requirements, serving compatibility or inference performance.

Installation and QAD fences remain outside the pilot. Existing backend tests are retained for broader coverage, including DDP and DeepSpeed. Annotated Markdown executes as trusted repository test code; the runner is not a security sandbox.

Summary by CodeRabbit

  • New Features

    • Added executable scenarios to the LLM QAT README, with CPU and GPU test profiles.
    • Added support for running and validating marked scenarios in Markdown documentation.
  • Documentation

    • Documented scenario directives, execution behavior, and commands for local testing and acceptance checks.
  • Tests

    • Added checks for scenario parsing, execution, error reporting, timeouts, cleanup, and QAT workflow results.

Signed-off-by: Grzegorz Karch <gkarch@nvidia.com>
@grzegorz-k-karch grzegorz-k-karch self-assigned this Oct 3, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/Model-Optimizer/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 7ff0bd7d-db9e-4f50-8257-6b6219e90896
📥 Commits

Reviewing files that changed from the base of the PR and between 6a10687 and ed136b6.

📒 Files selected for processing (9)
  • .github/workflows/example_tests.yml
  • examples/llm_qat/README.md
  • tests/_test_utils/doc_tests/README.md
  • tests/_test_utils/doc_tests/fixtures/llm_qat.py
  • tests/_test_utils/doc_tests/parser.py
  • tests/_test_utils/doc_tests/runner.py
  • tests/examples/README.md
  • tests/examples/llm_qat/test_readme.py
  • tests/unit/doc_tests/test_markdown.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

The change adds executable Markdown scenarios and a runner, then uses them to test the LLM QAT README with reduced-scale fixtures. It also updates example-test change detection and adds documentation and unit tests for the scenario framework.

Changes

Executable Markdown documentation tests

Layer / File(s) Summary
Parse and validate Markdown scenarios
tests/_test_utils/doc_tests/parser.py, tests/_test_utils/doc_tests/README.md, tests/unit/doc_tests/test_markdown.py
The parser recognizes marked scenarios and validates metadata, executable fences, and step order. Unit tests cover malformed directives and scenario boundaries. The documentation describes the directive contract.
Run scenarios with shared state and timeouts
tests/_test_utils/doc_tests/runner.py, tests/_test_utils/doc_tests/README.md, tests/unit/doc_tests/test_markdown.py
The runner executes setup, shell commands, and verification under one timeout. It cleans up the process group and reports failures with captured output. Tests cover execution state, errors, timeouts, and cleanup.
Exercise the LLM QAT README
examples/llm_qat/README.md, tests/_test_utils/doc_tests/fixtures/llm_qat.py, tests/examples/llm_qat/test_readme.py, tests/examples/README.md, tests/_test_utils/doc_tests/README.md, .github/workflows/example_tests.yml, tests/unit/doc_tests/test_markdown.py
The README defines CPU and GPU scenarios. Fixtures create a reduced local workspace and verify training and export artifacts. Pytest collects and runs the scenarios, and the workflow detects README changes in the PyTorch lane.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant pytest
  participant parse_markdown
  participant run_scenario
  participant scenario_process
  participant prepare_llm_qat_workspace
  participant verify_llm_qat_workspace
  pytest->>parse_markdown: collect README scenarios
  pytest->>run_scenario: execute selected scenario
  run_scenario->>scenario_process: launch with timeout
  scenario_process->>prepare_llm_qat_workspace: create temporary workspace
  scenario_process->>scenario_process: run README shell commands
  scenario_process->>verify_llm_qat_workspace: check QAT artifacts
  scenario_process-->>run_scenario: return output or failure
  run_scenario-->>pytest: return output or raise error
Loading

Suggested reviewers: kevalmorabia97

Merge Risk: ⚪ Minimal · up to ed136

This change adds opt-in documentation tests and a CI trigger for README changes. It does not alter production behavior, and no concrete merge-blocking risk was found in the supplied context.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 5 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title refers to the pull request’s documentation-test framework, but it does not specify that the tests execute annotated Markdown scenarios.
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 No listed critical pattern was introduced in the checked scope. The reviewed diff changes no Python files under modelopt/ or examples/, and changes no pyproject.toml or requirements file. The ne…
Full details: Docstring Coverage

Explanation

Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 5 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.07%. Comparing base (f094f89) to head (ed136b6).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2652      +/-   ##
==========================================
- Coverage   69.49%   68.07%   -1.43%     
==========================================
  Files         614      620       +6     
  Lines       68631    71158    +2527     
==========================================
+ Hits        47694    48438     +744     
- Misses      20937    22720    +1783     
Flag Coverage Δ
examples-diffusers 21.30% <ø> (-0.04%) ⬇️
examples-gpt-oss 13.58% <ø> (-0.04%) ⬇️
examples-hf_ptq 23.18% <ø> (-0.01%) ⬇️
examples-llm_distill 13.64% <ø> (-0.04%) ⬇️
examples-llm_eval 17.59% <ø> (-0.03%) ⬇️
examples-llm_qat 17.79% <ø> (+0.01%) ⬆️
examples-llm_sparsity 16.01% <ø> (-0.05%) ⬇️
examples-megatron_bridge 27.10% <ø> (+0.41%) ⬆️
examples-specdec_bench 13.34% <ø> (-0.04%) ⬇️
examples-speculative_decoding 18.00% <ø> (+<0.01%) ⬆️
examples-torch_onnx 21.86% <ø> (-0.07%) ⬇️
examples-torch_trt 15.39% <ø> (-0.03%) ⬇️
examples-vllm_serve 13.82% <ø> (-0.04%) ⬇️
unit 58.67% <ø> (-0.69%) ⬇️

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.

Signed-off-by: Grzegorz Karch <gkarch@nvidia.com>

This branch has not been deployed

No deployments
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