Skip to content

examples/deepseek_v32: add runnable precision comparison to act_quant.py#10

Merged
ChangChengShouWang merged 1 commit into
gemm_newfrom
copilot/add-accuracy-comparison
Apr 20, 2026
Merged

examples/deepseek_v32: add runnable precision comparison to act_quant.py#10
ChangChengShouWang merged 1 commit into
gemm_newfrom
copilot/add-accuracy-comparison

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 20, 2026

act_quant.py was a kernel-only file with no way to validate correctness. This adds a self-contained precision test runnable via python act_quant.py.

Changes

  • _fast_round_scale_ref — pure-PyTorch replica of the kernel's IEEE 754 bit-manipulation: extracts float32 exponent bits, computes ceil(log2), reconstructs a power-of-two via (exp+127)<<23. Matches kernel behavior exactly for both exact and non-exact powers of two.

  • act_quant_torch_ref — float32 reference quantisation: per-row absmax per N-group (clamped at 1e-4, matching the kernel), derives scale, clamps x/s to FP8 [-448, 448].

  • act_quant — kernel wrapper that pre-allocates Y as torch.float8_e4m3fn and S as float32 before dispatching to the compiled tilelang kernel.

  • run_test_case / run_test — exercises four (m, n, round_scale) configurations with two checks:

    • Scale S: tight tolerance (rtol=1e-3, atol=1e-4)
    • End-to-end dequant y·s ≈ x: FP8-appropriate tolerance (rtol=0.2, atol=0.1) accounting for the 3-bit mantissa quantisation step and scale rounding
TILELANG_ASCEND_MODE=Developer python examples/deepseek_v32/act_quant.py
#   m=  32  n= 128  round_scale=False  scale_max_err=...  dequant_max_err=...  PASS
#   m=  64  n= 256  round_scale=False  ...
#   m=  96  n= 512  round_scale=True   ...
#   m= 128  n= 128  round_scale=True   ...
# act_quant precision test passed.

Agent-Logs-Url: https://github.com/CeleNewYear/tilelang-ascend-dev/sessions/3c139960-1102-4131-88ad-316cc7b00772

Co-authored-by: ChangChengShouWang <188188721+ChangChengShouWang@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run bash format.sh in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work!

🚀

@ChangChengShouWang ChangChengShouWang merged commit 43df00d into gemm_new Apr 20, 2026
1 check passed
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.

2 participants