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++
Merge branch 'f-139b-spd' into f-139-rel
Niko12214f5e6c841d4f
diff --cc include/strata/hip_compat/cuda_runtime.hindex 2359da983,84f9c13be..8ea907a94--- a/include/strata/hip_compat/cuda_runtime.h+++ b/include/strata/hip_compat/cuda_runtime.h@@@ -40,12 -39,9 +40,13 @@@#define cudaEventSynchronize hipEventSynchronize#define cudaEvent_t hipEvent_t#define cudaFree hipFree+#if HIP_VERSION_MAJOR < 7+#define cudaFreeHost hipHostFree+#else#define cudaFreeHost hipFreeHost+#endif#define cudaFuncAttributeMaxDynamicSharedMemorySize hipFuncAttributeMaxDynamicSharedMemorySize+ #define cudaFuncAttributePreferredSharedMemoryCarveout hipFuncAttributePreferredSharedMemoryCarveout#define cudaGetDevice hipGetDevice#define cudaGetDeviceCount hipGetDeviceCount#define cudaGetDeviceProperties hipGetDevicePropertiesdiff --cc src/core/expert_source.cppindex 3e3951097,0ac6e3912..98e1952d6--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@@ -2127,16 -2099,30 +2127,30 @@@ void expert_pool_dispatch_multi(ExpertDfor (int64_t i = 0; i < n; ++i) if (d.remote[r]->owns(i)) kind[i] = 2;}}+ static const bool dec_batch = [] { const char* v = std::getenv("STRATA_DEC_BATCH"); return v == nullptr || std::atoi(v) != 0; }();+ // the GPU's copy_rows_from_mapped zeroes the rows it computed itself (dec_batch); STRATA_VERIFY_DEVICE_PLAN's+ // copy_or_zero_from_mapped copies every row, so there the host still zeroes them+ static const bool device_plan = [] { const char* v = std::getenv("STRATA_VERIFY_DEVICE_PLAN"); return v != nullptr && std::atoi(v) != 0; }();+ const bool gpu_zeroes_hits = (d.plan != nullptr && n <= kMaxWindowEntries && n <= d.plan->cap && dec_batch && !device_plan);+ bool any_cpu = false;+ for (int64_t i = 0; i < n; ++i)+ if (kind[i] < 0) { any_cpu = true; break; }const auto c1 = std::chrono::steady_clock::now();- if (native && strata::kernels::cpu::q2_native_kernels(lay.fmt[(size_t) d.layers].gu_type)) // a native Q2_0 pack: the Q2_0 kernels' activations- for (int64_t t = 0; t < n_tok; ++t) act_quant_any(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);- else if (native)- for (int64_t t = 0; t < n_tok; ++t)- native_quant_act(lay.fmt[(size_t) d.layers], x_f + (size_t) t * H, d.nact_multi.data() + (size_t) t * kNativeActBytes);- else- for (int64_t t = 0; t < n_tok; ++t) act_quant_q8_1(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);+ if (any_cpu) {+ // #578 --remote-expert-opt: a token whose experts all run on a GPU (CUDA0 or a helper) needs no CPU activation+ const bool ep = d.remote_count > 0 && d.remote[0]->optimized_decode();+ for (int64_t t = 0; t < n_tok; ++t) {+ if (ep && std::all_of(kind + t * k, kind + (t + 1) * k, [](int32_t v) { return v >= 0; })) continue;- if (native && lay.fmt[(size_t) d.layers].gu_type == 42) // a native Q2_0 pack: the Q2_0 kernels' activations++ if (native && strata::kernels::cpu::q2_native_kernels(lay.fmt[(size_t) d.layers].gu_type)) // a native Q2_0 pack: the Q2_0 kernels' activations+ act_quant_any(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);+ else if (native)+ native_quant_act(lay.fmt[(size_t) d.layers], x_f + (size_t) t * H, d.nact_multi.data() + (size_t) t * kNativeActBytes);+ else+ act_quant_q8_1(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);+ }+ }const auto c2 = std::chrono::steady_clock::now();- { // CS-T: the experts the CPU computes, fetched together (the GGUF in place reads them on several threads)+ if (any_cpu) { // CS-T: the experts the CPU computes, fetched together (the GGUF in place reads them on several threads)static thread_local std::vector<int64_t> miss;miss.clear();for (int64_t i = 0; i < n_tok * k; ++i)diff --cc src/kernels/cpu/expert_layout.cppindex ddf232c51,7b61e4c72..8b6e3bc2c--- a/src/kernels/cpu/expert_layout.cpp+++ b/src/kernels/cpu/expert_layout.cpp@@@ -70,9 -53,40 +70,41 @@@ bool cpu_avx512_ok()return ok;}+ bool cpu_avx512bw_ok() {+ static const bool ok = [] {+ if (const char* f = std::getenv("STRATA_FORCE_AVX2"); f != nullptr && f[0] == '1') return false;+ unsigned r[4] = {0, 0, 0, 0};+ auto cpuid = [&](unsigned leaf, unsigned sub) {+ #if defined(_MSC_VER)+ int x[4];+ __cpuidex(x, (int) leaf, (int) sub);+ for (int i = 0; i < 4; ++i) r[i] = (unsigned) x[i];+ #else+ __cpuid_count(leaf, sub, r[0], r[1], r[2], r[3]);+ #endif+ };+ cpuid(0, 0);+ if (r[0] < 7) return false;+ cpuid(1, 0);+ if (!((r[2] >> 27) & 1u)) return false; // OSXSAVE+ #if defined(_MSC_VER)+ const unsigned long long xcr0 = _xgetbv(0);+ #else+ unsigned lo = 0, hi = 0;+ __asm__ volatile("xgetbv" : "=a"(lo), "=d"(hi) : "c"(0));+ const unsigned long long xcr0 = ((unsigned long long) hi << 32) | lo;+ #endif+ if ((xcr0 & 0xE6) != 0xE6) return false; // the OS saves the AVX-512 state+ cpuid(7, 0);+ const unsigned ebx = r[1];+ return ((ebx >> 16) & 1u) && ((ebx >> 17) & 1u) && ((ebx >> 30) & 1u) && ((ebx >> 31) & 1u);+ }();+ return ok;+ }+bool cpu_avx2_ok() {static const bool ok = [] {+ if (cpu_isa_cap() < 2) return false;unsigned r[4] = {0, 0, 0, 0};auto cpuid = [&](unsigned leaf, unsigned sub) {#if defined(_MSC_VER)diff --cc src/kernels/cuda/iq_kernels.cuindex bbcf1d065,b8ab4a5aa..5c552fa76--- a/src/kernels/cuda/iq_kernels.cu+++ b/src/kernels/cuda/iq_kernels.cu@@@ -2210,33 -1899,8 +2538,34 @@@ void native_expert_grouped(const Native(int) L.n_ff, hq);}check("native_expert_grouped/swiglu");+ }+ if (g_exp_phase == 1) return;- const dim3 gd((unsigned) ((L.n_embd + 7) / 8), (unsigned) gy);+ const int d_rows = (!g_old_kernels && L.n_ff == 640) ? (L.d_type == 20 ? 32 : (L.d_type == 42 ? 16 : 8)) : 8;+ const dim3 gd((unsigned) ((L.n_embd + d_rows - 1) / d_rows), (unsigned) gy);+#if defined(STRATA_HIP_GFX906)+ if ((em0 == 7 || em0 == 8) && (L.d_type == 20 || L.d_type == 42)) {+ const dim3 gl((unsigned) ((L.n_embd + LDS_RB - 1) / LDS_RB), (unsigned) cap_groups);+ const size_t sh = (size_t) LDS_NT * (size_t) (L.n_ff / 32) * sizeof(block_q8_1);+ if (L.d_type == 20) native_down_lds_kernel<20><<<gl, 256, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out);+ else native_down_lds_kernel<42><<<gl, 256, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out);+ check("native_expert_grouped/down");+ return;+ }+ const int em = exp_mode() >= 5 ? 2 : exp_mode();+ const dim3 gd_amd((unsigned) ((L.n_embd + (em == 1 ? 3 : em == 4 ? 31 : 15)) / (em == 1 ? 4 : em == 4 ? 32 : 16)), (unsigned) cap_groups);+#define STRATA_D_AMD(T) \+ case T: if (em == 1) native_down_amd_kernel<T, 1><<<gd_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); \+ else if (em == 4) native_down_amd_kernel<T, 4><<<gd_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); \+ else native_down_amd_kernel<T, 2><<<gd_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;+ // the AMD layouts cover the IQ packs' down types; the others (Unsloth's Q4_K / Q5_K / Q5_1 / Q8_0) take the+ // CUDA layout below+ if ((em == 1 || em == 2 || em == 4) && (L.d_type == 20 || L.d_type == 23 || L.d_type == 42)) {+ switch (L.d_type) {+ STRATA_D_AMD(20) STRATA_D_AMD(23) STRATA_D_AMD(42)+ }+ } else+#undef STRATA_D_AMD+#endifswitch (L.d_type) {#define STRATA_DOWN(T) case T: launch_down<T>(gd, s, grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;STRATA_D_FMTS(STRATA_DOWN)