Repository navigation
perf(exl3): keep bf16 activations on the native fp16 kernels (#4767) - #4817
Merged
Merged
Conversation
This was referenced Nov 17, 2026
6 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4767.
ExllamaV3Linear.forwardrouted every non-FP16 activation toExllamaV3TorchLinear. The default checkpoint dtype is BF16, so the defaultpath paid the ~39 ms torch decode (M=1) / ~44 ms (M=512) instead of the
native kernel's ~0.04 ms / ~0.46 ms.
Change
BF16 now stays on the native EXL3 kernels:
subset of FP16's 11-bit one and the value is inside FP16's finite range, so
the cast is bit-exact against the plain FP16 path.
math.frexp, so the scaledmagnitude lands in (0.5, 1]), run native, multiply back. The Hadamard rotation
is bounded by
sqrt(128)*amaxand GEMM accumulation stays far below FP16's65504 limit, preserving the wide-input guarantee from fix(exl3): route wide activations through Torch #3731.
bc.runbakes bias in;hgemmadds it explicitly) so it is never scaled.Pre-scale decision costs one
vector_norm(inf)reduction plus one host read perBF16 forward.
Measurements (GB10, sm_121, torch 2.15.0+cu132, synthetic EXL3 4-bit 4096->14336)
The native extension cannot be built on this box (CUDA toolkit/header
mismatch), so fp16/native timings are unavailable. Measured with a stub native
kernel to isolate the bridge:
The old torch decode accounted for ~99.8% of BF16 latency. No total-speedup
ratio is claimed for the native kernel itself since it cannot run here.
Tests
tests/test_exl3_wide_input.py-> 27 passed; the four-file EXL3 set ->205 passed, 8 skipped, 9 failed (all
test_exllamav3_torch_padding.pynative-JIT cases, identical failure set on the parent commit).
New tests: dispatch at 1/32/33/64 rows + zero rows, exact cast, power-of-two
pre-scale from 1e4-1e30, mocked-kernel numerics vs FP64 at 1e4/1e5
(scale-relative error <= 1e-2), non-finite fallback.
ruff: clean.