fix(types): suppress mypy false-positive on HIP-gated cascade call - #236
Merged
demandal25 merged 2 commits intoMay 20, 2026
Merged
Conversation
cascade.py:547 calls `wrapper.run(..., partial_state=(out, lse))` inside the `_HIP_FUSED_CASCADE` branch. At runtime on HIP, flashinfer/__init__.py:262 aliases sys.modules["flashinfer.prefill"] to prefill_rocm, whose run() accepts partial_state. mypy can't follow that runtime swap and only sees prefill.py (CUDA), whose run() doesn't have partial_state — so it errors with "No overload variant of run matches". Targeted `# type: ignore[call-overload]` with a comment explaining the runtime aliasing. No change to either wrapper's typed contract: adding partial_state to CUDA's @overload would misleadingly suggest CUDA implements a HIP-only feature. This unblocks pre-commit on every PR. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
demandal25
force-pushed
the
fix-ci-pre-commit-and-docs
branch
from
May 20, 2026 14:34
3c7d385 to
d4e8193
Compare
There was a problem hiding this comment.
Pull request overview
Fixes two repository-wide CI failures unrelated to individual PR content: mypy errors in pre-commit for a HIP-only code path, and Read the Docs builds failing due to attempting an editable install that requires CUDA/ROCm toolchains.
Changes:
- Add a targeted
# type: ignore[call-overload]on a HIP-gated call site where static typing can’t follow a runtime module alias swap. - Make
docs/conf.pyresilient toimport flashinferfailing (e.g., in RTD) by falling back to a default version string. - Add a minimal
.readthedocs.yamlto build docs withoutpip install -e .and without GPU toolchains.
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
flashinfer/cascade.py |
Adds a mypy suppression for a HIP-only call that uses a runtime aliasing pattern mypy can’t model. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Suppresses a mypy
call-overloaderror atflashinfer/cascade.py:547that has been failingpre-commiton every PR since cascade attention landed (#221), with a localized# type: ignore[call-overload]and an explanatory comment.What changed
flashinfer/cascade.py:547— Added# type: ignore[call-overload]to the_HIP_FUSED_CASCADEbranch's call towrapper.run(..., partial_state=(out, lse)), plus a two-line comment explaining the runtime aliasing that mypy cannot see.No behavior change. mypy now passes.
Root cause
cascade.pyimportsBatchPrefillWithPagedKVCacheWrapperfromflashinfer.prefill(the CUDA module). At runtime on HIP,flashinfer/__init__.py:262does:so
wrapperis actually the HIP variant, whoserun()acceptspartial_state. mypy can't follow that runtimesys.modulesswap — it always sees the CUDAprefill.pyoverloads, which don't declarepartial_state— so it errors with:This was the only mypy error in the tree, so every PR's
pre-commitcheck has shipped red since #221.Design choice: minimal
type: ignorevs broader refactor# type: ignore[call-overload]+ commentcast(HIPWrapper, wrapper)+ fix HIP@overloadscastdocuments intent slightly better; HIP@overloads match implpartial_stateto CUDA@overloads with a runtimeraise NotImplementedErrorSemantically,
cast(HIPWrapper, wrapper)and# type: ignore[call-overload]say the same thing to mypy — "trust me, this call is valid" — and carry identical runtime risk.Reasons for the minimal fix in this PR:
_HIP_FUSED_CASCADEis opt-in and default off (os.environ.get("FLASHINFER_HIP_FUSED_CASCADE", "0") == "1"). It's an experimental kernel-fusion optimization. A heavier mypy ceremony for an opt-in experimental branch is poor ROI._HIP_FUSED_CASCADEitself, not its visible type symptom. Routing through a HIP helper or addingcasttidies the symptom but doesn't remove the leak —cascade.pywould still need to know HIP exists.A future PR that promotes
FLASHINFER_HIP_FUSED_CASCADEfrom experimental to default-on is the right moment to revisit this. The correct fix at that point is probably exposing the fusion through a uniformrun_and_merge(...)method on both backends (CUDA's variant being two kernel launches), not addingpartial_stateto CUDA's signature.Why not also fix
partial_stateinprefill_rocm.py's@overloads?The HIP wrapper's
@overloaddeclarations also lackpartial_state, which is a latent contract gap (impl signature and overloads don't match). Butcascade.pyimports from the CUDAprefill.pymodule, so mypy never checks against the HIP overloads — fixing them has zero effect on this CI failure. Out of scope here; can be cleaned up alongside the future refactor above.Test plan
pre-commit run --all-files— all hooks pass (mypy included)pytest -n auto --reruns 2 -m "not slow"— full fast suite passes (no behavior change expected)pre-commitcheck goes green