Skip to content

omni: INT4 per-block zero-point GEMM + calling adapter (torchao asymmetric INT4) - #658

Open
JWLHS wants to merge 4 commits into
intel:mainfrom
JWLHS:codex/int4-a16
Open

omni: INT4 per-block zero-point GEMM + calling adapter (torchao asymmetric INT4)#658
JWLHS wants to merge 4 commits into
intel:mainfrom
JWLHS:codex/int4-a16

Conversation

@JWLHS

@JWLHS JWLHS commented Aug 31, 2026

Copy link
Copy Markdown

This PR ports the INT4 per-block zero-point GEMM (torchao asymmetric INT4 format) and its ComfyUI calling adapter:

  • onednn_int4_gemm_preconverted: per-block zero points (w = (q - zp) * scale inside oneDNN), fp16/bf16 activations × u4 weights, group sizes 32/64/128/256, K up to 12288 without NaN.
  • ComfyUI-OmniXPU int4_gemm adapter with runtime capability probing (falls back cleanly when the kernel lacks per-block zp support).
  • Regression tests: tests/test_int4_preconverted_correctness.py (per-block zp vs manual w=(q-zp)*scale, fp16/bf16/f32, K=12288, CPU-tensor rejection).

Verification:

  • A770 (DG2): 62/62 kernel tests pass (including this PR's tests).
  • B580 (BMG, tested by yzwzhanghao2): onednn_int4_gemm_preconverted 6/6 pass on the same wheel.

Note: the W4A8 s8u4 GEMM previously bundled here is split out and stays in #629; this PR only carries the verified INT4 (a16) path.

…tric INT4)

onednn_int4_gemm_preconverted gains an optional zp_u8 [G, N]. When provided
it applies per-block zero points inside oneDNN, w = (q - zp) * scale — native
support for INT4 models quantized on the torchao backend (Int4PlainInt32Tensor:
int32 qdata byte view + per-block zp/scale, asymmetric). The per-block zero
point centers biased weight distributions per block, lowering quantization
error vs symmetric INT4.
- adapters/int4_gemm.py: int4_gemm wrapper over onednn_int4_gemm_preconverted
  with optional zp_u8 + capability check
- config flag OMNIXPU_INT4_GEMM + patch component registration
- zp 存在:探测 preconverted 是否接受 zp_u8;不支持则警告+返回 None
  (调用方回退自身 python/torchao 路径),不报错
- 无 zp(wa4):3 参调用,兼容不支持 zp 的老 kernel
- apply() 报告 preconverted 可用性与 zp 支持
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant