Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
WSL2: survive the driver's ~1 GiB pinned host budget with 3 GPUs
Joost R.1564404f62f5
diff --git a/src/core/native_head.cpp b/src/core/native_head.cppindex fc9f694ff..2f58cfbd6 100644--- a/src/core/native_head.cpp+++ b/src/core/native_head.cpp@@ -5,6 +5,7 @@#include <cuda_runtime.h>#include <climits>+#include <cstdio>#include <cstring>#include <exception>@@ -102,6 +103,7 @@ const NativeEmbed* native_embed() { return g_embed; }NativeEmbed::~NativeEmbed() {if (host_) cudaFreeHost(host_);+ else if (dev_) cudaFree(const_cast<void*>(dev_)); // the VRAM fallback below}bool NativeEmbed::load(const std::string& path, int64_t n_embd, int64_t n_vocab, std::string& err) {@@ -119,17 +121,31 @@ bool NativeEmbed::load(const std::string& path, int64_t n_embd, int64_t n_vocab,row_ = strata::kernels::iq_row_bytes((int) t->type, n_embd);bytes_ = (uint64_t) row_ * (uint64_t) n_vocab;if (cudaHostAlloc(&host_, bytes_, cudaHostAllocMapped | cudaHostAllocPortable) != cudaSuccess) {+ // Under WSL2 the driver's pinned/mapped host budget (~1 GiB) can be spent by the GPU contexts+ // themselves (three cards). The table is only gathered from, so keep it in the current device's VRAM+ // instead: it costs its size there and reads faster than over PCIe.+ cudaGetLastError();host_ = nullptr;- err = "native embedding: cannot pin " + std::to_string(bytes_ >> 20) + " MiB";- return false;- }- std::memcpy(host_, gguf.tensor_data(*t), bytes_);- void* d = nullptr;- if (cudaHostGetDevicePointer(&d, host_, 0) != cudaSuccess) {- err = "native embedding: no device alias for the mapped table";- return false;+ void* d = nullptr;+ if (cudaMalloc(&d, bytes_) != cudaSuccess ||+ cudaMemcpy(d, gguf.tensor_data(*t), bytes_, cudaMemcpyHostToDevice) != cudaSuccess) {+ if (d) cudaFree(d);+ cudaGetLastError();+ err = "native embedding: cannot pin " + std::to_string(bytes_ >> 20) + " MiB, nor place it in VRAM";+ return false;+ }+ std::fprintf(stderr, "strata: native embedding: cannot pin %llu MiB, kept in VRAM instead\n",+ (unsigned long long) (bytes_ >> 20));+ dev_ = d;+ } else {+ std::memcpy(host_, gguf.tensor_data(*t), bytes_);+ void* d = nullptr;+ if (cudaHostGetDevicePointer(&d, host_, 0) != cudaSuccess) {+ err = "native embedding: no device alias for the mapped table";+ return false;+ }+ dev_ = d;}- dev_ = d;type_ = (int) t->type;n_embd_ = n_embd;n_vocab_ = n_vocab;diff --git a/src/program/generate.cpp b/src/program/generate.cppindex 092327c0a..3a7b57f96 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -1331,16 +1331,21 @@ int main(int argc, char** argv) {}}const bool native_pack = strata::kernels::cpu::expert_layout().native;- if (o.expert_cache_remote[0] > 0) {+ // STRATA_EARLY_REMOTE_CONTEXTS=1: create EVERY secondary context here, like CUDA1's. Under WSL2 the driver's+ // pinned/mapped host budget (dxg gpadl, ~1 GiB) is spent by CUDA0's weights and MTP before the later loop runs,+ // and a new context then fails with cudaErrorMemoryAllocation (CUDA2: "cudaSetDevice(2) failed: out of memory").+ const char* early_env = std::getenv("STRATA_EARLY_REMOTE_CONTEXTS");+ const bool early_remote = early_env && early_env[0] == '1';+ for (int r = 0; r < 3; ++r) if (o.expert_cache_remote[(size_t) r] > 0 && (r == 0 || early_remote)) {// Keep CUDA1's proven startup order: initialise its context before// allocating GPU0 weights or mapping the large host expert arena.double free_gib = 0;- if (!strata::core::RemoteExperts::preflight(remote_dev[0], free_gib, err)) {+ if (!strata::core::RemoteExperts::preflight(remote_dev[r], free_gib, err)) {std::fprintf(stderr, "strata generate: %s\n", err.c_str());return 1;}std::fprintf(stderr, "strata generate: CUDA%d context ready, %.2f GiB free before expert arena registration\n",- remote_dev[0], free_gib);+ remote_dev[r], free_gib);}// plan v0.3 P6: the PCIe share of the missed experts, measured per kind of pack (the paper, finding on PCIe).// PR #44: a x8 link carries half of what the native default assumes - the GPU's SMs read that share over the@@ -1743,7 +1748,7 @@ int main(int argc, char** argv) {}// Create the additional contexts after MTP has secured CUDA0 memory, but// before the host arena maps its expert pages into their address spaces.- for (int r = 1; r < 3; ++r) if (o.expert_cache_remote[(size_t) r] > 0) {+ for (int r = 1; r < 3; ++r) if (o.expert_cache_remote[(size_t) r] > 0 && !early_remote) {double free_gib = 0;if (!strata::core::RemoteExperts::preflight(remote_dev[r], free_gib, err)) {std::fprintf(stderr, "strata generate: %s\n", err.c_str());