Skip to content

[Inductor][NVGEMM] Guard optional operator import - #198292

Closed
mlazos wants to merge 1 commit into
gh/mlazos/321/basefrom
gh/mlazos/321/head
Closed

mlazos wants to merge 1 commit into
gh/mlazos/321/basefrom
gh/mlazos/321/head

Conversation

@mlazos

@mlazos mlazos commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Human commentary: Fixes operator import

AI-generated draft:

Issue

Fixes #197463

Summary

ensure_nv_universal_gemm_available() located cutlass.operators inside its guarded availability check but imported it later through FP4 registration. A present but broken optional installation could therefore raise ImportError while lowering an ordinary matrix multiplication instead of disabling NVGEMM.

Keep FP4 registration inside the existing ImportError and ValueError boundary. This preserves the probe's boolean contract for every caller; merely reordering the autotune checks would leave direct callers exposed.

For example, when find_spec("cutlass.operators") succeeds but importing its dtype utilities fails, the probe now returns False and Inductor can use another GEMM backend.

Checklist

  • Passes lint (spin fixlint is unavailable in this environment)
  • Added a regression test
  • Documentation is not applicable
  • Benchmarks are not applicable

Tests

python test/inductor/test_utils.py TestFP4Support.test_ensure_nv_universal_gemm_import_error passed (1 test).

python test/inductor/test_utils.py TestFP4Support passed (4 tests, 1 skipped).

A real stub package whose cutlass/operators/__init__.py raises ImportError returned False after the fix. The refreshed main worktree could not run through the normal editable installation because that installation targets an older worktree; the source-level behavior and diff are unchanged.

BC-breaking?

No. This restores the documented availability-probe behavior for a broken optional dependency.

Authored with assistance from an AI coding agent.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

The NVGEMM availability probe only guarded module discovery, while FP4 registration imported the optional operators package after the guard. A discoverable but broken installation therefore raised during ordinary Inductor lowering instead of disabling the optional backend.

Run FP4 registration inside the existing ImportError and ValueError boundary so the probe consistently returns False. Guarding the probe itself keeps direct callers safe; merely reordering autotune gates would leave the boolean availability contract broken.

Test Plan:

```
python test/inductor/test_utils.py TestFP4Support.test_ensure_nv_universal_gemm_import_error
```

Passed (1 test).

```
python test/inductor/test_utils.py TestFP4Support
```

Passed (4 tests, 1 skipped).

```
lintrunner -a
```

Passed with no lint issues in the initialized checkout. The refreshed worktree rerun is blocked by unrelated editable-build and lintrunner initialization skew.

Fixes #197463

Authored with assistance from an AI coding agent.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198292

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 4 Unrelated Failures

As of commit 08ffdbe with merge base 6a895d1 (image):

NEW FAILURE - The following job has failed:

  • trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable) (gh)
    test_numpy_interop

    AI verdict: AI verdict: probably not related

    The test_numpy_interop process died with SIGBUS about 0.27s after it started, before pytest had written its stepcurrent file, so the crash happened during interpreter or module import. The suspect commit only reorders three lines of pure Python inside ensure_nv_universal_gemm_available(), a CUDA/NVGEMM probe that is only reached from Inductor GEMM lowering. Neither this test nor its imports reach that function, so this looks like a one-off native crash on the macOS runner.

    Full reasoning on HUD →

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@mlazos

mlazos commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

AI-Review

Automated multi-agent review (architecture, correctness, simplification, generalization, and GPT-5.6 final approval). This is AI-generated — please verify findings manually.


No verified issues found.

@mlazos
mlazos marked this pull request as ready for review September 23, 2026 22:44
@mlazos

mlazos commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 23, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable)

Details for Dev Infra team Raised by workflow job

@mlazos

mlazos commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 2, 2, mt-l-x86iamx-8-64, unstable), inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 1, 2, mt-l-x86iamx-8-64, unstable), trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Sep 24, 2026
Human commentary: Fixes a bug where 2-CTA kernels weren't considered.

AI-generated draft:

> ## Issue
>
> Fixes #196313
>
> ## Summary
>
> `nvMatmulHeuristics` reports tile M per CTA, while CUTLASS reports a pair-wide M tile for true 2-CTA kernels. Comparing those values directly prevented recommended dense 2-CTA kernels from entering NVGEMM autotuning.
>
> Normalize heuristic-matching keys using the implementation's `use_2cta_instrs` metadata, with a guarded design-metadata fallback for older kernels. The design flag alone is insufficient because block-scaled operators can set it for 1-CTA kernels. Supplemental configs continue to use raw design coordinates, preserving distinct 128-row and 256-row candidates.
>
> For example, a dense pair-wide `(256, 128, 2, 1)` design now matches the heuristic's per-CTA `(128, 128, 2, 1)` recommendation, while a block-scaled 1-CTA `(128, 128, 2, 1)` design remains unchanged.
>
> ## Checklist
>
> - [ ] Passes lint (`spin fixlint` is unavailable in this environment)
> - [x] Added regression tests
> - [x] Documentation is not applicable
> - [ ] B300 benchmarks were not rerun locally; reporter results are linked in #196313
>
> ## Tests
>
> The focused source-loaded filtering suite passed 6 tests covering dense 2-CTA normalization, block-scaled 1-CTA preservation, metadata fallback and absence, ordering, and supplemental raw-key collisions.
>
> `lintrunner -a --skip PYREFLY torch/_inductor/heuristics/template/nv_universal_gemm.py test/inductor/test_nv_universal_gemm.py` passed with no lint issues. Full `lintrunner -a` exited successfully but emitted unrelated repo-wide Pyrefly diagnostics because the refreshed worktree has no lintrunner initialization and the editable build targets an older checkout.
>
> B300 performance was not available locally; the issue contains the reporter's B300 timings for the same key correction.
>
> ## BC-breaking?
>
> No. This corrects internal matching of equivalent kernel metadata and preserves existing supplemental-key behavior.
>
> Authored with assistance from an AI coding agent.

Pull Request resolved: #198293
Approved by: https://github.com/drisspg
ghstack dependencies: #198292
jeanschmidt added a commit to pytorch/test-infra that referenced this pull request Oct 1, 2026
…ss (#8920)

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0)
(oldest at bottom):
* #8926
* #8924
* #8923
* #8922
* #8921
* __->__ #8920
* #8919
* #8918

Adds an exclusion to Single-cause bugfix: not when the fix turns an
error into a quieter outcome, a warning or a dropped or substituted
value, that the function's documentation did not already promise.
pytorch/pytorch#196687 made an unpicklable `__doc__` drop to None with a
warning instead of failing the save; albanD ruled that choosing how to
fail needs a reviewer.

Intended verdicts: pytorch/pytorch#196687 NO_LAND,
pytorch/pytorch#198292 LAND (its docstring already promised the False
result).

Test plan: greenlight suite 2005 passed, parsers 152, test_remap 14.
@github-actions
github-actions Bot deleted the gh/mlazos/321/head branch November 29, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor release notes: inductor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants