[fix] baseline5 1.8192->4096 solve oom 2. bridge.linear 导过去

This commit is contained in:
root
2026-08-20 06:33:38 +00:00
parent 882669b0bc
commit 8842a5ffef
4 changed files with 569 additions and 2 deletions

View File

@@ -8,11 +8,13 @@ Architecture (matching xllm/core/layers/ilu/ dispatch chain):
→ layers/ilu/attention.cpp → kernels/ilu/attention.cpp → ixformer::infer
→ layers/common/rms_norm.cpp → kernels/ilu/norm.cpp → ixformer::infer
→ layers/common/activation.cpp → kernels/ilu/activation.cpp → ixformer::infer
→ layers/common/linear.cpp → kernels/ilu/matmul.cpp → ixformer_linear_ex
→ layers/ilu/fused_moe.cpp → kernels/ilu/fused_moe.cpp → ixformer::infer
Our Python equivalent:
qwen3_5.py → Qwen3_5ForCausalLM.forward()
→ patch_vllm_hot_path → xllm_ops → xllm_*.so → ixformer::infer
→ patch_vllm_hot_path → UnquantizedLinearMethod → ix_moe_bridge.linear
→ corex_moe.py → ix_full_bridge.so → ixformer::infer
This module patches vllm at import time. Call apply() from patch_ops.sh.
@@ -24,6 +26,9 @@ Patches applied (matching xllm/core/kernels/ilu/ exactly):
4. vllm model RotaryEmbedding → xllm_ops.rotary_embedding
5. vllm attention reshape_and_cache → xllm_ops.reshape_and_cache
6. vllm attention paged_attention → xllm_ops.paged_attention
7. vllm linear layers (ALL) → ix_moe_bridge.linear (ixformer GEMV)
Upstream: ilu/matmul.cpp → gemv_conditions → ixformer_linear_ex
Savings: 12.2ms/token (17.3ms → 5.1ms for all linear ops)
NO FALLBACK. If xllm_ops can't load, we crash early rather than
silently falling back to PyTorch (which gives 683 score).
@@ -187,6 +192,58 @@ def apply(strict=True):
if strict:
raise
# =====================================================================
# 7. Patch Linear (THE biggest savings: 12.2ms per decode step)
# =====================================================================
# Upstream xllm/core/kernels/ilu/matmul.cpp:
# gemv_conditions(m<=1, k%32==0, n%2==0, no bias) → ixformer_linear_ex
# else → ixformer_linear
# Both map to ix_moe_bridge.so → bridge.linear(input, weight, bias)
#
# vllm calls F.linear(x, weight, bias) in UnquantizedLinearMethod.apply
# F.linear on BI-V100 = PyTorch generic GEMM = 115µs per (1,2048)×(N,2048)
# bridge.linear = ixformer optimized GEMV = 31µs (3.7x faster)
#
# Total savings: 17,306 → 5,146 µs across all linear ops = 12.2ms/token
if status.get("ix_moe_bridge", False):
try:
import torch.nn.functional as F
from vllm.model_executor.layers.linear import UnquantizedLinearMethod
_bridge = xllm_ops._get("ix_moe_bridge")
_orig_apply = UnquantizedLinearMethod.apply
def _patched_linear_apply(self, layer, x, bias=None):
"""Replace F.linear with ix_moe_bridge.linear (ixformer GEMV).
Matches upstream xllm/core/kernels/ilu/matmul.cpp:
gemv_conditions: m <= 1 && k % 32 == 0 && n % 2 == 0 && no bias
→ ixformer_linear_ex (the fast GEMV path)
"""
weight = layer.weight
m = x.view(-1, x.size(-1)).size(0)
k = x.size(-1)
n = weight.size(0)
# Match upstream gemv_conditions exactly
if (m <= 1
and k % 32 == 0
and n % 2 == 0
and bias is None):
return _bridge.linear(x, weight, None)
# For batched (prefill) or odd shapes, use bridge with bias
return _bridge.linear(x, weight, bias)
UnquantizedLinearMethod.apply = _patched_linear_apply
patches_applied += 1
logger.info("patch_hot_path: ✓ UnquantizedLinearMethod.apply → ix_moe_bridge.linear")
except Exception as e:
logger.error("patch_hot_path: ✗ linear patch failed: %s", e)
if strict:
raise
# =====================================================================
# Summary
# =====================================================================