feat(metax): route reshape_and_cache_flash through flag_gems dispatch - #333
Open
tengqm wants to merge 1 commit into
Open
feat(metax): route reshape_and_cache_flash through flag_gems dispatch#333tengqm wants to merge 1 commit into
tengqm wants to merge 1 commit into
Conversation
On an empty vLLM wheel (VLLM_TARGET_DEVICE=empty) there is no compiled
_C_cache_ops kernel, so the MetaX attention path crashes at the first
forward pass: fa_utils.py binds reshape_and_cache_flash to
vllm._custom_ops, which delegates to the missing
torch.ops._C_cache_ops.reshape_and_cache_flash and raises AttributeError.
Register reshape_and_cache_flash as a flag_gems op (default.flagos,
guarded by _has_flaggems_op) backed by the pure-Triton
flag_gems.fused.reshape_and_cache_flash, and bind the metax call site to
CachedOp("reshape_and_cache_flash"). No coupling to vllm's private
_C_cache_ops ABI; standard wheels keep their existing selection.
This PR was written in part with the assistance of generative AI.
tengqm
force-pushed
the
feat/metax-reshape-and-cache-flash-flaggems
branch
from
July 31, 2026 08:12
92f5f0d to
ff1c8e4
Compare
This was referenced Jul 31, 2026
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.
Problem
On an empty vLLM wheel (
VLLM_TARGET_DEVICE=empty),torch.ops._C_cache_opshas no compiled kernel. The MetaX flash attention backend bindsreshape_and_cache_flashtovllm._custom_ops, which delegates to that missing C op and raises at the first forward pass:reshape_and_cache_flashis not a dispatch op today, so it bypasses the manager entirely and has no fallback.Fix
flaggems/flaggems.py— addFlagGemsBackend.reshape_and_cache_flash, forwarding to the pure-Tritonflag_gems.fused.reshape_and_cache_flash.flaggems/register_ops.py— register it asdefault.flagos, guarded by_has_flaggems_op.vendor/metax/impl/attention/utils/fa_utils.py— bind the call site toCachedOp("reshape_and_cache_flash")instead ofvllm._custom_ops.Routes through the FL dispatch manager (policy-driven, fallback-capable) with no coupling to vLLM's private
_C_cache_opsABI. Standard wheels keep their existing selection.Supersedes #319, which patched
vllm._custom_opsfrompatches/__init__.py: itshasattr(torch.ops, "_C_cache_ops")guard is always True (the namespace is lazily auto-created), so the patch never fired, and it routed to vLLM's Triton op which MetaX C550 disables.Testing
Verified on MetaX C550, Qwen3-4B, TP=1,
--enforce-eager, empty repacked vLLM wheel + this plugin:vllm servereaches startup;/v1/completionsreturns coherent output.Op 'reshape_and_cache_flash' using 'default.flagos'— noAttributeError.This PR was written in part with the assistance of generative AI.