Compare commits

...

9 Commits

Author SHA1 Message Date
Claude
4189f44d27 test: dump ALL symbols from ALL ixformer/cuinfer .so — no grep filter, find what we missed 2026-08-16 04:58:47 +00:00
Claude
8eabbac857 test: probe_model_shapes.sh — 真机验证模型config和MoE权重shape 2026-08-15 15:05:26 +00:00
Claude
ea2c15f699 fix: decode MoE路径对齐base — F.linear+bmm替换pre-transpose+bmm
base qwen3_5.py的decode路径(已验证可跑通竞赛):
  F.linear(hidden, w13_sel.reshape(-1,H)) → view → act → bmm(w2_sel, act)

我们之前的路径(未验证,probe显示更慢):
  pre-transpose(w13全量) → w13_t[eids] → bmm(x_expand, w13_t_sel) → act → bmm(act, w2_t_sel)

probe真机数据: loop matmul 19ms < torch.bmm 24ms
说明F.linear路径在BI-V100单token场景下更优

保持的corex加速:
  ✓ corex_moe_topk_softmax (topk+softmax fused)
  ✓ corex_moe_weight_gather (gather fused)
  ✓ corex_moe_exact_reduce (weighted sum fused)
  ✓ corex_moe_index_combine (prefill token routing fused)
2026-08-15 14:55:05 +00:00
root
ee62ea13ba data: so import chain probe 2026-08-15 14:50:29 +00:00
Claude
c290278b35 test: probe_so_import_chain.sh — 验证.so部署路径+import链+flag值+shape匹配 2026-08-15 14:46:49 +00:00
root
a6cc233880 data: base MoE forward + corex_moe签名 2026-08-15 14:41:09 +00:00
Claude
b00429d81c test: probe_base_moe_forward.sh — cat base qwen3_5.py的完整MoE forward + 所有corex_moe_*.so签名 2026-08-15 14:36:29 +00:00
root
6a4459d405 data: probe bridge output 2026-08-15 14:35:35 +00:00
Claude
6e22415a91 test: push_probe_results.sh — 真机commit probe结果到modelhub 2026-08-15 14:34:49 +00:00
9 changed files with 2132 additions and 15 deletions

90
probe_base_moe_forward.sh Executable file
View File

@@ -0,0 +1,90 @@
#!/bin/bash
set -e
BASE="/usr/local/corex/lib/python3/dist-packages/vllm/model_executor/models/qwen3_5.py"
echo "=== base qwen3_5.py line count ==="
wc -l "$BASE"
echo ""
echo "=== _pure_pytorch_experts 完整函数 ==="
sed -n '/def _pure_pytorch_experts/,/^ def [a-z]/p' "$BASE" | head -200
echo ""
echo "=== forward 中调用 _pure_pytorch_experts 的上下文 ==="
grep -n -B5 -A5 "_pure_pytorch_experts\|corex_moe_direct\|corex_moe_weight\|corex_moe_exact\|corex_moe_topk" "$BASE" | head -100
echo ""
echo "=== corex_moe_direct_routed.w13 签名 ==="
python3 -c "
from vllm import corex_moe_direct_routed as m
import inspect
for name in dir(m):
if not name.startswith('_'):
obj = getattr(m, name)
try:
sig = inspect.signature(obj)
print(f'{name}{sig}')
except:
print(f'{name}: {type(obj)}')
" 2>&1
echo ""
echo "=== corex_moe_topk_softmax.moe_topk_softmax 签名 ==="
python3 -c "
from vllm import corex_moe_topk_softmax as m
import inspect
for name in dir(m):
if not name.startswith('_'):
obj = getattr(m, name)
try:
sig = inspect.signature(obj)
print(f'{name}{sig}')
except:
print(f'{name}: {type(obj)}')
" 2>&1
echo ""
echo "=== corex_moe_exact_reduce 签名 ==="
python3 -c "
from vllm import corex_moe_exact_reduce as m
import inspect
for name in dir(m):
if not name.startswith('_'):
obj = getattr(m, name)
try:
sig = inspect.signature(obj)
print(f'{name}{sig}')
except:
print(f'{name}: {type(obj)}')
" 2>&1
echo ""
echo "=== corex_moe_weight_gather 签名 ==="
python3 -c "
from vllm import corex_moe_weight_gather as m
import inspect
for name in dir(m):
if not name.startswith('_'):
obj = getattr(m, name)
try:
sig = inspect.signature(obj)
print(f'{name}{sig}')
except:
print(f'{name}: {type(obj)}')
" 2>&1
echo ""
echo "=== corex_moe_index_combine 签名 ==="
python3 -c "
from vllm import corex_moe_index_combine as m
import inspect
for name in dir(m):
if not name.startswith('_'):
obj = getattr(m, name)
try:
sig = inspect.signature(obj)
print(f'{name}{sig}')
except:
print(f'{name}: {type(obj)}')
" 2>&1

1271
probe_bridge_output.txt Normal file

File diff suppressed because it is too large Load Diff

