Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A number or a word is set like any environment variable, for example `STRATA_KVA
(`terminal/strata-<model>.json`), which the server passes to the engine. The Strata project's Terminal writes it there with
`strata launch --set NAME=value`.

## Switches you can turn on (365)
## Switches you can turn on (366)

Off unless you set them. The last column says where each one is described.

Expand Down Expand Up @@ -314,6 +314,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_Q8_V70` | number | NVIDIA and AMD | [NVIDIA_V100.md](NVIDIA_V100.md) |
| `STRATA_QSA_CLUSTER` | number | NVIDIA and AMD, Intel Arc | [DETAILS.md](DETAILS.md) |
| `STRATA_QSA_SPLIT_ATTN` | number | NVIDIA and AMD | [DETAILS.md](DETAILS.md) |
| `STRATA_QUANT_IQ4XS_X4_V2` | on / off | NVIDIA and AMD | [TEST_REQUESTS.md](TEST_REQUESTS.md) |
| `STRATA_RAM_ADAPT` | number | NVIDIA and AMD | [DETAILS.md](DETAILS.md), [release-notes-0.2.7.md](release-notes-0.2.7.md) |
| `STRATA_RAM_KEEP_GIB` | number | NVIDIA and AMD | [DETAILS.md](DETAILS.md), [UNSLOTH_Q4.md](UNSLOTH_Q4.md) |
| `STRATA_RDNA2_SGEMM` | number | AMD | [AMD_HIP.md](AMD_HIP.md), [README.md](bench-results/2026-10-04-rdna2-fp16-prompt/README.md) |
Expand Down
1 change: 1 addition & 0 deletions docs/TEST_REQUESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ This list is edited by the maintainers. An item stays until a report answers it.
| AMD RX 7000 series (RX 7900 XTX, 7900 XT, 7800 XT and similar, RDNA 3) on Linux or Windows | The RX 7000 builds have not been run on a real RX 7000 card by us; the Docker image for them is also untested on a card | none yet |
| Windows with an AMD card: the app or the Terminal, one model, one picture sent | The Windows AMD build has not been run on a real card, and neither has its picture reader (CPU under 24 GB, GPU from 24 GB) | none yet |
| A Mac with Apple silicon (macOS 15 or newer): the app or the Terminal with a real model | Mac builds have run on very few Macs. Tell us the Mac's memory, the model, the speed, and anything that failed. Pictures on the Mac (GPU reader) were run on one Mac mini M4 only: tell us if they work on yours. The signing script has not been run against Apple's real notary service yet, so a first-launch warning is expected and useful to hear about | none yet |
| A CPU without efficiency cores (AMD Ryzen, Intel before the 12th generation), a model with IQ4_XS experts outside VRAM (for example Qwen4-35B-A3B UD-IQ4_XS), decode with and without `STRATA_QUANT_IQ4XS_X4_V2=1` | The kernel it turns on gives the same bits with fewer instructions: 27% faster on one P-core of an i9-12900H with the weights in cache, 8% with them in RAM, and +2% decode with the experts held still there. Whether it helps on a CPU with fewer, faster cores per memory channel has not been measured | none yet |

