Compare commits

...

2 Commits

Author SHA1 Message Date
claude
93353a1414 test: probe ixformer .so symbols for MoE grouped GEMM
CUTLASS grouped GEMM (example 24) requires SM80 Tensor Core + cuda/std headers.
Cannot compile on corex (same issue as CCCL 3.6 variadic functions).

Alternative path: ix_moe_bridge.so calls ixformer::infer::moe_w16a16_group_gemm
which is BI-V100 optimized grouped GEMM already in the base image.

This probe script checks if the MoE functions exist in ixformer .so
before attempting to build ix_moe_bridge.so.

Run: bash qwen3_6_scripts/probe_ixformer_symbols.sh
2026-08-14 11:40:13 +00:00
claude
865c18f852 feat: integrate xllm_moe into qwen3_5.py MoE hot path
xllm_moe.so provides 3 fused CUDA kernels compiled for ivcore10:
  - moe_fused_topk: CUB topk + softmax (replaces corex_moe_topk_softmax)
  - moe_compute_index: histogram + prefix_sum + place (replaces corex_moe_index_combine)
  - moe_combine_result: reorder + weighted sum (available but not yet wired to output)

Dispatch priority in _pure_pytorch_experts():
  Tier 0: xllm_moe (if available)
  Tier 1: corex_moe_* individual .so
  Tier 2: PyTorch fallback

Integration points:
  1. Topk routing: xllm_moe.moe_fused_topk → corex_moe_topk_softmax → torch.topk
  2. Index computation: xllm_moe.moe_compute_index → corex_moe_index_combine → torch.argsort
  3. Expert loop: still Python F.linear (next target: batch GEMM)

patch_ops.sh already deploys all prebuilt/*.so including xllm_moe.so
2026-08-14 11:37:21 +00:00
2 changed files with 87 additions and 2 deletions

View File

@@ -0,0 +1,58 @@
#!/bin/bash
# probe_ixformer_symbols.sh — Check what ixformer::infer functions are available
# Run: bash qwen3_6_scripts/probe_ixformer_symbols.sh
echo "=== Locate ixformer .so ==="
python3 -c "
import ixformer, os, glob
d = os.path.dirname(ixformer.__file__)
print(f'ixformer dir: {d}')
for f in glob.glob(os.path.join(d, '*.so')):
print(f' {os.path.basename(f)} ({os.path.getsize(f)} bytes)')
" 2>/dev/null
IXFORMER_SO=$(python3 -c "
import ixformer, os, glob
d = os.path.dirname(ixformer.__file__)
sos = glob.glob(os.path.join(d, '*ixformer*.so'))
print(sos[0] if sos else '')
" 2>/dev/null)
if [ -z "$IXFORMER_SO" ]; then
echo "ixformer .so not found"
exit 1
fi
echo ""
echo "=== MoE functions (grouped GEMM pipeline) ==="
nm -D "$IXFORMER_SO" 2>/dev/null | grep -i "moe_w16a16\|group_gemm\|moe_expand\|moe_compute_token\|moe_output_reduce\|topk_softmax" | head -20
echo ""
echo "=== Attention functions ==="
nm -D "$IXFORMER_SO" 2>/dev/null | grep -i "flash_attn_unpad\|paged_attention\|xllm_paged" | head -10
echo ""
echo "=== Linear functions ==="
nm -D "$IXFORMER_SO" 2>/dev/null | grep -i "ixformer_linear\|residual_rms_norm" | head -10
echo ""
echo "=== All ixformer::infer symbols ==="
nm -D "$IXFORMER_SO" 2>/dev/null | grep "ixformer.*infer\|ixinfer" | wc -l
echo "total symbols"
echo ""
echo "=== Also check _ixformer_torch .so ==="
find /usr/local/corex -name "*ixformer*torch*.so" 2>/dev/null | head -5
TORCH_SO=$(find /usr/local/corex -name "*ixformer*torch*.so" 2>/dev/null | head -1)
if [ -n "$TORCH_SO" ]; then
echo "MoE symbols in torch ext:"
nm -D "$TORCH_SO" 2>/dev/null | grep -i "moe_w16a16\|group_gemm\|topk_softmax\|moe_expand\|moe_compute" | head -20
fi
echo ""
echo "=== corex lib64 ixformer ==="
ls /usr/local/corex/lib64/libixformer* 2>/dev/null
if [ -f /usr/local/corex/lib64/libixformer.so ]; then
echo "MoE symbols in libixformer.so:"
nm -D /usr/local/corex/lib64/libixformer.so 2>/dev/null | grep -i "moe_w16a16\|group_gemm\|topk_softmax" | head -20
fi

View File

@@ -148,6 +148,14 @@ try:
except ImportError:
_corex_moe_index_combine = None
try:
from vllm import xllm_moe as _xllm_moe
except ImportError:
try:
import xllm_moe as _xllm_moe
except ImportError:
_xllm_moe = None
try:
from vllm import corex_gdn_chunk_recurrent as _corex_gdn_chunk_recurrent
except ImportError:
@@ -202,6 +210,11 @@ _USE_COREX_MOE_TOPK_SOFTMAX = (
_USE_COREX_MOE_INDEX_COMBINE = (
_corex_moe_index_combine is not None
and env_bool("BI100_MOE_COREX_INDEX_COMBINE", True))
_USE_XLLM_MOE = (
_xllm_moe is not None
and env_bool("BI100_MOE_XLLM", True))
if _USE_XLLM_MOE:
logger.info("xllm_moe ENABLED — fused_topk + compute_index + combine_result")
_USE_FUSED_MOE_ACTIVATION = env_bool("BI100_MOE_FUSED_ACTIVATION", True)
# ix_fused_moe: full 7-step fused MoE pipeline via ixformer C++ API
@@ -1666,7 +1679,12 @@ class Qwen3_5MoeSparseBlock(nn.Module):
# ---------------------------------------------------------------
# Fused topk+softmax: single CUB kernel vs 2 PyTorch ops.
# Source: xllm/core/kernels/cuda/moe/moe_topk_softmax_kernels.cuh
if _USE_COREX_MOE_TOPK_SOFTMAX:
if _USE_XLLM_MOE:
topk_weights, topk_ids = _xllm_moe.moe_fused_topk(
router_logits, self.top_k, True, None, "softmax")
topk_ids = topk_ids.to(torch.int64)
topk_weights = topk_weights.to(hidden_states.dtype)
elif _USE_COREX_MOE_TOPK_SOFTMAX:
topk_weights, topk_ids = _corex_moe_topk_softmax.moe_topk_softmax(
router_logits.float(), self.top_k, True)
topk_ids = topk_ids.to(torch.int64)
@@ -1762,7 +1780,16 @@ class Qwen3_5MoeSparseBlock(nn.Module):
out = torch.zeros_like(hidden_states)
flat_eids = topk_ids.reshape(-1)
if _USE_COREX_MOE_INDEX_COMBINE:
if _USE_XLLM_MOE:
# xllm CUDA: histogram + prefix_sum + place
src_dst, dst_src, expert_sizes = \
_xllm_moe.moe_compute_index(flat_eids, w13.shape[0])
sorted_tok_ids = torch.arange(
T, device=topk_ids.device
).repeat_interleave(self.top_k)[dst_src.long()]
sorted_weights = topk_weights.reshape(-1)[dst_src.long()]
expert_counts = expert_sizes.tolist()
elif _USE_COREX_MOE_INDEX_COMBINE:
# Fused CUDA: histogram + prefix_sum + place (11.5x faster)
src_dst, dst_src, expert_sizes = \
_corex_moe_index_combine.moe_compute_index(