Skip to content

feat(metax): route reshape_and_cache_flash through flag_gems dispatch - #333

Open
tengqm wants to merge 1 commit into
flagos-ai:mainfrom
tengqm:feat/metax-reshape-and-cache-flash-flaggems
Open

feat(metax): route reshape_and_cache_flash through flag_gems dispatch#333
tengqm wants to merge 1 commit into
flagos-ai:mainfrom
tengqm:feat/metax-reshape-and-cache-flash-flaggems

Conversation

@tengqm

@tengqm tengqm commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem

On an empty vLLM wheel (VLLM_TARGET_DEVICE=empty), torch.ops._C_cache_ops has no compiled kernel. The MetaX flash attention backend binds reshape_and_cache_flash to vllm._custom_ops, which delegates to that missing C op and raises at the first forward pass:

AttributeError: '_OpNamespace' '_C_cache_ops' object has no attribute 'reshape_and_cache_flash'

reshape_and_cache_flash is not a dispatch op today, so it bypasses the manager entirely and has no fallback.

Fix

  • flaggems/flaggems.py — add FlagGemsBackend.reshape_and_cache_flash, forwarding to the pure-Triton flag_gems.fused.reshape_and_cache_flash.
  • flaggems/register_ops.py — register it as default.flagos, guarded by _has_flaggems_op.
  • vendor/metax/impl/attention/utils/fa_utils.py — bind the call site to CachedOp("reshape_and_cache_flash") instead of vllm._custom_ops.

Routes through the FL dispatch manager (policy-driven, fallback-capable) with no coupling to vLLM's private _C_cache_ops ABI. Standard wheels keep their existing selection.

Supersedes #319, which patched vllm._custom_ops from patches/__init__.py: its hasattr(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 serve reaches startup; /v1/completions returns coherent output.
  • Forward-pass log: Op 'reshape_and_cache_flash' using 'default.flagos' — no AttributeError.

This PR was written in part with the assistance of generative AI.

@github-actions github-actions Bot added the core label Jul 31, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant