Skip to content
Open
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 @@ -386,7 +386,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 (137)
## Switches that go back to earlier behaviour (138)

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 @@ -497,6 +497,7 @@ version made it the default.
| `STRATA_QUANT_NVFP4_X4` | on / off | NVIDIA and AMD | - | [inkling.md](models/inkling.md) |
| `STRATA_QUANT_ROWS4` | on / off | NVIDIA and AMD | - | - |
| `STRATA_QWEN4_KERNEL_TABLES` | on / off | NVIDIA | - | [qwen4.md](models/qwen4.md) |
| `STRATA_QWEN4_PLE_AHEAD` | on / off | NVIDIA and AMD | - | [qwen4.md](models/qwen4.md) |
| `STRATA_RDNA_KQ_ALL` | on / off | NVIDIA and AMD | v0.2.19 | - |
| `STRATA_REMOTE_SPIN` | on / off | NVIDIA, AMD, Intel Arc | v0.2.16 | - |
| `STRATA_RESIDENT_PIN` | on / off | NVIDIA and AMD, Intel Arc | v0.2.16 | [DETAILS.md](DETAILS.md), [TROUBLESHOOTING.md](TROUBLESHOOTING.md), [UNSLOTH_Q4.md](UNSLOTH_Q4.md) |
Expand Down
14 changes: 14 additions & 0 deletions docs/models/qwen4.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ All downloads come from [unsloth/Qwen4-35B-A3B-GGUF](https://huggingface.co/unsl
and embedded MTP weights, and shard 2 holds the PLE n-gram table (shared by hardlink across tiers that use the same PLE
table). `strata-poly` opens shard 1 via `--model` and maps shard 2 automatically.

`--ple-direct` (opt-in, CUDA and HIP) reads the table's rows straight from disk instead of the map: the same Direct
n-gram row reader the Flash Next engine uses for its own PLE (unbuffered reads, a ~100 MB row cache, an SSD
keep-alive), so the table's bytes stay out of RAM and the VRAM reserve no longer counts them as files that need page
cache. A prompt's rows then come from the SSD while it is read: on a Windows PC with a PCIe 3.0 SSD prompts were read
about 3.4 times slower than with the map (PR #440's report), so it is not the default. Apple Silicon always keeps the
map (its gathers need no copy at all).

With `--ple-direct` the reader also reads ahead (`STRATA_QWEN4_PLE_AHEAD=0` turns it off): a verify window's rows are
asked for while its guesses are drafted, and a prompt's rows in chunks of 1,024 tokens up to 4,096 tokens ahead of the
call being read. On an RTX 4060 Laptop 8 GB with an RS1D0TSSD710 SSD and UD-IQ4_XS, `--kv q8_0`, decode went from
82.88 ± 2.86 to 86.05 ± 1.00 tokens/s (6 interleaved runs, 500 tokens) and a 6,000-token prompt from 1,088.7 to
1,138.7 tokens/s (frozen experts), the same tokens. The reader's reads run on `STRATA_IO_THREADS` threads (16 by
default on Linux); 64 read a long prompt at 1,012.8 tokens/s against 977.8 with 16 on that SSD.

| Size | Download (GB) | Routed experts (GB) | Dense weights (GB) | PLE table (GB) | Estimated RAM floor (GB) |
| --- | ---: | ---: | ---: | ---: | ---: |
| **UD-IQ2_XS** | 24.5 | 10.18 | 2.27 | 11.52 (IQ4_NL) | 16 |
Expand Down
5 changes: 4 additions & 1 deletion engine/src/poly/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,9 @@ void Engine::fill_expert_cache() {
if (!opt_.gpu_experts || n_moe_ == 0) return;
size_t free_b = 0, total_b = 0;
ck(cudaMemGetInfo(&free_b, &total_b), "cudaMemGetInfo");
const size_t ram = ram_available(), files = gg_->bytes() + (dg_ ? dg_->bytes() : 0);
// (not what the architecture reads from its file with no page cache, direct_file_bytes(): it takes no RAM)
const size_t all_files = gg_->bytes() + (dg_ ? dg_->bytes() : 0);
const size_t ram = ram_available(), files = all_files - std::min(all_files, direct_file_bytes());
ram_tight_ = ram > 0 && files + (5ULL << 30) > ram;
// 256 MiB at least, whatever was asked: the launches recorded later take theirs out of the reserve (mind_vram())
reserve_mib_ = opt_.vram_reserve_mib >= 0 ? std::max(opt_.vram_reserve_mib, 256) :
Expand Down Expand Up @@ -11091,6 +11093,7 @@ bool Engine::read(const int32_t* tokens, int n, const Mark* marks, int n_marks,
}
hold(lead);
cover(pos_ + n);
if (n_co == 0) read_begins(tokens, n);
// On several cards, each reads through its own layers and hands the rows on, and `turn` hears of a card's
// turns as its share of the model's layers: [lo_, to).
const std::function<bool(int, int)>* asked = turn;
Expand Down
9 changes: 9 additions & 0 deletions engine/src/poly/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ struct Options {
std::string basinkv_kv_quant = "int8"; ///< BasinKV pinned host KV format: "int8" or "wht_int4" (--basinkv-kv-quant)
float basinkv_alpha = -1.f; ///< BasinKV Quest shrunk-box radius weight in [0, 1]; < 0: auto (0.25 if D>=256 else 1.0)
float basinkv_beta = 0.10f; ///< BasinKV SphereIndex subspace radius weight beta >= 0 (--basinkv-beta)
bool ple_direct = false; ///< --ple-direct (opt-in, not Metal): a qwen4exp PLE n-gram table read row by row from
///< disk through the Direct row reader (the Flash Next engine's own); by default the
///< table is mapped on host, as before
bool freeze_experts = false; ///< the experts' split held still for the whole run, as STRATA_FREEZE_EXPERTS=1
#if defined(STRATA_GPU_METAL)
KvFmt kv_format = KvFmt::kAuto; ///< Q8 for compatible Qwen35MoE geometry, otherwise fp16
Expand Down Expand Up @@ -647,6 +650,9 @@ class Engine {
virtual void reset_call() {}
/// Optional host hook called in run() and step() after r_ (and at_) upload, before any layer or CUDA Graph launch.
virtual void begin_step(const int32_t* tokens, int n) { (void) tokens; (void) n; }
/// A read's tokens, all of them, before its first call (read(), one sequence at pos_): an architecture may start
/// fetching what the calls will need of them.
virtual void read_begins(const int32_t* tokens, int n) { (void) tokens; (void) n; }
/// Optional hook called by copy_seq() to duplicate any architecture-private per-sequence host state.
virtual void on_copy_seq(int from, int to) { (void) from; (void) to; }
/// Optional architecture lifecycle hooks (no-op by default; used by opt-in BasinKV).
Expand Down Expand Up @@ -699,6 +705,9 @@ class Engine {
/// A token's experts outside VRAM may go to the host's threads through the doorbell (h_bell_): the architecture
/// routes on the card (route_card()) and sums a token's experts in moe_card() when moe_sum_later() is false.
virtual bool bells() const { return false; }
/// Bytes of the model's files the architecture reads straight from disk, with no page cache (Qwen4's PLE n-gram
/// table through the Direct reader): they are not RAM the files need, which fill_expert_cache()'s reserve counts.
virtual size_t direct_file_bytes() const { return 0; }
/// follow(): the tokens over which an expert's recent uses halve (kSwapHalf for every family but Inkling 2).
virtual int swap_half() const;
/// Options::expert_swaps when it is not given (-1): the uploads on their way into the cache at a time.
Expand Down
4 changes: 4 additions & 0 deletions engine/src/poly/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,9 @@ void usage() {
" --basinkv-alpha F BasinKV Quest shrunk-box radius weight in [0, 1] (default -1 = auto:\n"
" 0.25 for head_dim >= 256, 1.0 below)\n"
" --basinkv-beta F BasinKV SphereIndex subspace radius weight >= 0 (default 0.10)\n"
" --ple-direct opt-in: read a qwen4exp PLE n-gram table's rows straight from disk through the\n"
" Direct n-gram row reader the Flash Next engine uses (unbuffered reads, a ~100 MB\n"
" row cache, SSD keep-alive) in place of a host map of its file; not on Metal\n"
" --kv fmt the K and V attention caches' format, opt-in: fp16 (default,\n"
" unchanged); q8_0 (ggml Q8_0 blocks: half the KV VRAM, slightly\n"
" different answers; qwen35moe's, kolibri1's, Flint's and Inkling 2's,\n"
Expand Down Expand Up @@ -2454,6 +2457,7 @@ int main(int argc, char** argv) {
}
o.basinkv_beta = x;
}
else if (a == "--ple-direct") o.ple_direct = true;
else if (a == "--kv") {
const std::string fmt = val();
if (fmt == "fp16") o.kv_format = KvFmt::kFp16;
Expand Down
Loading