Repository navigation
Conversation
…-VNNI), the same bits cpu_experts() computed NVFP4 experts (Inkling 2 Mini UD-Q4_K_XL, layers 0-19) one weight row at a time, and that kernel was bound by its instructions: with 14 threads of an i9-12900H it read 42.2 GB/s of weights where Q4_K and Q8_0 reach the RAM's 63-65 GB/s. dot_nvfp4_q8_0_x4 (x86_nvfp4_x4.inc, built in the AVX2 and the AVX-VNNI tier) loads the activations and their scales once for four rows, takes a block's 32 code bytes in one load and puts them in the one-row kernel's order with one permute and two unpacks, and puts the code's sign on the activation; the int32 sums, the scale products and the fmadd chain are the one-row kernel's, so every value has its bits. The AVX-VNNI tier gets a four-row table: cpu_experts takes a four-row kernel of the one-row kernel's own tier only, and on AVX-VNNI CPUs (Alder Lake and later) that is the AVX-VNNI one. STRATA_QUANT_NVFP4_X4=0 turns it off (registered as a rollback switch). i9-12900H, 1 GiB+ of random rows: 14 threads 42.2 -> 48.4 GB/s (+15%); one P-core 9.8 -> 12.2 GB/s (+24%). Inkling 2 Mini UD-Q4_K_XL, RTX 4060 Laptop, 14 threads, experts held still: 6 interleaved pairs, alternating order, the four-row kernel faster in each; settled rounds 19.7 -> 21.3 tokens/s, CPU experts 30.8 -> 27.9 ms a token; the same tokens in all 12 runs. Default settings: CPU experts 9.6 -> 9.0 ms, decode 39.9 -> 40.4 (within the noise). poly_cpu_x4_test: NVFP4 0 of 1,536 values differ from the one-row kernel, in the AVX-VNNI tier and with STRATA_FORCE_ISA=avx2; its NVFP4 blocks take any scale byte (0x7F and bit 7 included). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
Collaborator
|
Integrated on |
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.
Problem and result
Inkling 2 Mini's UD-Q4_K_XL stores the experts of layers 0 to 19 as NVFP4. The experts the card does not hold are computed on the CPU, one weight row at a time with
dot_nvfp4_q8_0, and on an RTX 4060 Laptop (8 GB) that is 38% of a token's time (9.4 of about 25 ms;perf:dot_nvfp4_q8_0is 42% of the process's CPU samples). That kernel is bound by its instructions, not by the RAM. With 14 threads of an i9-12900H, each over its own slice of random rows, it reads 42.2 GB/s of weights where Q4_K reaches 62.7 and Q8_0 65.2 GB/s (the RAM's limit).The new kernel computes four weight rows against one activation row a call:
Inkling 2 Mini UD-Q4_K_XL, RTX 4060 Laptop, 14 threads, a short chat (42-token prompt, 178 tokens written):
STRATA_QUANT_NVFP4_X4=0)STRATA_FREEZE_EXPERTS=1 --expert-swaps 0), 6 interleaved pairs, alternating which runs firstOn was faster in each of the 6 pairs. The first pair (and the second run of the second) was faster for both, before the laptop settled; "settled" is rounds 3 to 6. The gain grows with the share of experts the CPU computes: smaller cards, longer answers on a full cache.
Related discussion
none (no issue).
Approach
dot_nvfp4_q8_0_x4in a newsrc/quant/x86/x86_nvfp4_x4.inc, included bydot_avx2.cpp(int sums bymaddubs+madd) anddot_avxvnni.cpp(byVPDPBUSD), asx86_dots.incis:kvalues_fp4is sign and magnitude) goes on the activation, as ggml'sabs/signpair does, so the products are the same;ue4m3_to_fp32(d) * dy), spread by twopermutevar8x32, and thefmaddchain (sub-blocks 0-1, then 2-3) andhsum_float_8are its.dot_avxvnni.cppgets a four-row table (avxvnni_dot_x4_table(), underSTRATA_QUANT_AVXVNNIlike its dot table) anddot_x4_kernel()reads it.cpu_experts()'rows_of()takes a four-row kernel of the one-row kernel's own tier only, and on CPUs with AVX-VNNI (Alder Lake and later, Zen 5) the one-row NVFP4 kernel is the AVX-VNNI one. Without that table the AVX2 four-row kernel would not be taken there.STRATA_QUANT_NVFP4_X4=0leaves NVFP4 out ofdot_x4_kernel()(a rollback switch interminal/data/settings-register.json,docs/SETTINGS.mdregenerated); a section indocs/models/inkling.md.poly_cpu_x4_test:fill()knows NVFP4 blocks (any scale byte, 0x7F and bit 7 included), so NVFP4 is checked now.inkling.md.Validation
Revision
c5c048d03. Linux, i9-12900H (6 P-cores, 8 E-cores, AVX2 + AVX-VNNI, no AVX-512), 30 GB RAM, GCC in the CUDA 13.4 build container; RTX 4060 Laptop GPU 8 GB; Inkling 2 Mini UD-Q4_K_XL (Unsloth).Passed:
poly_cpu_x4_test(built with-DSTRATA_BUILD_TESTS=ON): NVFP4 0 of 1,536 values differ from the one-row kernel (row lengths 256 to 4,096); in the AVX-VNNI tier and withSTRATA_FORCE_ISA=avx2(the AVX2 tier); PASS. WithSTRATA_QUANT_NVFP4_X4=0: NVFP4 one row at a time, PASS.python3 tools/settings_register.py --checkandpython3 -m unittest tools.test_settings_register: OK.Failed:
Not run:
STRATA_FORCE_ISA=avx2), AMD CPUs, AVX-512 CPUs (which take the AVX-512 one-row kernel, so this kernel is not used there), Windows / MSVC.Limits
🤖 Generated with Claude Code