Skip to content
Merged
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 @@ -365,7 +365,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_WDDM_BUDGET` | number | AMD, Intel Arc | [AMD_HIP.md](AMD_HIP.md) |
| `STRATA_WDDM_MARGIN_MIB` | number | AMD | [AMD_HIP.md](AMD_HIP.md) |

## Switches that go back to earlier behaviour (119)
## Switches that go back to earlier behaviour (120)

These behaviours are on by default. Setting the switch returns the earlier behaviour; the notes in the register say which
version made it the default.
Expand Down Expand Up @@ -405,6 +405,7 @@ version made it the default.
| `STRATA_IL_PAD` | number | NVIDIA and AMD | v0.2.16 | - |
| `STRATA_INK_FLASH` | on / off | NVIDIA and AMD | - | - |
| `STRATA_INK_KERNEL_TABLES` | on / off | NVIDIA | - | [inkling.md](models/inkling.md) |
| `STRATA_INK_MMA75` | on / off | NVIDIA and AMD | - | [inkling.md](models/inkling.md) |
| `STRATA_INK_PROJECT_MIXED` | on / off | NVIDIA | - | - |
| `STRATA_IQ3_LANES` | on / off | NVIDIA and AMD | - | - |
| `STRATA_IQ_MT_MIN` | on / off | NVIDIA and AMD, CPU | v0.2.16 | [BATCHING.md](BATCHING.md), [DETAILS.md](DETAILS.md), [OLDER_GPUS.md](OLDER_GPUS.md) |
Expand Down
6 changes: 6 additions & 0 deletions docs/models/inkling.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ whatever its launch, so the answers are the same to the bit. It was measured +1.
Ti (22 GB, every expert in VRAM) and no change on an RTX 2070 (8 GB). `STRATA_POLY_EXPERT_TILES=0` goes back to a
launch for each run.

On an RTX 20 card a prompt's attention runs in a tensor-core kernel shaped for Turing: one layer's call of 1,024 rows
takes 1.0 ms in a sliding-window layer and 18 ms in a full layer at 32K keys (RTX 2070 Super). It rounds the
attention's sums in another order than the kernel before it, which `STRATA_INK_MMA75=0` goes back to (2.8 ms and
39 ms; a 32K prompt reads about 9% slower). Against that kernel's greedy answers to the three prompts above (64 tokens
each, the three files) it gives the same most likely token at 566 of the 576 steps (98.3%).

On an RTX 30 card or newer, most of a prompt's products run on the int8 tensor cores, with the prompt's numbers
rounded to 8 bits. UD-Q2_K_XL's IQ1_S experts (the gate and up of 6 layers) are the exception: they stay on halves
unless `STRATA_PREFILL_IQ1S=int8` is set. On an RTX 3090 that setting reads a 2,048-token prompt 7.7% faster (2,159
Expand Down
82 changes: 81 additions & 1 deletion engine/src/poly/ink_flash_test.cu
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// src/poly/ink_flash_test.cu - ink_attend_batch() (ink_flash_kernel, from Ampere on) against a float64 reference of the same attention, beside the two paths it stands in
// src/poly/ink_flash_test.cu - ink_attend_batch() (the flash kernels: ink_flash_kernel from Ampere on,
// ink_flash75_kernel or ink_mma75_kernel on Turing) against a float64 reference of the same attention, beside the two
// paths it stands in
// for: ink_attend() (a token's scores in floats) and attend_batch() with an AttnBias (cuBLAS products, the path
// Inkling2 takes when ink_attend_batch() does not). Inkling 2 Mini's heads: 128 values, 16 relative values; groups
// of 1 to 4 query heads, full and window layers, ring caches, a gate, calls that start past position 0.
//
// Then the same rows in one call and split over several: every output the same bits (a token's result does not depend
// on the call it is in). On Turing it tests ink_mma75_kernel, and ink_flash75_kernel with
// STRATA_INK_MMA75=0: run it both ways there.
//
// usage: poly_ink_flash_test (exit 0: every case within the bounds below; 77: no flash kernel here)
// each case also prints a hash of the flash kernel's output bits, which two
// builds of the same arithmetic must share
Expand All @@ -18,6 +24,7 @@
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <random>
#include <string>
Expand Down Expand Up @@ -214,6 +221,75 @@ size_t work_floats(int rows, int n_head) { // inkling2.cpp's awork_
return heads + heads / 2 + 1 + 3 * (size_t) rows * n_head;
}

// A token's result must not depend on the call it is in: the case's rows in one call, then the same rows (same caches,
// same inputs) in calls of the given sizes, one after another; every output float the same bits.
int run_split_tests(cudaStream_t st) {
struct Split {
Case c;
std::vector<int> sizes;
};
const Split splits[] = {
// name per n_kv pos rows window ring extent gate call sizes
{{"split window ring g3", 3, 8, 1900, 333, 1024, 1357, 1024, true}, {1, 100, 232}},
{{"split window 1K g3", 3, 8, 3072, 1024, 1024, 2048, 1024, true}, {512, 512}},
{{"split window 1K g3 odd", 3, 8, 3072, 1024, 1024, 2048, 1024, true}, {333, 21, 1, 669}},
{{"split full later g3", 3, 8, 1500, 200, 0, 0, 1024, false}, {21, 64, 115}},
{{"split full pos0 g3", 3, 8, 0, 700, 0, 0, 1024, true}, {300, 17, 383}},
{{"split window g1", 1, 8, 999, 64, 128, 192, 128, true}, {5, 59}},
{{"split full g2", 2, 4, 40, 130, 0, 0, 64, false}, {17, 113}},
{{"split full g4", 4, 2, 0, 77, 0, 0, 1024, false}, {5, 72}},
{{"split window g2", 2, 4, 300, 150, 128, 278, 128, true}, {7, 30, 113}},
{{"split window g4", 4, 2, 500, 90, 100, 190, 100, false}, {3, 87}},
{{"split window 20 g3", 3, 8, 64, 70, 20, 90, 20, true}, {11, 59}},
};
int fails = 0;
for (unsigned si = 0; si < sizeof(splits) / sizeof(splits[0]); ++si) {
const Split& sp = splits[si];
Call x(sp.c, 4321u + si);
const size_t per_row = (size_t) x.n_head * kDim, n_out = (size_t) sp.c.rows * per_row;
float* out = zeros(n_out);
InkAttn a = x.attn(out, nullptr, 0);
if (!ink_attend_batch(a, st)) {
std::printf("%-24s flash off\n", sp.c.name);
cudaFree(out);
continue;
}
ck(cudaStreamSynchronize(st), "ink_attend_batch");
const std::vector<float> whole = download(out, n_out);
ck(cudaMemset(out, 0, n_out * sizeof(float)), "cudaMemset");
// the calls last first, so a call that wrote past its rows would leave that behind
std::vector<int> first;
int at = 0;
for (const int m : sp.sizes) first.push_back(at), at += m;
bool took = true;
for (size_t k = sp.sizes.size(); k-- > 0;) {
const int m = sp.sizes[k];
at = first[k];
InkAttn b = a;
b.q = x.dq + (size_t) at * per_row;
b.r = x.dr + (size_t) at * x.n_head * kRel;
b.sink = x.dsink + (size_t) at * x.n_head;
if (x.dgate) b.gate = x.dgate + (size_t) at * per_row;
b.out = out + (size_t) at * per_row;
b.pos = sp.c.pos + at;
b.rows = m;
took = ink_attend_batch(b, st) && took;
}
at = first.back() + sp.sizes.back();
ck(cudaStreamSynchronize(st), "ink_attend_batch (split)");
const std::vector<float> parts = download(out, n_out);
size_t differ = 0;
for (size_t i = 0; i < n_out; ++i) differ += std::memcmp(&whole[i], &parts[i], 4) != 0;
const bool ok = took && at == sp.c.rows && differ == 0;
std::printf("%-24s one call fnv %016llx | %zu calls fnv %016llx | %zu floats differ %s\n", sp.c.name,
(unsigned long long) fnv(whole), sp.sizes.size(), (unsigned long long) fnv(parts), differ,
ok ? "ok" : "FAIL");
fails += !ok;
cudaFree(out);
}
return fails;
}

int run_tests() {
const Case cases[] = {
// name per n_kv pos rows window ring extent gate
Expand All @@ -228,6 +304,9 @@ int run_tests() {
{"window ring odd g3", 3, 4, 2049, 45, 100, 145, 100, false},
{"window ring g1", 1, 8, 999, 64, 128, 192, 128, true},
{"few rows g3", 3, 8, 33, 32, 0, 0, 1024, false},
{"window ring g2", 2, 4, 700, 150, 128, 278, 128, true},
{"window ring g4", 4, 2, 333, 90, 100, 190, 100, false},
{"window 20 g3", 3, 8, 64, 70, 20, 90, 20, true},
};
cudaStream_t st;
ck(cudaStreamCreate(&st), "stream");
Expand Down Expand Up @@ -272,6 +351,7 @@ int run_tests() {
fails += !ok;
for (void* p : {(void*) out, (void*) score, (void*) work, (void*) zero}) cudaFree(p);
}
fails += run_split_tests(st);
blas_destroy(blas);
cudaStreamDestroy(st);
std::printf("%d failed\n", fails);
Expand Down
Loading
Loading