To add a request, open a pull request that adds a row, or tell the maintainers in an issue.
2 changes: 2 additions & 0 deletions engine/cmake/strata_poly.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ if(STRATA_BUILD_POLY AND STRATA_NATIVE_EXPERTS AND (STRATA_ENABLE_CUDA OR STRATA
add_executable(poly_cpu_x4_test src/poly/cpu_x4_test.cpp src/poly/cpu_experts.cpp)
target_link_libraries(poly_cpu_x4_test PRIVATE strata_quant Threads::Threads)
add_test(NAME poly_cpu_x4_test COMMAND poly_cpu_x4_test)
add_test(NAME poly_cpu_x4_test_iq4xs_v2 COMMAND poly_cpu_x4_test) # the opt-in IQ4_XS four-row kernel
set_tests_properties(poly_cpu_x4_test_iq4xs_v2 PROPERTIES ENVIRONMENT "STRATA_QUANT_IQ4XS_X4_V2=1")
# T-MAC CPU cold-expert microbenchmark (native cpu_experts vs Path A vs Path B across ISAs and thread counts)
add_executable(tmac_bench tests/quant/tmac_bench.cpp src/poly/cpu_experts.cpp)
target_include_directories(tmac_bench PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/poly)
Expand Down
67 changes: 67 additions & 0 deletions engine/src/quant/x86/dot_avx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "../registry.hpp"
#include "strata/quant/dot.hpp"

#include <cstdlib>
#include <cstring>

namespace strata::quant {
namespace avx2 {

Expand Down Expand Up @@ -1009,7 +1012,71 @@ void dot_q4_K_q8_K_x4_avx2(int n, float out[4], const void* STRATA_RESTRICT w_ba
}
}

// (PolyStrata, opt-in: STRATA_QUANT_IQ4XS_X4_V2=1) dot_iq4_xs_q8_K_x4_avx2's sums with fewer instructions. A pair of
// sub-blocks' 32 bytes of nibbles in one 256-bit load (A: their low nibbles, B: their high ones), the 8 scales of a block
// decoded together and spread by one shuffle a pair, the activations rearranged to match once a block for the 4 rows,
// and the IQ4_NL signs applied to the activations (_mm256_sign_epi8) with the |values| on the unsigned side. Each
// 32-bit lane ends with the int32 products it has in the kernel below, and the float steps are its, so every output has
// its bits (poly_cpu_x4_test). One i9-12900H P-core: 16.5 -> 21.0 GB/s with the weights in cache, 11.0 -> 11.9 from RAM.
static void dot_iq4_xs_q8_K_x4_v2(int n, float out[4], const void* STRATA_RESTRICT w_base, size_t row_bytes,
const void* STRATA_RESTRICT vy) {
const int nb = n / QK_K;
const uint8_t* wb = (const uint8_t*) w_base;
const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
static constexpr uint8_t kAbsIq4nl[16] = {127, 104, 83, 65, 49, 35, 22, 10, 1, 13, 25, 38, 53, 69, 89, 113};
const __m256i abs256 = _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*) kAbsIq4nl));
const __m256i m4b = _mm256_set1_epi8(0x0F);
const __m256i k78 = _mm256_set1_epi8(0x78);
const __m128i m4s = _mm_set1_epi8(0x0F);
const __m128i m30 = _mm_set1_epi16(0x30);
const __m128i k32 = _mm_set1_epi16(32);
const __m128i hmul = _mm_setr_epi16(1 << 14, 1 << 12, 1 << 10, 1 << 8, 1 << 6, 1 << 4, 1 << 2, 1);
// pair p's scales: int16 2p in the low half, 2p + 1 in the high half, eight times each
const __m256i sctl[4] = {
_mm256_setr_epi8(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3),
_mm256_setr_epi8(4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7),
_mm256_setr_epi8(8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11),
_mm256_setr_epi8(12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15),
};
__m256 accum[4] = {_mm256_setzero_ps(), _mm256_setzero_ps(), _mm256_setzero_ps(), _mm256_setzero_ps()};
for (int ibl = 0; ibl < nb; ++ibl) {
const float yd = y[ibl].d;
__m256i ya[4], yb[4];
for (int p = 0; p < 4; ++p) {
const __m256i y0 = _mm256_loadu_si256((const __m256i*) (y[ibl].qs + 64 * p));
const __m256i y1 = _mm256_loadu_si256((const __m256i*) (y[ibl].qs + 64 * p + 32));
ya[p] = _mm256_permute2x128_si256(y0, y1, 0x20);
yb[p] = _mm256_permute2x128_si256(y0, y1, 0x31);
}
for (int r = 0; r < 4; ++r) {
const block_iq4_xs& bx = ((const block_iq4_xs*) (wb + r * row_bytes))[ibl];
// the 8 scales, negated (the signs below are the other way round): 32 - (low 4 bits | high 2 bits << 4)
uint32_t sl;
std::memcpy(&sl, bx.scales_l, 4);
const __m128i v = _mm_cvtsi32_si128((int) sl);
const __m128i l8 = _mm_unpacklo_epi8(_mm_and_si128(v, m4s), _mm_and_si128(_mm_srli_epi16(v, 4), m4s));
const __m128i hi = _mm_and_si128(_mm_srli_epi16(_mm_mullo_epi16(_mm_set1_epi16((short) bx.scales_h), hmul), 10), m30);
const __m256i sall = _mm256_broadcastsi128_si256(_mm_sub_epi16(k32, _mm_or_si128(_mm_cvtepu8_epi16(l8), hi)));
__m256i sa = _mm256_setzero_si256(), sb = _mm256_setzero_si256();
for (int p = 0; p < 4; ++p) {
const __m256i q = _mm256_loadu_si256((const __m256i*) (bx.qs + 32 * p));
const __m256i na = _mm256_and_si256(q, m4b), nbv = _mm256_and_si256(_mm256_srli_epi16(q, 4), m4b);
const __m256i sc = _mm256_shuffle_epi8(sall, sctl[p]);
const __m256i pa = _mm256_maddubs_epi16(_mm256_shuffle_epi8(abs256, na), _mm256_sign_epi8(ya[p], _mm256_add_epi8(na, k78)));
const __m256i pb = _mm256_maddubs_epi16(_mm256_shuffle_epi8(abs256, nbv), _mm256_sign_epi8(yb[p], _mm256_add_epi8(nbv, k78)));
sa = _mm256_add_epi32(sa, _mm256_madd_epi16(pa, sc));
sb = _mm256_add_epi32(sb, _mm256_madd_epi16(pb, sc));
}
const __m256i tot = _mm256_add_epi32(_mm256_permute2x128_si256(sa, sb, 0x20), _mm256_permute2x128_si256(sa, sb, 0x31));
accum[r] = _mm256_fmadd_ps(_mm256_set1_ps(h2f(bx.d) * yd), _mm256_cvtepi32_ps(tot), accum[r]);
}
}
for (int r = 0; r < 4; ++r) out[r] = hsum_float_8(accum[r]);
}

