Conversation
AbeFei
commented
Jun 12, 2026
- Add _dequant_paged_kv_block_kernel and rewrite the int8 dequant prefill to dequantize referenced KV blocks to bf16, then reuse the bf16 FA2 kernel; fall back to the scalar kernel for unsupported shapes. ~100x faster (1199ms -> 11.6ms).
- Pass original (Hkv, D) scales (drop repeat_interleave); cache bf16 dequant buffers.
- Make the GQA packed kernel's autotune-disabled config shared-mem-safe for large groups to fix OOR in CI; fix double-scaling in the non-packed partial-page loop.
- change "contrib" dir to "experimental" - move block diffusion attenton to experimental dir
* fix: refactor perf tests. * fix wrong import --------- Co-authored-by: zhangjihang <zhangjihang@bytedance.com>
- Change some core api for better target-independent - Modify patching for qwen3 for transformers - Update pyproject to use latest triton-x - Optimize triton version sdpa
…nference BDT layout (#96) * Add causal conv1d for inference BDT layout * Add perf test * Remove constructor
* feat: paged_store_kv support varlen. * fix: return value && perf.
…nhance the error message.
* add npu backend * add npu backend * add npu backend * add npu backend * add npu backend * add npu backend * add npu_gelu --------- Co-authored-by: mc-zhang <zhangbolun6@huawei.com>
feat(ttx/kernels/utils.py): add tensor device guard for triton kernels.
…ary_code chore(ttx/kernels/npu): remove unnecessary code.
* feat: optimize conv1d fwd&bwd. * fix: test shape.
feat(normalization): make normalization nn.Module like.
This reverts commit 94561d4.
* feat: refactor rope. * fix: test base. * fix: graph test.
add o as optional input in swa_paged_decode_impl
* feat: ixformer support 2d scale for static quant. * fix: ilu ttx.
* [ilu/ixformer] support moe using gdr * [ilu/ixformer] Use bfloat16 inv_smooth_scale in quant moe when input.dtype=torch.bfloat16. --------- Co-authored-by: xiaomei.wang <xiaomei.wang@iluvatar.com>
Co-authored-by: song.liu <song.liu@iluvatar.com>
* ci: add claude code automated PR review workflow Runs on NPU self-hosted runner for each PR, posts review comments via the internal Anthropic-compatible endpoint. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: pre-cleanup workspace before checkout for claude review NPU runner workspace can hold root-owned files left by prior container jobs; checkout fails with EACCES otherwise. Wipe via docker before checkout, matching the iluvatar workflow's approach. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: harden pre-cleanup step Run as root explicitly, use rm -rf with dotglob to catch hidden files, list dir at end to verify, and drop "|| true" so failures surface instead of being silently swallowed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: override npu image entrypoint in pre-cleanup The npu CI image's ENTRYPOINT runs sshd and swallows our `bash -c`, so the cleanup never executed. Use --entrypoint bash to bypass it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: provide GitHub auth for claude-code-action Add id-token: write permission and pass github_token explicitly so the action can authenticate to the GitHub API without going through the OIDC + GitHub App flow (which fails on this self-hosted runner). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: replace claude-code-action with custom review script The official action installs claude-code from claude.com which is geo-blocked from our network (proxy egress IP triggers region check). Self-roll a small Python step instead: compute the PR diff, POST it to the internal Anthropic-compatible endpoint, post the response as a PR issue comment via the GitHub API. Requires a new repo secret ANTHROPIC_AUTH_TOKEN (Bearer token for the internal endpoint). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: address review feedback for claude review - Add concurrency group to cancel superseded reviews on rapid pushes - Skip job for fork PRs (no secret access) - Drop redundant git fetch (fetch-depth: 0 already pulls full history) - Retry LLM call up to 3x with exponential backoff - Validate response shape and surface non-text/error payloads instead of throwing KeyError Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: harden claude review against second-round feedback - Run review script from BASE_SHA, not PR head, so a PR cannot modify the script to exfiltrate ANTHROPIC_AUTH_TOKEN / GITHUB_TOKEN. Falls back to PR head only when the script does not yet exist at base (first-time bootstrap, e.g. this PR). - Truncate comment body to GitHub's 65536-char hard limit. - Bail out of retry loop on 4xx (except 408/429) so auth/format errors do not waste attempts. - Add jitter to exponential backoff. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: byte-accurate comment limit and GitHub POST error handling - GitHub's 65KB comment limit is bytes (not chars); slice the encoded utf-8 buffer and decode with errors='ignore' to avoid corrupting a multi-byte boundary. - Catch HTTPError / URLError on the comment POST and surface the response body so failures don't lose the review output silently. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: tighten claude review prompt format Enforce a strict output structure (Verdict / Summary / Must fix / Suggestions / Nits / Notes) with severity tags and required path:LINE citations. Bans emoji, requires a 2-3 sentence PR summary, and folds non-blocker items behind <details>. Adds debug-residue, layering, and silent-fallback to the review checklist. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [ilu/ixformer] update static_quant for 2d scale * [ilu/ixformer] support IxformerStorePagedKVCache chunk_metadata pass * misc: refine yml. * [ilu/ixformer] add log --------- Co-authored-by: fan.jiang <fan.jiang@iluvatar.com> Co-authored-by: xudong.zhao <xudong.zhao@iluvatar.com> Co-authored-by: wens <zhaowenshuo.oo@bytedance.com> Co-authored-by: xiaomei.wang <xiaomei.wang@iluvatar.com>
#326) * [ilu/ixformer] add IxformerPagedDecodeGQAWithKVDequant/IxformerPagedDecodeSWAWithKVDequant * fix: add _get_dequant_buffers * misc: update version. * fix: add max_total_seq_len for TTXPagedDecodeSWAWithKVDequant --------- Co-authored-by: 江帆 <fan.jiang@iluvatar.com> Co-authored-by: wens <zhaowenshuo.oo@bytedance.com>
* fix: [ttx/mlu][swa] move get_aux_mask on device * reduce extra casting kernels on the device
* feat: support MojoPerfillSageGQA * fix: modify the input shape form [T, Hq] to [Hq, T] * fix IxformerPagedPrefillSageGQA forward.
…#335) * refactor: align naming convention, change max_xxx_lens to max_xxx_len * Update mojo_opset/tests/accuracy/operators/test_attention.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update mojo_opset/tests/accuracy/operators/test_attention_cudagraph.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: chenyifan.42 <chenyifan.42@bytedance.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: xiaomei.wang <xiaomei.wang@iluvatar.com>
* feat: add attention_gate core impl. * misc: add tests. * feat: add MojoFusedAttnOutputGate. * [ilu/ixformer] support MojoFusedAttnOutputGate --------- Co-authored-by: xiaomei.wang <xiaomei.wang@iluvatar.com>
* Enable torch deterministic config for mojo deterministic mode * Update curl command to use proxy for downloading * revert last Removed proxy option from curl command for downloading ixformer wheel. --------- Co-authored-by: wwens7 <zhaowenshuo.oo@bytedance.com>
* WIP: add shmem_manager & support compute overlap comm ops
* feat(ttx): add triton-dist fused comm+compute operators for Ascend NPU
Add TTXAllGatherGemm, TTXGemmAllReduce, and TTXGemmReduceScatter backends
that fuse GEMM with collective communication via aclshmem on Ascend NPU.
Ported from triton-dist-package reference kernels and verified on 2-card setup.
Also fixes libentry import issue across all NPU triton kernels by adding a
try/except fallback in npu/utils.py, and rewrites multi-card comm tests to
use torchrun instead of mp.spawn.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* tmp
* refactor(runtime): unify TTX shmem management via MojoSymmetricMemoryManager
- Add backend="ttx" support to MojoSymmetricMemoryManager with unique_id
bootstrap mode (eliminates ASH_MASTER_ADDR/PORT env var requirement)
- Move shmem preload (.so conflict workaround) into centralized _init_ttx_backend
- Delete _ensure_ash_init from kernel layer (was runtime concern, not kernel)
- TTX operators now use runtime.get_backend_manager() + runtime.allocate_peer_mem()
- Add proper finalize path via close() for TTX backend
- Add bfloat16 support to GemmAllReduce and GemmReduceScatter kernels
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address code review feedback
- Use torch.npu.current_device() instead of self.rank for device_id
(fixes multi-node environments where rank != local device index)
- Fix typos: aclshmem_finialize → aclshmem_finalize, destory → destroy
- Fix README typo: mojo_opsetutils → mojo_opset.utils
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address Claude Code review feedback
- Simplify libentry fallback to direct definition (clearer intent)
- Remove debug test scripts from repo root (test_ag_gemm_torchrun.py,
test_ttx_allgather_gemm.py)
- Consolidate try/except ImportError for triton-dist kernels with
explicit None defaults to avoid confusing downstream errors
- Use output.add_(self.bias) instead of allocating new tensor
- Add comments explaining why torch.zeros (not empty) is required
for atomic_add kernels
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(test): skip quant comm tests when backend lacks implementation
Add @bypass_not_implemented to single-rank quant comm tests so they
are skipped (not failed) when MOJO_BACKEND=ttx on MLU/ILU CI where
no TTX implementation exists for MojoQuantGemmAll2All/MojoAll2AllQuantGemm.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor(test): remove single-rank and gloo tests from test_compute_with_comm
This file is dedicated to multi-card comm+compute fusion testing.
Remove single-rank parametrized tests (no real comm exercised, redundant
with other test files) and skip all tests in CI (require triton-dist +
multi-NPU environment with HCCL).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address second round Claude Code review
- Narrow ImportError catch: gate on `import triton_dist` specifically,
log at debug level when unavailable
- Replace pytest.mark.skip with pytest.importorskip("triton_dist") so
tests auto-enable when the dependency is available
- Read MOJO_TTX_SHMEM_SIZE_MB at call time (not module import) so tests
can override via env
- Remove stale TODO comments (replaced by importorskip mechanism)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(ttx): lazy-import npu utils to avoid loading npu kernels on ILU
Move `from mojo_opset.backends.ttx.kernels.npu.utils import get_num_cores`
from module-level to inside _ensure_shmem methods. This prevents ILU CI
from triggering npu kernel module load (which fails on `tl.gather`).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(ci): tolerate pytest exit code 5 when triton-dist is unavailable
test_compute_with_comm.py uses pytest.importorskip("triton_dist") which
skips all tests when the package is not installed. Pytest returns exit
code 5 for "no tests collected" which fails CI. Allow exit code 5 as
a valid outcome (all-skipped is expected until triton-dist is in CI).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address third round code review
- Fix CI exit code handling: `rc=$?; [ $rc -eq 0 ] || [ $rc -eq 5 ]`
correctly distinguishes "all skipped" (5) from real failures (1)
- Fix _ensure_shmem: always delegate to runtime.allocate_peer_mem()
(handles grow-on-demand) instead of early-returning on stale _peer_mem.
This prevents undersized buffer if operator is reused with larger K.
- Store self._runtime for consistent access across methods
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Skip distributed test for temp
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: song.liu <song.liu@iluvatar.com>
…mask, simplify kernel structure (#321) - Replace external aux_mask (pre-allocated triangular mask tensor) with inline causal mask computation directly in kernel - Remove redundant inner KV block loop for full pages (PAGE_SIZE == BLOCK_N), loading entire page in single iteration - Remove boundary_check for full-page loads to enable async SME copy path - Add num_stages=2 hint to full-page loop for pipeline pass trigger - Update autotune configs: larger BLOCK_M (256) and more warps (8/16) - Remove unused parameters: aux_mask_ptr, mask strides, AUX_MASK_SIZE, USE_AUX_MASK
Use pinned non-blocking H2D for group_offsets to avoid draining the GPU queue each call, and add small-M autotune tiles (BLOCK_M=16) so large-N MoE shapes pick a bandwidth-friendly config. Drop MAX_M from the autotune key to avoid re-tuning on varying per-group row counts.
Co-authored-by: song.liu <song.liu@iluvatar.com>
* refactor: distinguish between fused moe and non-fused moe * Update mojo_opset/core/operators/moe.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * refactor: update ixformer moe / quant_moe * refactor: support ep for fused moe (#350) * refactor: distinguish between fused moe and non-fused moe * Update mojo_opset/core/operators/moe.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * refactor: update ixformer moe / quant_moe * refactor: support EP for fused MojoMoE / MojoQuantMoE * fix: fix group gemm calls * fix: unify cudagraph settings for groupgemm * ci: add tests for fused ep moe --------- Co-authored-by: chenyifan.42 <chenyifan.42@bytedance.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * [ilu/ixformer] refine: EP of fused moe. * fix: support moe ep with dp inputs * fix: revert ixformer calls to adapt old versions * ci: fix ci * fix: update max init of swa * Update flash_attention.py --------- Co-authored-by: chenyifan.42 <chenyifan.42@bytedance.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: xiaomei.wang <xiaomei.wang@iluvatar.com>
* ci: fix tests for experts and quantexperts * Apply suggestions from code review Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * [ilu/ixformer] fix moe ops. * [ilu/ixformer] update ixformer version. * test(moe_ep): validate small-op composed nn.Module matches MojoMoE(torch) Adds _SmallOpMoEModule — a plain nn.Module assembled from MojoMoEGating / MojoMoEDispatch / MojoExperts / MojoMoECombine — and asserts its forward matches MojoMoE(backend='torch') under both EP=1 (plain pytest) and EP=2 (torchrun --nproc-per-node=2). In the EP path, expert_outputs is padded back to [num_tokens * top_k, hidden] with zeros at non-local positions because ixformer's moe_combine kernel rejects sliced tensors; the per-rank reduce yields the same total as the torch reference. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * doc: add docs for MoEDispatch --------- Co-authored-by: chenyifan.42 <chenyifan.42@bytedance.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: xudongzhao1006 <690335895@qq.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a high-performance FlashAttention-2 prefill path that dequantizes int8 KV blocks into a temporary bf16/fp16 cache before running the native FA2 prefill kernel. It also fixes a scale indexing bug by using kv_head_id instead of q_head_id and improves division safety. However, the reviewer identified a critical issue where the TTXPagedPrefillGQAWithKVDequant operator does not pass the required key_cache_dequant and value_cache_dequant buffers, leading to a guaranteed AssertionError crash. The reviewer suggested dynamically allocating these buffers on the fly if they are not provided to ensure robustness and backward compatibility.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| assert key_cache_dequant is not None, "key_cache_dequant must be pre-allocated" # shape: (N_blocks, Hkv, block_size, D) | ||
| assert key_cache_dequant.dtype == q.dtype, ( | ||
| "key_cache_dequant dtype must match query dtype for the dequant-FA2 prefill path" | ||
| ) | ||
| assert value_cache_dequant is not None, "value_cache_dequant must be pre-allocated" # shape: (N_blocks, Hkv, block_size, D) | ||
| assert value_cache_dequant.dtype == q.dtype, ( | ||
| "value_cache_dequant dtype must match query dtype for the dequant-FA2 prefill path" | ||
| ) |
There was a problem hiding this comment.
The TTXPagedPrefillGQAWithKVDequant operator does not pass key_cache_dequant and value_cache_dequant buffers to paged_attention_prefill_with_kv_dequant. Under the default configuration where use_dequant_fa2_prefill is True, this will cause a guaranteed AssertionError crash because these buffers are required to be pre-allocated.
To make the API robust and backward-compatible, we should allocate these buffers on the fly if they are not provided, rather than strictly asserting their presence. This allows the 100x faster FA2 path to be used even when the caller does not manage/cache the dequantized buffers.
| assert key_cache_dequant is not None, "key_cache_dequant must be pre-allocated" # shape: (N_blocks, Hkv, block_size, D) | |
| assert key_cache_dequant.dtype == q.dtype, ( | |
| "key_cache_dequant dtype must match query dtype for the dequant-FA2 prefill path" | |
| ) | |
| assert value_cache_dequant is not None, "value_cache_dequant must be pre-allocated" # shape: (N_blocks, Hkv, block_size, D) | |
| assert value_cache_dequant.dtype == q.dtype, ( | |
| "value_cache_dequant dtype must match query dtype for the dequant-FA2 prefill path" | |
| ) | |
| if key_cache_dequant is None: | |
| key_cache_dequant = torch.empty_like(key_cache, dtype=q.dtype) | |
| else: | |
| assert key_cache_dequant.dtype == q.dtype, ( | |
| "key_cache_dequant dtype must match query dtype for the dequant-FA2 prefill path" | |
| ) | |
| if value_cache_dequant is None: | |
| value_cache_dequant = torch.empty_like(value_cache, dtype=q.dtype) | |
| else: | |
| assert value_cache_dequant.dtype == q.dtype, ( | |
| "value_cache_dequant dtype must match query dtype for the dequant-FA2 prefill path" | |
| ) |
Claude Code ReviewVerdict: Request changes -- New dequant-FA2 prefill path requires pre-allocated buffers but the public op wrapper does not appear to provide them, and SummaryAdds a dequant-then-bf16-FA2 prefill path for int8 paged KV: a new Must fix
SuggestionsSuggestions (4)
NitsNits (2)
Notes
|
b27d50d to
9682dc2
Compare
Claude Code ReviewVerdict: Request changes -- Scalar fallback path now uses kv_head_id-indexed scales but receives per-Hq expanded scales no longer (good), yet the decode path and other callers may still pass Hq-expanded; also a likely shape bug in the dequant kernel's scale indexing for the fallback. SummaryAdds a dequant-then-bf16-FA2 prefill path for int8 paged KV by introducing a dedicated dequant kernel that materializes only referenced blocks, plus a numerically safer division in the FA2/decode kernels. Also fixes scale indexing in the existing scalar dequant prefill kernel from Must fix
SuggestionsSuggestions (4)
NitsNits (2)
Notes
|
- Add _dequant_paged_kv_block_kernel and rewrite the int8 dequant prefill to dequantize referenced KV blocks to bf16, then reuse the bf16 FA2 kernel; fall back to the scalar kernel for unsupported shapes. ~100x faster (1199ms -> 11.6ms). - Pass original (Hkv, D) scales (drop repeat_interleave); cache bf16 dequant buffers. - Make the GQA packed kernel's autotune-disabled config shared-mem-safe for large groups to fix OOR in CI; fix double-scaling in the non-packed partial-page loop.
9682dc2 to
f0f4181
Compare
Claude Code ReviewVerdict: Request changes -- The dequant prefill path always allocates two full bf16 KV-cache buffers even when the kernel chooses the scalar fallback, wasting large amounts of memory on the hot path. SummaryAdds a dequant-then-bf16-FA2 prefill path for int8 paged KV: a new kernel materializes only referenced int8 blocks into a bf16/fp16 paged cache of identical layout, then reuses the existing bf16 FA2 prefill kernel. Also fixes an indexing bug where the scalar dequant prefill kernel loaded K/V scales by Must fix
SuggestionsSuggestions (4)
NitsNits (2)
Notes
|
7defc82 to
df2f3da
Compare