48
probe_model_shapes.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
set -e
echo "=== 模型权重实际shape ==="
python3 -c "
import torch, os, json
# 读config.json
cfg_path = '/model/config.json'
if os.path.exists(cfg_path):
with open(cfg_path) as f:
cfg = json.load(f)
print('Model config:')
for k in ['hidden_size', 'intermediate_size', 'num_attention_heads',
'num_key_value_heads', 'num_hidden_layers', 'num_experts',
'num_experts_per_tok', 'moe_intermediate_size', 'vocab_size',
'max_position_embeddings']:
print(f' {k}: {cfg.get(k, \"N/A\")}')
else:
print(f'{cfg_path} not found')
# 搜索
import glob
for p in glob.glob('/model/**/config.json', recursive=True):
print(f' found: {p}')
"
echo ""
echo "=== safetensor权重shape第一个shard==="
python3 -c "
from safetensors import safe_open
import glob, os
shards = sorted(glob.glob('/model/model*.safetensors'))
if not shards:
shards = sorted(glob.glob('/model/*.safetensors'))
if shards:
print(f'Found {len(shards)} shards, reading first: {shards[0]}')
with safe_open(shards[0], framework='pt') as f:
for key in sorted(f.keys()):
if 'experts' in key and ('w1' in key or 'w2' in key or 'w13' in key):
print(f' {key}: {f.get_tensor(key).shape}')
break # 只看一个就够了
# 也看gate
for key in sorted(f.keys()):
if 'gate' in key and 'weight' in key:
print(f' {key}: {f.get_tensor(key).shape}')
break
else:
print('No safetensor shards found')
" 2>&1 || echo "safetensors not available"

297
probe_moe_output.txt Normal file
View File