void dot_iq4_xs_q8_K_x4_avx2(int n, float out[4], const void* STRATA_RESTRICT w_base, size_t row_bytes, const void* STRATA_RESTRICT vy) {
static const bool v2 = [] { const char* e = std::getenv("STRATA_QUANT_IQ4XS_X4_V2"); return e && e[0] == '1'; }();
if (v2) return dot_iq4_xs_q8_K_x4_v2(n, out, w_base, row_bytes, vy);
assert(n % QK_K == 0);
const int nb = n / QK_K;
const uint8_t* wb = (const uint8_t*) w_base;
Expand Down
35 changes: 35 additions & 0 deletions terminal/data/settings-register.json
Original file line number Diff line number Diff line change
Expand Up @@ -42439,6 +42439,41 @@
"retire_after": "",
"retired_in": "0.2.16"
},
{
"name": "STRATA_QUANT_IQ4XS_X4_V2",
"backends": [
"cuda-hip"
],
"reads": [
{
"file": "engine/src/quant/x86/dot_avx2.cpp",
"line": 1078,
"backend": "cuda-hip",
"fn": "getenv"
}
],
"parse": "flag",
"default_state": null,
"code_default": null,
"engine_sets": [],
"engine_defaults": [],
"launch_files": [],
"launch_sets": [],
"launch_reads": [],
"doc_mentions": [
"docs/TEST_REQUESTS.md"
],
"first_commit": null,
"first_date": null,
"since": null,
"last_commit": null,
"last_date": null,
"status": "opt-in",
"owner": "kernels/cpu",
"note": "AVX2: the IQ4_XS four-row kernel with fewer instructions, the same bits",
"retire_after": "",
"retired_in": ""
},
{
"name": "STRATA_RAM_ADAPT",
"backends": [
Expand Down