Repository navigation
Conversation
…tions, the same bits STRATA_QUANT_IQ4XS_X4_V2=1 makes dot_iq4_xs_q8_K_x4_avx2 (cpu_experts()' four weight rows a call for IQ4_XS) take a kernel with the same int32 sums and float steps in fewer instructions: a sub-block pair's nibbles in one 256-bit load, a block's 8 scales decoded together, the activations rearranged once a block for the 4 rows, and the IQ4_NL signs put on the activations. Default off: unchanged. One core, 1 GiB of random rows (kbench), GB/s of weights, one activation row: i9-12900H P-core: in cache 16.5 -> 21.0 (+27%), from RAM 11.0 -> 11.9 (+8%) E-core: in cache 6.5 -> 7.6 (+17%), from RAM 6.1 -> 6.4 (+4%) Engine, Qwen4-35B-A3B UD-IQ4_XS, RTX 4060 Laptop, --kv q8_0, 300 tokens, 4 rounds: default 79.16 +- 3.72 -> 78.06 +- 1.07 tok/s (the same within the noise); experts held still 61.33 +- 1.30 -> 62.56 +- 1.09 (+2.0%), CPU experts 8.6 -> 8.3 ms a token, the same tokens in all 8 runs. poly_cpu_x4_test: 0 of 1,536 IQ4_XS values differ from the one-row kernel with it on; a second ctest entry runs the test that way. A test request asks for CPUs without efficiency cores. 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
cpu_experts()computes the IQ4_XS experts outside VRAM (gate and up of Unsloth's UD-IQ4_XS files, Qwen4-35B-A3B among them) withdot_iq4_xs_q8_K_x4_avx2, four weight rows against one activation row a call. On one core that kernel is bound by its instructions, not by memory, when the weights are in cache: 16.5 GB/s of weights on an i9-12900H P-core, where the new kernel reaches 21.0 on the same data with the same results.The new kernel computes the same int32 sums and the same float steps in fewer instructions. One core, 1 GiB of random rows (past the caches) or 512 KiB repeated (in cache), GB/s of weights, one activation row, two runs each (equal to 0.1):
mainSTRATA_QUANT_IQ4XS_X4_V2=1In the engine on this laptop the 14 CPU threads together are bound by RAM (about 47 of 62 GB/s), so the gain is small. Qwen4-35B-A3B UD-IQ4_XS, RTX 4060 Laptop 8 GB,
--kv q8_0, 300 tokens, the arms interleaved, 4 rounds:mainSTRATA_QUANT_IQ4XS_X4_V2=1STRATA_FREEZE_EXPERTS=1 --expert-swaps 0, 23% of the experts' uses from VRAM)A CPU with fewer cores for its memory bandwidth, or one whose cores are slower per clock, spends more of the experts' time in this kernel; that is the case this PR asks to be measured.
Related discussion
none (no issue). Follows
feat/quant-iq4xs-q4k-rows(several activation rows a call), which is independent of it.Approach
dot_iq4_xs_q8_K_x4_v2, taken bydot_iq4_xs_q8_K_x4_avx2when the variable is1(read once):mullo_epi16, shift and mask), negated, and spread to a pair by onepshufb;permute2x128) for all 4 rows, so each 32-bit lane holds the products it holds in the old kernel;sign_epi8) and only|value|looked up, somaddubstakes the table value unsigned;fmaddare the old kernel's, so every output has its bits.Validation
Revision
3f0a1c52f. Linux, i9-12900H (6 P-cores, 8 E-cores, AVX2, no AVX-512), GCC in the CUDA 13.4 build container; RTX 4060 Laptop 8 GB for the engine runs.Passed:
poly_cpu_x4_test(built with-DSTRATA_BUILD_TESTS=ON) with the variable set: 0 of 1,536 IQ4_XS values differ from the one-row kernel, bit for bit, row lengths 256 to 4,096; and without it, unchanged. A second ctest entry (poly_cpu_x4_test_iq4xs_v2) runs it with the variable set;ctest -R poly_cpu_x4: 2 of 2 passed.taskset -c 2P-core,-c 16E-core).python3 tools/settings_register.py --checkandpython3 -m unittest tools.test_settings_register: OK.Failed:
main's kernel the E-core is faster alone (table above), but a full-load E-core run againstmainhas not been repeated.Not run:
Limits
🤖 Generated with Claude Code