Skip to content

feat(enflame): port GCU300 enablement bundle to main - #432

Open
tengqm wants to merge 2 commits into
flagos-ai:mainfrom
tengqm:port/enflame-gcu300-v024
Open

feat(enflame): port GCU300 enablement bundle to main#432
tengqm wants to merge 2 commits into
flagos-ai:mainfrom
tengqm:port/enflame-gcu300-v024

Conversation

@tengqm

@tengqm tengqm commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Port the Enflame GCU300 enablement bundle to main for vLLM 0.24.0. The twin PR
on the release/0.2 line is #357.

Changes (1 commit, base main @ ba52028):

  • gcu.pyGCUBackend dispatchers for silu_and_mul / rms_norm /
    rotary_embedding, plus an attention selector that falls back to the plugin
    AttentionFLBackend when the empty vLLM wheel ships no compiled
    flash_attn.vllm_flash_attn._vllm_fa2_C (and aliases
    sys.modules["vllm.vllm_flash_attn"] when the native path is taken).
  • gcu/impl/slot_mapping.py — on-device int32 slot mapping built with
    searchsorted instead of repeat_interleave (grid.y 255 cap).
  • gcu/patch.py — patch module.
  • dispatch/config/gcu.yaml — flag_gems blacklist for the GCU300 int64
    codegen wall (sort / sort_stable / rsub_scalar / rsub_tensor) and argmax
    correctness.
  • dispatch/config/utils.py — device-name fallback in get_config_path so
    gcu.yaml loads for vendor_name == "enflame".

Notes

  • The attention fallback was authored against fix(attention): split KV-cache write from forward for vLLM v1 #353 (split KV-cache write from
    forward), which is closed unmerged on this repo; on main the
    forward_includes_kv_cache_update attribute defaults to True on vLLM's
    AttentionBackend, so the read site in model_runner is safe. Whether the
    GCU300 KV-cache path needs the split is to be confirmed on-node.
  • The FlagTree path on GCU300 hits a compiler-level int64 codegen wall (same as
    the 0.20.2 line) and is blacklisted in gcu.yaml; the Triton path is the
    verified route.

Verification

Pending on-node: tops1.10.6 and tops1.9.10, app image serve E2E with Qwen3-4B.


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

@github-actions github-actions Bot added the core label Sep 2, 2026
import vllm.v1.worker.block_table as bt

bt.BlockTable.compute_slot_mapping = _compute_slot_mapping_torch
_patched = True
apply_chunk_delta_h_gcu_patch()
apply_fused_recurrent_packed_decode_gcu_patch()
apply_slot_mapping_gcu_patch()
_patches_applied = True
alias_file = _CONFIG_DIR / f"{device_name}.yaml"
if alias_file.exists():
return alias_file
except Exception:
Comment on lines +7683 to +7685
from vllm_fl.dispatch.backends.vendor.gcu.sampler import ( # noqa: F401
_random_sample_gcu,
)
from vllm_fl.dispatch.backends.vendor.gcu.sampler import ( # noqa: F401
_random_sample_gcu,
)
except Exception:
Port the GCU300 enablement to the 0.24.0 dispatch framework (squash of
the five-branch history 3402afc..369a551 into one unit):

- register enflame in VENDOR_DEVICE_MAP so the platform plugin activates
  on torch.gcu
- add the gcu arm to compilation-graph selection
- GCU300 enablement bundle: vendor:gcu attention backend, int64
  factory/index blacklist (zeros/add/sub -> torch_gcu), native
  FLASH_ATTN path wiring
- drop generator-seeded exponential from the GCU sampler (correctness)
- clamp max_num_batched_tokens to 2047 on GCU

Deliberately NOT included here: the attention/operator layer that
0.20.2 delivered (flash_attn_backend binding, register_ops, activation &
friends) — that follows as the next commit on top of this one.
@tengqm
tengqm force-pushed the port/enflame-gcu300-v024 branch from 369a551 to 542026a Compare September 3, 2026 04:53
The squash commit carried the platform skeleton (device-map registration,
gcu config, slot_mapping int32 rewrite, sampler seed-drop, config clamps)
but NOT the operator layer the 0.20.2 enflame run verified — the files
patch.py and gcu.py import by name were simply absent, so any dispatch hit
(silu_and_mul / rms_norm / rotary_embedding) raised ImportError and the
native-FLASH_ATTN binding never ran. Restore from the verified 0.20.2 tree
(3431992, vllm-plugin-FL flagos-ai#357); the vLLM internals they patch (v1 attention
fa_utils/flash_attn, model_executor.layers.fla.ops, triton_utils) are
unchanged in 0.24.0 (metax ships the same fla.ops imports):

- impl/activation.py, normalization.py, rotary.py — pure-torch reference
  impls for the dispatch points gcu.py declares (the missing-import bug)
- impl/flash_attn_backend.py — the native-FLASH_ATTN enablement: binds
  vendor flash_attn.vllm_flash_attn + flag_gems reshape_and_cache_flash
  onto fa_utils and forces is_flash_attn_varlen_func_available() True
  (empty wheel strips vllm._C). This is the garbage-decode root cause.
- impl/bilinear_pos_embed.py, chunk_delta_h.py,
  fused_recurrent_packed_decode.py — GCU grid-cap kernel patches
  (qwen3-vl / FLA linear-attention paths)
- patch.py: re-add apply_flash_attn_backend_gcu_patch to apply_gcu_patches
- platform.py import_kernels: add the device_type == 'gcu' branch so
  apply_gcu_patches() actually runs (nothing called it before — same
  shape as the existing musa branch)
p_h0_3 = tl.make_block_ptr(
h0, (V, K), (K, 1), (i_v * BV, 128), (BV, 64), (1, 0)
)
b_h3 += tl.load(p_h0_3, boundary_check=(0, 1)).to(tl.float32)
p_h0_4 = tl.make_block_ptr(
h0, (V, K), (K, 1), (i_v * BV, 192), (BV, 64), (1, 0)
)
b_h4 += tl.load(p_h0_4, boundary_check=(0, 1)).to(tl.float32)
chunk_indices: torch.Tensor | None = None,
chunk_offsets: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor | None]:
B, T, Hg, K, V = *k.shape, u.shape[-1]

qwen3_vl.triton_pos_embed_interpolate = triton_pos_embed_interpolate_gcu
qwen3_vl._bilinear_pos_embed_kernel = _bilinear_pos_embed_kernel_gcu
_patched = True
# chunk.py / kda.py bind chunk_gated_delta_rule_fwd_h at import time.
chunk_mod.chunk_gated_delta_rule_fwd_h = chunk_gated_delta_rule_fwd_h_gcu
kda_mod.chunk_gated_delta_rule_fwd_h = chunk_gated_delta_rule_fwd_h_gcu
_patched = True
gdn_linear_attn.fused_recurrent_gated_delta_rule_packed_decode = (
fused_recurrent_gated_delta_rule_packed_decode_gcu
)
_patched = True
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.

2 participants