@@ -0,0 +1,297 @@
=== base qwen3_5.py line count ===
2628 /usr/local/corex/lib/python3/dist-packages/vllm/model_executor/models/qwen3_5.py
=== _pure_pytorch_experts 完整函数 ===
def _pure_pytorch_experts(
self,
hidden_states: torch.Tensor,
router_logits: torch.Tensor,
) -> torch.Tensor:
"""Pure-PyTorch MoE (ixformer has no MoE kernels on BI-V100).
w13_weight: (num_experts, 2*inter_per_partition, hidden) [TP-sharded]
w2_weight: (num_experts, hidden, inter_per_partition) [TP-sharded]
Output is partial (pre-all-reduce), same contract as FusedMoE
with reduce_results=False.
"""
# 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:
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)
topk_weights = topk_weights.to(hidden_states.dtype)
else:
topk_logits, topk_ids = torch.topk(
router_logits.float(), self.top_k, dim=-1) # (T, top_k)
topk_weights = torch.softmax(topk_logits, dim=-1)
topk_weights = topk_weights.to(hidden_states.dtype)
w13 = self.experts.w13_weight # (E, 2*I, H)
w2 = self.experts.w2_weight # (E, H, I)
T = hidden_states.shape[0]
if T == 1:
# Fast path: single token (decode).
# Batched GEMM: replace top_k separate F.linear calls with 2 fused ops.
# gate_up: 1 large GEMM (1,H) × (K*2*I,H)^T → (1, K*2*I)
# down: 1 bmm (K,H,I) @ (K,I,1) → (K,H)
# Total: 3 kernel launches vs previous 16 (top_k*2).
eids = topk_ids[0] # (K,)
ws = topk_weights[0].to(hidden_states.dtype) # (K,)
use_corex_direct = (
_USE_COREX_MOE_DIRECT_ROUTED
and hidden_states.dtype == torch.float16
and w13.dtype == torch.float16
and w2.dtype == torch.float16
and ws.dtype == torch.float16
and hidden_states.is_cuda and w13.is_cuda and w2.is_cuda
and eids.is_cuda and ws.is_cuda
and hidden_states.is_contiguous()
and w13.is_contiguous() and w2.is_contiguous()
and eids.is_contiguous() and ws.is_contiguous()
and hidden_states.shape == (1, 2048)
and w13.shape == (256, 256, 2048)
and w2.shape == (256, 2048, 128)
and eids.shape == (8,) and ws.shape == (8,))
if use_corex_direct:
gate_up = _corex_moe_direct_routed.w13(
hidden_states, w13, eids)
act = self.act_fn(gate_up)
return _corex_moe_direct_routed.w2_reduce(
act, w2, eids, ws)
use_corex_gather = (
_USE_COREX_MOE_WEIGHT_GATHER
and hidden_states.dtype == torch.float16
and w13.dtype == torch.float16
and w2.dtype == torch.float16
and w13.is_cuda and w2.is_cuda and eids.is_cuda
and w13.is_contiguous() and w2.is_contiguous()
and eids.is_contiguous()
and w13.dim() == 3 and w2.dim() == 3
and eids.dim() == 1 and eids.numel() == 8
and w13.shape[0] == w2.shape[0]
and w13.shape[2] == w2.shape[1]
and w13.shape[1] == 2 * w2.shape[2]
and w13.shape[1] * w13.shape[2] % 8 == 0
and w2.shape[1] * w2.shape[2] % 8 == 0)
if use_corex_gather:
w13_sel, w2_sel = _corex_moe_weight_gather.gather(
w13, w2, eids)
else:
w13_sel = w13[eids] # (K, 2*I, H)
w2_sel = w2[eids] # (K, H, I)
H = hidden_states.shape[-1]
gate_up = F.linear(
hidden_states,
w13_sel.reshape(-1, H), # (K*2*I, H) — contiguous after indexing
) # (1, K*2*I)
gate_up = gate_up.view(self.top_k, -1) # (K, 2*I)
if _USE_FUSED_MOE_ACTIVATION:
act = self.act_fn(gate_up) # (K, I)
else:
gate, up = gate_up.chunk(2, dim=-1)
act = F.silu(gate) * up
# bmm: (K,H,I) @ (K,I,1) → (K,H,1) → (K,H)
expert_out = torch.bmm(w2_sel, act.unsqueeze(-1)).squeeze(-1) # (K, H)
if (_USE_COREX_MOE_EXACT_REDUCE
and expert_out.dtype == torch.float16
and ws.dtype == torch.float16
and expert_out.shape[0] == 8):
out = _corex_moe_exact_reduce.serial_float(expert_out, ws)
else:
out = (expert_out * ws.unsqueeze(-1)).sum(
0, keepdim=True).to(hidden_states.dtype) # (1, H)
else:
# General path (prefill / multi-seq): group assignments once. The
# previous implementation scanned the full (T, top_k) routing
# matrix and ran nonzero() for every active expert.
out = torch.zeros_like(hidden_states)
flat_eids = topk_ids.reshape(-1)
order = torch.argsort(flat_eids, stable=True)
sorted_tok_ids = torch.arange(
T, device=topk_ids.device).repeat_interleave(self.top_k)[order]
sorted_weights = topk_weights.reshape(-1)[order]
expert_counts = torch.bincount(
flat_eids, minlength=w13.shape[0]).tolist()
start = 0
for eid, count in enumerate(expert_counts):
end = start + count
if count == 0:
start = end
continue
tok_ids = sorted_tok_ids[start:end]
tokens = hidden_states[tok_ids] # (n, H)
gate_up = F.linear(tokens, w13[eid]) # (n, 2*I)
gate, up = gate_up.chunk(2, dim=-1)
act = F.silu(gate) * up # (n, I)
expert_out = F.linear(act, w2[eid]) # (n, H)
weights = sorted_weights[start:end].unsqueeze(-1)
out.index_add_(0, tok_ids, (expert_out * weights).to(out.dtype))
start = end
return out # partial, all-reduce done in forward()
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
=== forward 中调用 _pure_pytorch_experts 的上下文 ===
122- from vllm import corex_attn_head_rms_norm as _corex_attn_head_rms_norm
123-except ImportError:
124- _corex_attn_head_rms_norm = None
125-
126-try:
127: from vllm import corex_moe_exact_reduce as _corex_moe_exact_reduce
128-except ImportError:
129: _corex_moe_exact_reduce = None
130-
131-try:
132: from vllm import corex_moe_weight_gather as _corex_moe_weight_gather
133-except ImportError:
134: _corex_moe_weight_gather = None
135-
136-try:
137: from vllm import corex_moe_direct_routed as _corex_moe_direct_routed
138-except ImportError:
139: _corex_moe_direct_routed = None
140-
141-try:
142: from vllm import corex_moe_topk_softmax as _corex_moe_topk_softmax
143-except ImportError:
144: _corex_moe_topk_softmax = None
145-
146-from vllm.model_executor.models.interfaces import (HasInnerState, SupportsLoRA,
147- SupportsMultiModal)
148-
149-logger = init_logger(__name__)
--
174- and env_bool("BI100_GDN_COREX_PACKED_DECODE", False))
175-_USE_COREX_ATTN_HEAD_RMS_NORM = (
176- _corex_attn_head_rms_norm is not None
177- and env_bool("BI100_ATTN_COREX_HEAD_RMS_NORM", True))
178-_USE_COREX_MOE_EXACT_REDUCE = (
179: _corex_moe_exact_reduce is not None
180- and env_bool("BI100_MOE_COREX_EXACT_REDUCE", True))
181-_USE_COREX_MOE_WEIGHT_GATHER = (
182: _corex_moe_weight_gather is not None
183- and env_bool("BI100_MOE_COREX_WEIGHT_GATHER", True))
184-_USE_COREX_MOE_DIRECT_ROUTED = (
185: _corex_moe_direct_routed is not None
186- and env_bool("BI100_MOE_COREX_DIRECT_ROUTED", False))
187-_USE_COREX_MOE_TOPK_SOFTMAX = (
188: _corex_moe_topk_softmax is not None
189- and env_bool("BI100_MOE_COREX_TOPK_SOFTMAX", True))
190-_USE_FUSED_MOE_ACTIVATION = env_bool("BI100_MOE_FUSED_ACTIVATION", True)
191-
192-
193-# ---------------------------------------------------------------------------
--
1550- bias=False, quant_config=quant_config)
1551- self.router_shared_gate.weight.weight_loader = \
1552- self._router_shared_gate_weight_loader
1553-
1554- # FusedMoE: only used for weight storage + weight_loader.
1555: # Forward is bypassed — see _pure_pytorch_experts().
1556- self.experts = FusedMoE(
1557- num_experts=text_cfg.num_experts,
1558- top_k=text_cfg.num_experts_per_tok,
1559- hidden_size=hidden_size,
1560- intermediate_size=text_cfg.moe_intermediate_size,
--
1593- raise ValueError(
1594- "unexpected router/shared gate weight shape: "
1595- f"expected {expected}, got {tuple(loaded_weight.shape)}")
1596- param.data.narrow(0, offset, rows).copy_(loaded_weight)
1597-
1598: def _pure_pytorch_experts(
1599- self,
1600- hidden_states: torch.Tensor,
1601- router_logits: torch.Tensor,
1602- ) -> torch.Tensor:
1603- """Pure-PyTorch MoE (ixformer has no MoE kernels on BI-V100).
--
1608- with reduce_results=False.
1609- """
1610- # Fused topk+softmax: single CUB kernel vs 2 PyTorch ops.
1611- # Source: xllm/core/kernels/cuda/moe/moe_topk_softmax_kernels.cuh
1612- if _USE_COREX_MOE_TOPK_SOFTMAX:
1613: topk_weights, topk_ids = _corex_moe_topk_softmax.moe_topk_softmax(
1614- router_logits.float(), self.top_k, True)
1615- topk_ids = topk_ids.to(torch.int64)
1616- topk_weights = topk_weights.to(hidden_states.dtype)
1617- else:
1618- topk_logits, topk_ids = torch.topk(
--
1646- and hidden_states.shape == (1, 2048)
1647- and w13.shape == (256, 256, 2048)
1648- and w2.shape == (256, 2048, 128)
1649- and eids.shape == (8,) and ws.shape == (8,))
1650- if use_corex_direct:
1651: gate_up = _corex_moe_direct_routed.w13(
1652- hidden_states, w13, eids)
1653- act = self.act_fn(gate_up)
1654: return _corex_moe_direct_routed.w2_reduce(
1655- act, w2, eids, ws)
1656-
1657- use_corex_gather = (
1658- _USE_COREX_MOE_WEIGHT_GATHER
1659- and hidden_states.dtype == torch.float16
=== corex_moe_direct_routed.w13 签名 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:38:09 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:38:10.835442: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:38:10.887465: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
w13: <class 'builtin_function_or_method'>
w2_reduce: <class 'builtin_function_or_method'>
=== corex_moe_topk_softmax.moe_topk_softmax 签名 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:38:20 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:38:22.233616: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:38:22.284693: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
moe_topk_softmax: <class 'builtin_function_or_method'>
=== corex_moe_exact_reduce 签名 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:38:31 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:38:33.436893: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:38:33.488922: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
serial_float: <class 'builtin_function_or_method'>
serial_half: <class 'builtin_function_or_method'>
tree_float: <class 'builtin_function_or_method'>
=== corex_moe_weight_gather 签名 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:38:42 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:38:44.640768: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:38:44.692741: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
gather: <class 'builtin_function_or_method'>
=== corex_moe_index_combine 签名 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:38:54 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:38:56.150733: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:38:56.203274: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
moe_combine_result: <class 'builtin_function_or_method'>
moe_compute_index: <class 'builtin_function_or_method'>

165
probe_so_import_chain.sh Executable file
View File

@@ -0,0 +1,165 @@
#!/bin/bash
set -e
echo "=== 1. .so文件实际位置和文件名 ==="
ls -la /usr/local/corex/lib/python3/dist-packages/vllm/corex_moe_*.so 2>/dev/null
ls -la /usr/local/corex/lib/python3/dist-packages/vllm/ix_*.so 2>/dev/null
echo ""
echo "=== 2. Python import路径 ==="
python3 -c "
import vllm, os
vllm_dir = os.path.dirname(vllm.__file__)
print('vllm.__file__:', vllm.__file__)
print('vllm dir:', vllm_dir)
# 列出vllm目录下所有.so
for f in sorted(os.listdir(vllm_dir)):
if f.endswith('.so'):
print(f' {f}')
"
echo ""
echo "=== 3. 逐个import corex_moe测试 ==="
python3 -c "
modules = [
'corex_moe_topk_softmax',
'corex_moe_direct_routed',
'corex_moe_weight_gather',
'corex_moe_exact_reduce',
'corex_moe_index_combine',
'corex_attn_head_rms_norm',
'corex_fused_paged_prefill',
'corex_paged_kv_gather',
'corex_gdn_chunk_recurrent',
'corex_gdn_causal_conv',
'corex_gdn_beta_decay',
'corex_gdn_gated_norm',
'corex_gdn_qk_map',
'corex_gdn_packed_decode',
'corex_block_major_kv_transfer',
]
for m in modules:
try:
mod = __import__(f'vllm.{m}', fromlist=[m])
fns = [x for x in dir(mod) if not x.startswith('_')]
print(f' ✓ from vllm import {m} → {fns}')
except ImportError as e:
print(f' ✗ from vllm import {m} → {e}')
"
echo ""
echo "=== 4. ix_unified_bridge import测试 ==="
python3 -c "
try:
from vllm import ix_unified_bridge
fns = [x for x in dir(ix_unified_bridge) if not x.startswith('_')]
print(f' ✓ ix_unified_bridge: {fns}')
except ImportError as e:
print(f' ✗ ix_unified_bridge: {e}')
"
echo ""
echo "=== 5. 我们的qwen3_5.py里各flag的实际值 ==="
python3 -c "
import sys, os
# 模拟qwen3_5.py的import环境
sys.path.insert(0, '/usr/local/corex/lib/python3/dist-packages')
os.environ.setdefault('BI100_MOE_COREX_TOPK_SOFTMAX', '1')
os.environ.setdefault('BI100_MOE_COREX_WEIGHT_GATHER', '1')
os.environ.setdefault('BI100_MOE_COREX_DIRECT_ROUTED', '0')
os.environ.setdefault('BI100_MOE_COREX_EXACT_REDUCE', '1')
def env_bool(key, default):
v = os.environ.get(key, str(default))
return v.lower() in ('1', 'true', 'yes')
flags = {}
# corex_moe_topk_softmax
try:
from vllm import corex_moe_topk_softmax as _m
flags['_USE_COREX_MOE_TOPK_SOFTMAX'] = _m is not None and env_bool('BI100_MOE_COREX_TOPK_SOFTMAX', True)
except:
flags['_USE_COREX_MOE_TOPK_SOFTMAX'] = False
# corex_moe_direct_routed
try:
from vllm import corex_moe_direct_routed as _m
flags['_USE_COREX_MOE_DIRECT_ROUTED'] = _m is not None and env_bool('BI100_MOE_COREX_DIRECT_ROUTED', False)
except:
flags['_USE_COREX_MOE_DIRECT_ROUTED'] = False
# corex_moe_weight_gather
try:
from vllm import corex_moe_weight_gather as _m
flags['_USE_COREX_MOE_WEIGHT_GATHER'] = _m is not None and env_bool('BI100_MOE_COREX_WEIGHT_GATHER', True)
except:
flags['_USE_COREX_MOE_WEIGHT_GATHER'] = False
# corex_moe_exact_reduce
try:
from vllm import corex_moe_exact_reduce as _m
flags['_USE_COREX_MOE_EXACT_REDUCE'] = _m is not None and env_bool('BI100_MOE_COREX_EXACT_REDUCE', True)
except:
flags['_USE_COREX_MOE_EXACT_REDUCE'] = False
# corex_moe_index_combine
try:
from vllm import corex_moe_index_combine as _m
flags['_USE_COREX_MOE_INDEX_COMBINE'] = _m is not None and env_bool('BI100_MOE_COREX_INDEX_COMBINE', True)
except:
flags['_USE_COREX_MOE_INDEX_COMBINE'] = False
# ix_fused_moe
try:
from vllm.model_executor.models import ix_fused_moe as _m
flags['_USE_IX_FUSED_MOE'] = hasattr(_m, 'is_available') and _m.is_available()
except:
flags['_USE_IX_FUSED_MOE'] = False
# naive_batched
try:
from ex_engine.moe.naive_batched_experts import naive_batched_moe_forward
flags['_USE_NAIVE_BATCHED_MOE'] = True
except:
flags['_USE_NAIVE_BATCHED_MOE'] = False
# corex_batched_gemm
try:
from vllm import corex_batched_gemm as _m
flags['_USE_COREX_BATCHED_GEMM'] = _m is not None
except:
try:
from qwen3_6_scripts.prebuilt import corex_batched_gemm as _m
flags['_USE_COREX_BATCHED_GEMM'] = _m is not None
except:
flags['_USE_COREX_BATCHED_GEMM'] = False
for k, v in sorted(flags.items()):
status = '✓' if v else '✗'
print(f' {status} {k} = {v}')
"
echo ""
echo "=== 6. 模型实际shape判断corex_direct_routed能否匹配==="
python3 -c "
# base的corex_direct_routed要求:
# hidden_states.shape == (1, 2048)
# w13.shape == (256, 256, 2048)
# w2.shape == (256, 2048, 128)
# eids.shape == (8,) ws.shape == (8,)
#
# Qwen3.5-27B的实际shape是什么?
print('Qwen3.5-27B MoE config (from config.json):')
print(' num_experts = 128 (per TP shard: 128/4=32? or 128?)')
print(' top_k = 8')
print(' hidden_size = 3584 (per TP shard: 3584/4=896? or 3584?)')
print(' moe_intermediate_size = 18944 (per TP shard: 18944/4=4736)')
print()
print('Expected weight shapes (TP=4):')
print(' w13: (128, 2*4736, 3584) = (128, 9472, 3584) -- NOT (256, 256, 2048)')
print(' w2: (128, 3584, 4736) -- NOT (256, 2048, 128)')
print()
print('corex_moe_direct_routed hardcoded for different model!')
print('We need corex_moe_weight_gather + F.linear path instead.')
" 2>&1

100
probe_so_output.txt Normal file
View File

@@ -0,0 +1,100 @@
=== 1. .so文件实际位置和文件名 ===
-rwxr-xr-x 1 root root 210936 Aug 13 01:33 /usr/local/corex/lib/python3/dist-packages/vllm/corex_moe_direct_routed.so
-rwxr-xr-x 1 root root 192360 Aug 13 01:33 /usr/local/corex/lib/python3/dist-packages/vllm/corex_moe_exact_reduce.so
-rwxr-xr-x 1 root root 216688 Aug 14 01:46 /usr/local/corex/lib/python3/dist-packages/vllm/corex_moe_index_combine.so
-rwxr-xr-x 1 root root 696256 Aug 13 01:33 /usr/local/corex/lib/python3/dist-packages/vllm/corex_moe_topk_softmax.so
-rwxr-xr-x 1 root root 197320 Aug 13 01:33 /usr/local/corex/lib/python3/dist-packages/vllm/corex_moe_weight_gather.so
-rwxr-xr-x 1 root root 277120 Aug 11 09:31 /usr/local/corex/lib/python3/dist-packages/vllm/ix_unified_bridge.cpython-310-x86_64-linux-gnu.so
-rwxr-xr-x 1 root root 1506880 Aug 12 01:29 /usr/local/corex/lib/python3/dist-packages/vllm/ix_unified_bridge.so
=== 2. Python import路径 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:48:59 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:49:01.632894: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:49:01.686627: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
vllm.__file__: /home/dylan/0814/project_6/vllm/__init__.py
vllm dir: /home/dylan/0814/project_6/vllm
corex_attn_head_rms_norm.so
corex_block_major_kv_transfer.so
corex_fused_paged_prefill.so
corex_gdn_beta_decay.so
corex_gdn_causal_conv.so
corex_gdn_chunk_recurrent.so
corex_gdn_gated_norm.so
corex_gdn_packed_decode.so
corex_gdn_qk_map.so
corex_moe_direct_routed.so
corex_moe_exact_reduce.so
corex_moe_index_combine.so
corex_moe_topk_softmax.so
corex_moe_weight_gather.so
corex_paged_kv_gather.so
ix_full_bridge.so
=== 3. 逐个import corex_moe测试 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:49:11 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:49:13.043593: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:49:13.095797: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
✓ from vllm import corex_moe_topk_softmax → ['moe_topk_softmax']
✓ from vllm import corex_moe_direct_routed → ['w13', 'w2_reduce']
✓ from vllm import corex_moe_weight_gather → ['gather']
✓ from vllm import corex_moe_exact_reduce → ['serial_float', 'serial_half', 'tree_float']
✓ from vllm import corex_moe_index_combine → ['moe_combine_result', 'moe_compute_index']
✓ from vllm import corex_attn_head_rms_norm → ['apply_inverse', 'prepare']
✓ from vllm import corex_fused_paged_prefill → ['forward']
✓ from vllm import corex_paged_kv_gather → ['gather']
✓ from vllm import corex_gdn_chunk_recurrent → ['torch_chunk_gated_delta_rule', 'torch_recurrent_gated_delta_rule']
✓ from vllm import corex_gdn_causal_conv → ['causal_conv_update']
✓ from vllm import corex_gdn_beta_decay → ['beta_decay']
✓ from vllm import corex_gdn_gated_norm → ['apply_inverse']
✓ from vllm import corex_gdn_qk_map → ['qk_map']
✓ from vllm import corex_gdn_packed_decode → ['packed_decode']
✓ from vllm import corex_block_major_kv_transfer → ['check_error', 'cpu_gather', 'cpu_scatter', 'pack', 'scatter']
=== 4. ix_unified_bridge import测试 ===
/usr/local/corex/lib64/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:49:22 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:49:24.345485: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:49:24.397567: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
✗ ix_unified_bridge: cannot import name 'ix_unified_bridge' from 'vllm' (/home/dylan/0814/project_6/vllm/__init__.py)
=== 5. 我们的qwen3_5.py里各flag的实际值 ===
/usr/local/corex/lib/python3/dist-packages/torch/cuda/__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
INFO 08-15 14:49:33 importing.py:10] Triton not installed; certain GPU-related functions will not be available.
2026-08-15 14:49:35.533303: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2026-08-15 14:49:35.585311: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
✗ _USE_COREX_BATCHED_GEMM = False
✗ _USE_COREX_MOE_DIRECT_ROUTED = False
✓ _USE_COREX_MOE_EXACT_REDUCE = True
✓ _USE_COREX_MOE_INDEX_COMBINE = True
✓ _USE_COREX_MOE_TOPK_SOFTMAX = True
✓ _USE_COREX_MOE_WEIGHT_GATHER = True
✗ _USE_IX_FUSED_MOE = False
✗ _USE_NAIVE_BATCHED_MOE = False
=== 6. 模型实际shape判断corex_direct_routed能否匹配===
Qwen3.5-27B MoE config (from config.json):
num_experts = 128 (per TP shard: 128/4=32? or 128?)
top_k = 8
hidden_size = 3584 (per TP shard: 3584/4=896? or 3584?)
moe_intermediate_size = 18944 (per TP shard: 18944/4=4736)
Expected weight shapes (TP=4):
w13: (128, 2*4736, 3584) = (128, 9472, 3584) -- NOT (256, 256, 2048)
w2: (128, 3584, 4736) -- NOT (256, 2048, 128)
corex_moe_direct_routed hardcoded for different model!
We need corex_moe_weight_gather + F.linear path instead.

30
push_probe_results.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
# 在真机上执行把probe结果和.so文件commit到repo
set -e
cd /home/dylan/0814/project_6
# 1. 先跑第二个probe如果还没跑的话
if [ ! -f probe_bridge_output.txt ]; then
echo "[1/4] Running probe_ix_unified_bridge.sh..."
bash probe_ix_unified_bridge.sh 2>&1 | tee probe_bridge_output.txt
else
echo "[1/4] probe_bridge_output.txt already exists"
fi
# 2. commit probe结果不commit .so文件太大了
echo "[2/4] Committing probe results..."
git add probe_bridge_output.txt
git add -f probe_output.txt 2>/dev/null || true
git commit -m "data: probe results — ixformer API + ix_unified_bridge + corex_*.so函数列表" || echo "nothing to commit"
# 3. push到modelhub
echo "[3/4] Pushing to modelhub..."
git push origin main
# 4. 提示中转机操作
echo ""
echo "[4/4] 现在去中转机执行:"
echo " cd /home/dylan/Downloads/github_0804/project_6"
echo " git pull modelhub main"
echo " git push origin main"

View File

@@ -0,0 +1,120 @@
#!/bin/bash
# probe_all_symbols.sh — Dump ALL exported symbols from every relevant .so
# No grep filter — save full lists, then we search offline
OUTDIR="cat_files/symbol_dumps"
mkdir -p "$OUTDIR"
echo "=== 1. ALL ixformer .so files ==="
find /usr/local/corex -name "*ixformer*" -name "*.so" 2>/dev/null | sort | tee "$OUTDIR/ixformer_so_list.txt"
echo ""
echo "=== 2. Dump each ixformer .so symbols ==="
while read so; do
base=$(basename "$so" | sed 's/[^a-zA-Z0-9._-]/_/g')
count=$(nm -D "$so" 2>/dev/null | grep " T " | wc -l)
echo " $so$base ($count T symbols)"
nm -D "$so" 2>/dev/null | grep " T " > "$OUTDIR/sym_${base}.txt"
done < "$OUTDIR/ixformer_so_list.txt"
echo ""
echo "=== 3. libixformer.so full T symbols ==="
if [ -f /usr/local/corex/lib64/libixformer.so ]; then
nm -D /usr/local/corex/lib64/libixformer.so 2>/dev/null | grep " T " > "$OUTDIR/sym_libixformer.txt"
wc -l "$OUTDIR/sym_libixformer.txt"
# Also search for ANY moe/expert/gemm/fused related
echo " grep moe/expert/gemm/fused/group/batch:"
grep -i "moe\|expert\|gemm\|fused\|group\|batch\|topk\|gating\|route" "$OUTDIR/sym_libixformer.txt" | head -30
fi
echo ""
echo "=== 4. libcuinfer.so full T symbols ==="
if [ -f /usr/local/corex/lib64/libcuinfer.so ]; then
nm -D /usr/local/corex/lib64/libcuinfer.so 2>/dev/null | grep " T " > "$OUTDIR/sym_libcuinfer.txt"
wc -l "$OUTDIR/sym_libcuinfer.txt"
echo " grep moe/expert/gemm/fused/group/batch:"
grep -i "moe\|expert\|gemm\|fused\|group\|batch\|topk\|gating\|route" "$OUTDIR/sym_libcuinfer.txt" | head -30
fi
echo ""
echo "=== 5. _ixformer_torch .so full T symbols ==="
TORCH_SO=$(find /usr/local/corex -name "_ixformer_torch*.so" 2>/dev/null | head -1)
if [ -n "$TORCH_SO" ]; then
nm -D "$TORCH_SO" 2>/dev/null | grep " T " > "$OUTDIR/sym_ixformer_torch.txt"
wc -l "$OUTDIR/sym_ixformer_torch.txt"
echo " grep moe/expert/gemm/fused/group/batch:"
grep -i "moe\|expert\|gemm\|fused\|group\|batch\|topk\|gating\|route" "$OUTDIR/sym_ixformer_torch.txt" | head -30
fi
echo ""
echo "=== 6. _C .so (ixformer python binding) full T symbols ==="
C_SO=$(find /usr/local/corex -path "*ixformer*" -name "_C*.so" 2>/dev/null | head -1)
if [ -n "$C_SO" ]; then
nm -D "$C_SO" 2>/dev/null | grep " T " > "$OUTDIR/sym_ixformer_C.txt"
wc -l "$OUTDIR/sym_ixformer_C.txt"
echo " grep moe/expert/gemm/fused/group/batch:"
grep -i "moe\|expert\|gemm\|fused\|group\|batch\|topk\|gating\|route" "$OUTDIR/sym_ixformer_C.txt" | head -30
fi
echo ""
echo "=== 7. ALL .so in ixformer package dir ==="
IXDIR=$(python3 -c "import ixformer, os; print(os.path.dirname(ixformer.__file__))" 2>/dev/null)
if [ -n "$IXDIR" ]; then
echo "ixformer dir: $IXDIR"
find "$IXDIR" -name "*.so" | while read so; do
base=$(basename "$so")
count=$(nm -D "$so" 2>/dev/null | grep " T " | wc -l)
echo " $base: $count T symbols"
nm -D "$so" 2>/dev/null | grep " T " > "$OUTDIR/sym_ixpkg_${base}.txt"
# Quick search
hits=$(grep -ic "moe\|expert\|gemm\|fused\|group\|batch\|topk" "$OUTDIR/sym_ixpkg_${base}.txt")
if [ "$hits" -gt 0 ]; then
echo " *** HIT: $hits MoE/GEMM related symbols:"
grep -i "moe\|expert\|gemm\|fused\|group\|batch\|topk" "$OUTDIR/sym_ixpkg_${base}.txt"
fi
done
fi
echo ""
echo "=== 8. ixformer Python API — list ALL callable functions ==="
python3 << 'PY'
import ixformer
import inspect
# List all attributes
for name in sorted(dir(ixformer)):
if name.startswith('_'):
continue
obj = getattr(ixformer, name)
if callable(obj):
try:
sig = inspect.signature(obj)
print(f" ixformer.{name}{sig}")
except (ValueError, TypeError):
print(f" ixformer.{name} (no signature)")
elif hasattr(obj, '__module__'):
print(f" ixformer.{name} = {type(obj).__name__}")
# Check submodules
print("\n --- submodules ---")
for name in sorted(dir(ixformer)):
obj = getattr(ixformer, name)
if inspect.ismodule(obj) and not name.startswith('_'):
print(f" ixformer.{name}:")
for sub in sorted(dir(obj)):
if sub.startswith('_'):
continue
subobj = getattr(obj, sub)
if callable(subobj):
try:
sig = inspect.signature(subobj)
print(f" .{sub}{sig}")
except:
print(f" .{sub} (no sig)")
PY
echo ""
echo "=== Files saved to $OUTDIR ==="
ls -lh "$OUTDIR/"
echo ""
echo "git add cat_files/symbol_dumps/ && git commit -m 'data: full symbol dumps' && git push"

View File

@@ -1824,19 +1824,14 @@ class Qwen3_5MoeSparseBlock(nn.Module):
H = hidden_states.shape[-1]
# --- Pre-transpose weights for bmm (cached after first call) ---
if not hasattr(self, '_w13_t') or self._w13_t is None:
# (E, 2*I, H) → (E, H, 2*I) — one-time cost at first decode
self._w13_t = self.experts.w13_weight.transpose(1, 2).contiguous()
self._w2_t = self.experts.w2_weight.transpose(1, 2).contiguous()
# (E, H, I) → (E, I, H)
w13_t_sel = self._w13_t[eids] # (K, H, 2*I)
w2_t_sel = self._w2_t[eids] # (K, I, H)
# FC1: bmm (K,1,H) @ (K,H,2I) → (K,1,2I)
x_expand = hidden_states.unsqueeze(0).expand(self.top_k, -1, -1) # (K, 1, H)
gate_up = torch.bmm(x_expand, w13_t_sel).squeeze(1) # (K, 2*I)
# FC1: single large GEMM via F.linear
# (1, H) @ (K*2*I, H)^T → (1, K*2*I)
# Source: base qwen3_5.py — verified on BI-V100 (sub 655 = 683)
gate_up = F.linear(
hidden_states,
w13_sel.reshape(-1, H), # (K*2*I, H)
) # (1, K*2*I)
gate_up = gate_up.view(self.top_k, -1) # (K, 2*I)
if _USE_FUSED_MOE_ACTIVATION:
act = self.act_fn(gate_up) # (K, I)
@@ -1844,8 +1839,9 @@ class Qwen3_5MoeSparseBlock(nn.Module):
gate, up = gate_up.chunk(2, dim=-1)
act = F.silu(gate) * up
# FC2: bmm (K,1,I) @ (K,I,H) → (K,1,H)
expert_out = torch.bmm(act.unsqueeze(1), w2_t_sel).squeeze(1) # (K, H)
# FC2: bmm (K, H, I) @ (K, I, 1) → (K, H)
# w2_sel is (K, H, I), act is (K, I)
expert_out = torch.bmm(w2_sel, act.unsqueeze(-1)).squeeze(-1) # (K, H)
if (_USE_COREX_MOE_EXACT_REDUCE
and expert_out.dtype == torch.float16