V100 fusions (#1097) behind STRATA_FUSE_DECODE=1; pf_wmma opt-in and only when every visible card is cc 7+; WMMA path skips NVFP4 layers; docs
This commit is contained in:
1 parent
a6bdc3fb5b
commit
c0d02ba96a
7 files changed
+120
-45
No files matched your search
+14
-1
@@ -27,7 +27,7 @@ select "old" kernels everywhere: which kernel runs is decided per architecture w
|
||||
|
||||
| Part of the prompt path | On sm_70 |
|
||||
| --- | --- |
|
||||
| MoE experts | `gemm_iq_f16_grouped`: a group of experts per launch on the FP16 tensor cores, the weights dequantized in shared memory (+10% prompt speed against MMQ's `dp4a` kernels, [bench](../bench/results/2026-10-07-v100-prompt-experts/README.md); `STRATA_PF_WMMA=0`: MMQ) |
|
||||
| MoE experts | opt-in (`STRATA_PF_WMMA=1`, only when every visible card is compute capability 7+; MMQ otherwise): `gemm_iq_f16_grouped`: a group of experts per launch on the FP16 tensor cores, the weights dequantized in shared memory (+10% prompt speed against MMQ's `dp4a` kernels, [bench](../bench/results/2026-10-07-v100-prompt-experts/README.md); FP16 activations instead of MMQ's q8_1, so the answers differ) |
|
||||
| Dense projections (dequantized weights) | FP16 tensor-core GEMMs (cuBLAS / CUTLASS `s884`) |
|
||||
| BF16 projections (hyper-connection, router, indexer, ...) | converted to FP16 and run on the FP16 tensor cores (#655, #540; `STRATA_BF16_TC=0`: cuBLAS BF16, an FP32 SIMT kernel on Volta) |
|
||||
| QSA attention for decode and verify windows (and prompts with `STRATA_PROMPT_ATTN_OLD=1`) | #540's kernel (fewer shuffles, bit-exact; `STRATA_ATTN_PRE75=0`: the one other cards run) |
|
||||
@@ -89,3 +89,16 @@ kernels' output, GPU work per verify window 22.8 -> 21.2 ms on a V100-SXM2 in th
|
||||
sm_70 only when `STRATA_SM70_TABLE=1` is set. They become the default once the contributor has confirmed them on a V100 with
|
||||
the 0.1.41 code. Without the variable sm_70 runs what 0.1.40.3 ran. The single switches (`STRATA_EXP_MODE`, `STRATA_MMVQ_IL`,
|
||||
`STRATA_GR_FAST`) still apply on top.
|
||||
|
||||
## More opt-in switches (CUDA 12 experimental build)
|
||||
|
||||
None of these is on by default. Each was measured by its contributor on a V100, not by the maintainers.
|
||||
|
||||
| Switch | What it does | Contributor's number |
|
||||
| --- | --- | --- |
|
||||
| `STRATA_FUSE_DECODE=1` | the decode GEMV / MoE operator fusions of #1097 (gate/up + SwiGLU in one kernel, SwiGLU + quantizer in one kernel, all activation images of a vector in one pass, two BF16 projections in one kernel); bitwise the unfused kernels | 4-16 us per token saved, not visible end to end |
|
||||
| `STRATA_PF_WMMA=1` | the FP16 tensor-core prompt experts (above); also takes IQ4_NL down projections (K=640, #1771) | +10% prompt speed (#1401) |
|
||||
| `STRATA_PF_WMMA2=1` | a second prompt-expert kernel for IQ2_S gate/up and IQ4_NL down (#2356) | +2.5-4.3% prompt speed |
|
||||
| `STRATA_ARGMAX_ROWS_SM70=1` | the multi-block greedy pick on sm_7x (#2357), bitwise the one-block pick | +0.7-0.8% decode |
|
||||
| `STRATA_GR_NORM_FAST=1` | the register-split hyper-connection norm on CUDA (#2358) | +0.5-0.6% decode |
|
||||
| `STRATA_Q8_GATHER_WIDE=0` | turns off the 8-wide int8 KV gather (#1095) that the experimental build uses below compute capability 7.5 | +11% on the gather kernel |
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
// STRATA_FUSE_DECODE=1: the operator fusions of PR #1097 (gate/up GEMV + SwiGLU in one kernel, SwiGLU + intermediate
|
||||
// quantizer in one kernel, every activation image of x in one pass, two BF16 projections in one kernel). They are
|
||||
// compiled only into the experimental build (STRATA_EXPERIMENTAL_SM60, the CUDA 12 engine for Pascal / Volta) and are
|
||||
// bitwise what the unfused sequences produce. Opt-in: unset or 0 keeps the unfused kernels.
|
||||
#include <cstdlib>
|
||||
|
||||
namespace strata::kernels {
|
||||
inline bool fuse_decode() {
|
||||
static const bool on = [] {
|
||||
const char* e = std::getenv("STRATA_FUSE_DECODE");
|
||||
return e != nullptr && e[0] == '1';
|
||||
}();
|
||||
return on;
|
||||
}
|
||||
} // namespace strata::kernels
|
||||
+43
-24
@@ -11,6 +11,7 @@
|
||||
#include "strata/kernels/kv_q4.hpp"
|
||||
#include "strata/kernels/kv_q8.hpp"
|
||||
#include "strata/kernels/quantize_act.hpp"
|
||||
#include "strata/kernels/fuse_decode.hpp"
|
||||
#include "strata/kernels/rope.hpp"
|
||||
#include "strata/kernels/router_top10.hpp"
|
||||
#include "strata/kernels/s2_gemv_q8.hpp"
|
||||
@@ -256,11 +257,14 @@ st_begin(layer, 8, stream);
|
||||
// Plan v0.3 P3: the canonical activation images only when a canonical projection reads them.
|
||||
if (!w_qkv->native_data || !w_gate->native_data) {
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
quantize_act_images(mixed, g.n_embd, b.x_q8_0, b.x_q8k, nullptr, stream); // ONE pass, was two kernels
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
quantize_q8_K(mixed, b.x_q8k, g.n_embd, stream);
|
||||
quantize_q8_0(mixed, b.x_q8_0, g.n_embd, stream);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
st_end(layer, 8, stream);
|
||||
// ---- 2. qkv = wqkv @ x, with the activation THIS layer's `attn_qkv` asks for
|
||||
@@ -315,12 +319,15 @@ st_begin(layer, 12, stream);
|
||||
} else {
|
||||
if (!native_bf16_projections) f32_to_bf16_bulk(mixed, b.x_bf16, g.n_embd, stream);
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
project_bf16_pair(mixed, b.x_bf16, (const uint16_t*) w_alpha->data, b.alpha, g.ssm_v_heads,
|
||||
(const uint16_t*) w_beta->data, b.beta, g.ssm_v_heads, g.n_embd, true, stream);
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
project_bf16(mixed, b.x_bf16, (const uint16_t*) w_alpha->data, b.alpha, g.n_embd, g.ssm_v_heads, true, stream);
|
||||
project_bf16(mixed, b.x_bf16, (const uint16_t*) w_beta->data, b.beta, g.n_embd, g.ssm_v_heads, true, stream);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (!fused_pre) try {
|
||||
if (native_gdn_enabled()) {
|
||||
@@ -360,11 +367,14 @@ st_end(layer, 14, stream);
|
||||
st_begin(layer, 15, stream);
|
||||
if (!w_out->native_data) {
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
quantize_act_images(b.y, g.ssm_value_dim, b.y_q8_0, b.y_q8k, nullptr, stream); // ONE pass, was two
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
quantize_q8_K(b.y, b.y_q8k, g.ssm_value_dim, stream);
|
||||
quantize_q8_0(b.y, b.y_q8_0, g.ssm_value_dim, stream);
|
||||
#endif
|
||||
}
|
||||
} if (!gemv_quantized(*w_out, p_out, f_out, b.y_q8_0, b.y_q8k, out, g.ssm_value_dim, g.n_embd, v.name("ssm_out.weight"), stream, err, b.y)) return false; st_end(layer, 15, stream); return true;}
|
||||
// ================================ the MoE block ================================
|
||||
uint64_t moe_buffers_bytes(const ModelGeometry& g, int64_t k) { const uint64_t parts[] = { (uint64_t) g.n_embd * 2,
|
||||
@@ -466,12 +476,15 @@ if (w_ginp->kind != WeightKind::Bf16InF32) { err = v.name("ffn_gate_inp_s
|
||||
// one is wanted is a property of the TENSOR and the pack mixes them by layer, so both are produced.
|
||||
if (!w_sgate->native_data || !w_sup->native_data) {
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
quantize_act_images(x, g.n_embd, b.x_q8_0, b.x_q8k, b.x_bf16, stream); // ONE pass, was three kernels
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
f32_to_bf16_bulk(x, b.x_bf16, g.n_embd, stream);
|
||||
quantize_q8_K(x, b.x_q8k, g.n_embd, stream);
|
||||
quantize_q8_0(x, b.x_q8_0, g.n_embd, stream);
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
f32_to_bf16_bulk(x, b.x_bf16, g.n_embd, stream);
|
||||
}
|
||||
@@ -1082,17 +1095,21 @@ struct Req { const char* suf; }; const WeightRef* w_idxk = v.get("indexer.k_p
|
||||
// Reading one as f32 would walk 2x its length inside the arena without faulting.
|
||||
if (w_idxk->kind != WeightKind::Bf16InF32 || w_idxq->kind != WeightKind::Bf16InF32) { err = v.name("indexer.*_proj.weight") + " must be engine form 1 (bf16); they are " + std::to_string((int) w_idxk->kind) + " and " + std::to_string((int) w_idxq->kind); return false; }
|
||||
// ---- 1. the three activation formats, once each
|
||||
if (!w_attnk->native_data || !w_attnv->native_data || !w_attnq->native_data) {
|
||||
bool images_fused = false;
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
quantize_act_images(x, g.n_embd, b.x_q8_0, b.x_q8k,
|
||||
native_bf16_projections ? nullptr : b.x_bf16, stream); // ONE pass, was two or three
|
||||
} else if (!native_bf16_projections) f32_to_bf16_bulk(x, b.x_bf16, g.n_embd, stream);
|
||||
#else
|
||||
if (strata::kernels::fuse_decode() && (!w_attnk->native_data || !w_attnv->native_data || !w_attnq->native_data)) {
|
||||
quantize_act_images(x, g.n_embd, b.x_q8_0, b.x_q8k,
|
||||
native_bf16_projections ? nullptr : b.x_bf16, stream); // ONE pass, was two or three
|
||||
images_fused = true;
|
||||
}
|
||||
#endif
|
||||
if (!images_fused) {
|
||||
if (!w_attnk->native_data || !w_attnv->native_data || !w_attnq->native_data) {
|
||||
quantize_q8_K(x, b.x_q8k, g.n_embd, stream);
|
||||
quantize_q8_0(x, b.x_q8_0, g.n_embd, stream);
|
||||
}
|
||||
if (!native_bf16_projections) f32_to_bf16_bulk(x, b.x_bf16, g.n_embd, stream);
|
||||
#endif
|
||||
}
|
||||
// ---- 2. the step state: ONE H2D carries every per-token count the kernels need. Nothing below passes a
|
||||
// per-token scalar as an argument, which is what keeps this layer capturable.
|
||||
//
|
||||
@@ -1110,15 +1127,19 @@ if (!w_attnk->native_data || !w_attnv->native_data || !w_attnq->native_data) {
|
||||
} else
|
||||
if (cudaMemcpyAsync(st.step, st.host_step, qsa_step_bytes(), cudaMemcpyHostToDevice, (cudaStream_t) stream) != cudaSuccess || cudaMemcpyAsync(st.pos_dev, st.host_pos, (size_t) g.n_head * 4, cudaMemcpyHostToDevice, (cudaStream_t) stream) != cudaSuccess) { err = "qsa_layer: the step-state upload failed"; return false; } }
|
||||
// ---- 3. the indexer's RAW key (and, with the V100 switch, its QUERY in the same kernel; was two launches)
|
||||
bool idx_pair = false;
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
// two BF16 projections of the same x in ONE kernel: the query is needed only at step 7 and nothing in between
|
||||
// touches it, so computing it here changes no order that matters; `idx_raw` is still appended at step 5.
|
||||
project_bf16_pair(x, b.x_bf16, (const uint16_t*) w_idxk->data, b.idx_raw, g.idx_key_dim,
|
||||
(const uint16_t*) w_idxq->data, b.q_idx, g.idx_q_heads * g.idx_key_dim, g.n_embd,
|
||||
false, stream);
|
||||
#else
|
||||
project_bf16(x, b.x_bf16, (const uint16_t*) w_idxk->data, b.idx_raw, g.n_embd, g.idx_key_dim, false, stream);
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
// two BF16 projections of the same x in ONE kernel: the query is needed only at step 7 and nothing in between
|
||||
// touches it, so computing it here changes no order that matters; `idx_raw` is still appended at step 5.
|
||||
project_bf16_pair(x, b.x_bf16, (const uint16_t*) w_idxk->data, b.idx_raw, g.idx_key_dim,
|
||||
(const uint16_t*) w_idxq->data, b.q_idx, g.idx_q_heads * g.idx_key_dim, g.n_embd,
|
||||
false, stream);
|
||||
idx_pair = true;
|
||||
}
|
||||
#endif
|
||||
if (!idx_pair)
|
||||
project_bf16(x, b.x_bf16, (const uint16_t*) w_idxk->data, b.idx_raw, g.n_embd, g.idx_key_dim, false, stream);
|
||||
// ---- 4. K and V, in Q8_K, then norm and rotate K only
|
||||
SForm f_k, f_v, f_o, f_q; if (!sform_of(*w_attnk, f_k, v.name("attn_k.weight"), err)) return false; if (!sform_of(*w_attnv, f_v, v.name("attn_v.weight"), err)) return false; if (!sform_of(*w_attno, f_o, v.name("attn_output.weight"), err)) return false; if (!sform_of(*w_attnq, f_q, v.name("attn_q.weight"), err)) return false; Planes p_k, p_v, p_o, p_q; if (!plane_ptrs(*w_attnk, v.name("attn_k.weight"), p_k, err)) return false; if (!plane_ptrs(*w_attnv, v.name("attn_v.weight"), p_v, err)) return false; if (!plane_ptrs(*w_attno, v.name("attn_output.weight"), p_o, err)) return false; if (!plane_ptrs(*w_attnq, v.name("attn_q.weight"), p_q, err)) return false;
|
||||
// k and v, with the activation THIS layer's tensors ask for. Both are K-quants in every QSA layer of this
|
||||
@@ -1171,10 +1192,8 @@ if (!gemv_quantized(*w_attnq, p_q, f_q, b.x_q8_0, b.x_q8k, b.q_full, g.n_embd, g
|
||||
if (cudaMemcpy2DAsync(b.qcur, (size_t) g.head_dim * 4, b.q_full, (size_t) g.head_dim * 2 * 4, (size_t) g.head_dim * 4, (size_t) g.n_head, cudaMemcpyDeviceToDevice, (cudaStream_t) stream) != cudaSuccess) { err = "qsa_layer: the q/gate split failed"; return false; } if (!normalize_rotate(b.qcur, w_qn, (int) g.n_head, (int) g.head_dim)) return false;
|
||||
// ---- 7. the indexer's query: with the V100 switch it was projected at step 3 (paired with the raw key);
|
||||
// the trunk projects it here. Either way, norm and rotate it now.
|
||||
#if !defined(STRATA_EXPERIMENTAL_SM60)
|
||||
project_bf16(x, b.x_bf16, (const uint16_t*) w_idxq->data, b.q_idx, g.n_embd, g.idx_q_heads * g.idx_key_dim,
|
||||
if (!idx_pair) project_bf16(x, b.x_bf16, (const uint16_t*) w_idxq->data, b.q_idx, g.n_embd, g.idx_q_heads * g.idx_key_dim,
|
||||
false, stream);
|
||||
#endif
|
||||
if (!normalize_rotate(b.q_idx, w_iqn, (int) g.idx_q_heads, (int) g.idx_key_dim)) return false;
|
||||
// ---- 8. score, select, gather, attend. `max_blocks` and `cap` are CAPACITIES from the state, not this
|
||||
// token's counts: a grid or a shared-memory size that follows the sequence length is baked into a captured
|
||||
|
||||
@@ -4256,6 +4256,12 @@ bool w2_on() {
|
||||
bool gemm_iq_f16_grouped(int ty, const void* W, size_t expert_bytes, int n_out, int K, const void* X, int ldx,
|
||||
const int32_t* bounds, int n_experts, int max_rows, float* Y, int ldy, void* stream) {
|
||||
if (n_out % WG_BN != 0 || n_experts <= 0 || max_rows <= 0 || ldy % 4 != 0) return false;
|
||||
{ // the tiles are tensor-core kernels: a pre-Volta card has no body for them (the sm_60 pass compiles them empty)
|
||||
int cur = 0, major = 0;
|
||||
if (cudaGetDevice(&cur) != cudaSuccess || cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, cur) != cudaSuccess ||
|
||||
major < 7)
|
||||
return false;
|
||||
}
|
||||
// STRATA_PF_WMMA2=1 (opt-in): IQ2_S gate/up and IQ4_NL down through gemm_iq_f16_w2_kernel (above)
|
||||
if (w2_on() && n_out % W2_RB == 0 && ldx % 8 == 0 && ldy % 8 == 0 && (uintptr_t) X % 16 == 0 && (uintptr_t) Y % 32 == 0 &&
|
||||
(uintptr_t) W % 4 == 0 && expert_bytes % 4 == 0 && ((ty == 22 && K % 512 == 0) || (ty == 20 && K % 128 == 0))) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "strata/kernels/f16_bits.hpp"
|
||||
|
||||
#include "strata/kernels/quantize_act.hpp"
|
||||
#include "strata/kernels/fuse_decode.hpp"
|
||||
#include "strata/kernels/verify_kernels.hpp"
|
||||
|
||||
#include <cuda_fp16.h>
|
||||
@@ -164,7 +165,6 @@ __global__ void gu_kernel(const uint8_t* __restrict__ blob_base, const int32_t*
|
||||
// `silu(gate) * up` lives in `strata/kernels/swiglu.cuh` (the fused kernels call it in their epilogues);
|
||||
// the standalone pass it replaced is gone. The scratch layout is unchanged: `[0, n_pairs)` ends up holding
|
||||
// the products, `[n_pairs, 2*n_pairs)` the raw up rows.
|
||||
#if !defined(STRATA_EXPERIMENTAL_SM60)
|
||||
/// `silu(gate) * up`, in place, over a GATE-MAJOR buffer: `[0, n_pairs)` is every hit's gate and
|
||||
/// `[n_pairs, 2*n_pairs)` is every hit's up, so hit `h`'s row `r` meets itself at `h*FF + r`.
|
||||
///
|
||||
@@ -177,7 +177,6 @@ __global__ void swiglu_kernel(float* __restrict__ gate_up, long long n_pairs) {
|
||||
const float u = gate_up[n_pairs + i];
|
||||
gate_up[i] = (g / (1.0f + __expf(-g))) * u;
|
||||
}
|
||||
#endif
|
||||
|
||||
__global__ void swiglu_quantize_q8_0_scaled_kernel(float* __restrict__ gate_up, long long n_pairs,
|
||||
uint8_t* __restrict__ blocks, float* __restrict__ scales) {
|
||||
@@ -643,17 +642,20 @@ void moe_hit_grouped_s2(const uint8_t* blob_base, const int32_t* slot_index, con
|
||||
{
|
||||
const long long pairs = n_hits * (long long) FF;
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
if (x_scales != nullptr)
|
||||
swilu_quantize_q8_0_scaled(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, h_scales, stream);
|
||||
else
|
||||
swilu_quantize_q8_0(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, stream);
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
const unsigned blocks = (unsigned) ((pairs + THREADS - 1) / THREADS);
|
||||
swiglu_kernel<<<blocks, THREADS, 0, cs>>>(gate_up, pairs);
|
||||
check("moe_hit_grouped_s2/swiglu", stream);
|
||||
if (x_scales != nullptr) quantize_q8_0_scaled(gate_up, h_q8_0, h_scales, n_hits * (int64_t) FF, stream);
|
||||
else quantize_q8_0(gate_up, h_q8_0, n_hits * (int64_t) FF, stream);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// 4. down.
|
||||
{
|
||||
@@ -747,16 +749,19 @@ void moe_hit_grouped_s2_dev(const uint8_t* blob_base, const int32_t* slot_index,
|
||||
{
|
||||
const long long pairs = cap * (long long) FF;
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
if (x_scales != nullptr)
|
||||
swilu_quantize_q8_0_scaled(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, h_scales, stream);
|
||||
else
|
||||
swilu_quantize_q8_0(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, stream);
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
swiglu_kernel<<<(unsigned) ((pairs + THREADS - 1) / THREADS), THREADS, 0, cs>>>(gate_up, pairs);
|
||||
check("moe_hit_grouped_s2_dev/swiglu", stream);
|
||||
if (x_scales != nullptr) quantize_q8_0_scaled(gate_up, h_q8_0, h_scales, cap * (int64_t) FF, stream);
|
||||
else quantize_q8_0(gate_up, h_q8_0, cap * (int64_t) FF, stream);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
{
|
||||
launch_hit_down(fast, blob_base, slot_index, dst_index, blob_bytes, h_q8_0,
|
||||
@@ -791,16 +796,19 @@ void moe_hit_grouped_s2_multi(const uint8_t* blob_base, const int32_t* slot_inde
|
||||
{
|
||||
const long long pairs = cap * (long long) FF;
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
if (x_scales != nullptr)
|
||||
swilu_quantize_q8_0_scaled(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, h_scales, stream);
|
||||
else
|
||||
swilu_quantize_q8_0(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, stream);
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
swiglu_kernel<<<(unsigned) ((pairs + THREADS - 1) / THREADS), THREADS, 0, cs>>>(gate_up, pairs);
|
||||
check("moe_hit_grouped_s2_multi/swiglu", stream);
|
||||
if (x_scales != nullptr) quantize_q8_0_scaled(gate_up, h_q8_0, h_scales, cap * (int64_t) FF, stream);
|
||||
else quantize_q8_0(gate_up, h_q8_0, cap * (int64_t) FF, stream);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
{
|
||||
launch_hit_down(fast, blob_base, slot_index, dst_index, blob_bytes, h_q8_0,
|
||||
@@ -1196,16 +1204,19 @@ void moe_grouped_s2(const unsigned long long* grp_ptr, const int32_t* grp_start,
|
||||
} else {
|
||||
const long long pairs = cap_entries * (long long) FF;
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
if (x_scales != nullptr)
|
||||
swilu_quantize_q8_0_scaled(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, h_scales, stream);
|
||||
else
|
||||
swilu_quantize_q8_0(gate_up, gate_up + pairs, gate_up, pairs, 1, h_q8_0, stream);
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
swiglu_kernel<<<(unsigned) ((pairs + THREADS - 1) / THREADS), THREADS, 0, cs>>>(gate_up, pairs);
|
||||
check("moe_grouped_s2/swiglu", stream);
|
||||
if (x_scales != nullptr) quantize_q8_0_scaled(gate_up, h_q8_0, h_scales, cap_entries * (int64_t) FF, stream);
|
||||
else quantize_q8_0(gate_up, h_q8_0, cap_entries * (int64_t) FF, stream);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
{
|
||||
const dim3 grid((unsigned) (H / D_ROWS), (unsigned) cap_groups);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
// BF16 path affects only the scalar gate: it reads the original F32 input and uses pinned CUDA MMVF plus
|
||||
// an FP32 sigmoid. Native projection overrides independently select CUDA Q8_1 MMVQ and FP32 SwiGLU.
|
||||
#include "strata/kernels/shared_expert.hpp"
|
||||
#include "strata/kernels/fuse_decode.hpp"
|
||||
#include "strata/kernels/bf16_gemv.hpp"
|
||||
#include "strata/kernels/bf16_bits.hpp"
|
||||
#include "strata/kernels/f16_bits.hpp"
|
||||
@@ -331,6 +332,7 @@ void shared_expert(const uint8_t* x_q8_0, const uint8_t* x_q8k, const uint16_t*
|
||||
const unsigned g_embd = (unsigned) ((n_embd + THREADS - 1) / THREADS);
|
||||
|
||||
#if defined(STRATA_EXPERIMENTAL_SM60)
|
||||
if (strata::kernels::fuse_decode()) {
|
||||
// V100 (experimental sm_70 build): gate and up projections, then silu(gate) * up - ONE kernel when both
|
||||
// projections are S-family (`s_gemv_pair_silu`: one read of x, SwiGLU in the epilogue, `up` never
|
||||
// materialised). The pair kernel is bit-exact vs the three-kernel sequence (shared row math, shared
|
||||
@@ -410,7 +412,9 @@ void shared_expert(const uint8_t* x_q8_0, const uint8_t* x_q8k, const uint16_t*
|
||||
} else {
|
||||
gemv(down_form, down_codes, down_scales, down_off, h_q8_0, h_q8k, out, n_ff, n_embd);
|
||||
}
|
||||
#else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
// gate and up projections, then silu(gate) * up in place in `gate`
|
||||
if (native_gate || native_up)
|
||||
native_quantize_q8_1(x_f32, native->q8_1, (int) n_embd, 1, stream);
|
||||
@@ -453,7 +457,7 @@ void shared_expert(const uint8_t* x_q8_0, const uint8_t* x_q8k, const uint16_t*
|
||||
gemv(down_form, down_codes, down_scales, down_off, h_q8_0, h_q8k, out, n_ff, n_embd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// the per-token scalar gate, then the multiply. Note the gate is computed from `x`, the ORIGINAL hidden
|
||||
// state, not from anything the expert produced. The historical branch uses BF16-rounded inputs; the
|
||||
|
||||
+14
-8
@@ -1013,18 +1013,23 @@ struct MmqPlan {
|
||||
// Volta (sm_70): MMQ runs on dp4a there (no int8 tensor cores). pf_wmma(): the layers MMQ would take, and the IQ1_M
|
||||
// ones the FP16 path would, run as one launch per expert group on FP16 tensor-core tiles instead
|
||||
// (strata::kernels::gemm_iq_f16_grouped: each weight superblock dequantized once into shared memory by the FP16 path's
|
||||
// own formulas, FP16 activations, FP32 sums). STRATA_PF_WMMA=0 / 1: off / on on any CUDA card.
|
||||
// own formulas, FP16 activations, FP32 sums). OPT-IN: STRATA_PF_WMMA=1 (the activations are FP16 rather than MMQ's
|
||||
// q8_1, so the answers differ from the default). Only when EVERY visible CUDA card is compute capability 7.0 or
|
||||
// newer: the tiles need tensor cores, and a Volta + Pascal rig (one process, one decision) keeps MMQ.
|
||||
bool pf_wmma() {
|
||||
#if defined(__HIPCC__)
|
||||
return false;
|
||||
#else
|
||||
static const bool on = [] {
|
||||
if (const char* e = std::getenv("STRATA_PF_WMMA")) return e[0] == '1';
|
||||
int dev = 0, major = 0, minor = 0;
|
||||
if (cudaGetDevice(&dev) != cudaSuccess) return false;
|
||||
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
|
||||
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
|
||||
return major == 7 && minor == 0;
|
||||
const char* e = std::getenv("STRATA_PF_WMMA");
|
||||
if (e == nullptr || e[0] != '1') return false;
|
||||
int n = 0;
|
||||
if (cudaGetDeviceCount(&n) != cudaSuccess || n <= 0) return false;
|
||||
for (int d = 0; d < n; ++d) {
|
||||
int major = 0;
|
||||
if (cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, d) != cudaSuccess || major < 7) return false;
|
||||
}
|
||||
return true;
|
||||
}();
|
||||
return on;
|
||||
#endif
|
||||
@@ -3483,7 +3488,8 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
}
|
||||
// pf_wmma: this layer's groups on the FP16 tensor-core tiles (single GPU, native pack, Q2_0 / IQ4_NL down)
|
||||
const bool wmma_l = use_mmq && pf_wmma() && !fused_l && on_peer.empty() && lay.native &&
|
||||
(mmq_dt == 42 || mmq_dt == 20) && strata::kernels::iq_row_bytes(mmq_gt, N) > 0;
|
||||
(mmq_dt == 42 || mmq_dt == 20) && !lay.fmt[(size_t) l].tail_off &&
|
||||
strata::kernels::iq_row_bytes(mmq_gt, N) > 0;
|
||||
if (use_mmq && mmq_plan().wmma_only[(size_t) l] && !wmma_l) {
|
||||
err = "prefill: an IQ1_M layer in the MMQ grouping needs the WMMA tiles, which this chunk cannot take";
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user