Merge branch 'main' into f-027-cuda
This commit is contained in:
commit
cb2e1dbb4e
5 files changed
+101
-11
No files matched your search
@@ -8025,7 +8025,12 @@ def dsv41_prefill_chunk_args(cards, ram_gb) -> list:
|
||||
4K prompt 78.7 -> 87.2 tok/s, 8K 108.9 -> 125.1, 32K 155.2 -> 176.9; decode unchanged (16.53 -> 16.59 tok/s), because the
|
||||
chunk buffers take ~5 GB from the GPU expert tier and the RAM store's hit rate rises to compensate. The prompt chunk's
|
||||
summation order changes, not the model: the repo's chunk-size KL check (1024 0.1705 / 2048 0.1692 / 4096 0.1688 / 8192 0.1695)
|
||||
shows no quality move. Only where the shared pool has room; STRATA_DSV41_NO_BIG_CHUNK=1 leaves the engine's own choice."""
|
||||
shows no quality move. Only where the shared pool has room; STRATA_DSV41_NO_BIG_CHUNK=1 leaves the engine's own choice.
|
||||
|
||||
A 16,384-token chunk on the 128 GB box (2026-10-26, engine 0.1.51, the same set, 1-2 runs a point): 8K 119.8 -> 119.4 (nothing,
|
||||
the set is read once a chunk either way), 16K 152.2 -> 158.6 (+4.2%), 32K 174.0 -> 179.7 (+3.3%), decode 17.21 -> 17.27
|
||||
(2+2 interleaved, unchanged) although the bigger chunk moves ~30% more experts to the CPU lane. So a pool that holds this
|
||||
box's 128 GB takes 16,384; a smaller unified PC keeps 8,192 (not measured below this box)."""
|
||||
if not cards or not any(c.get("uma") for c in cards):
|
||||
return []
|
||||
pool = float(ram_gb or 0) + max([float(c.get('dedicated_gb') or 0.0) for c in cards] or [0.0])
|
||||
@@ -8033,7 +8038,7 @@ def dsv41_prefill_chunk_args(cards, ram_gb) -> list:
|
||||
return []
|
||||
if os.environ.get("STRATA_DSV41_NO_BIG_CHUNK") == "1":
|
||||
return []
|
||||
return ["--prefill-chunk", "8192"]
|
||||
return ["--prefill-chunk", "16384" if pool >= 96.0 else "8192"]
|
||||
|
||||
|
||||
def dsv41_config_env(cards) -> dict:
|
||||
|
||||
@@ -1218,7 +1218,34 @@ __global__ void __launch_bounds__(kThreads) markov_kernel(float* __restrict__ lo
|
||||
if (lane == 0) logits[v] += a;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- the markov bias over a head group (markov_share)
|
||||
// the same bias with the head quantised to Q8_0 blocks of 32 (34 B: an F16 d and 32 int8): half the bytes read for the same sums.
|
||||
// A lane's 8 values sit inside one block (8 divides 32), so a lane reads one d and 8 codes; the sums are the same terms, in the
|
||||
// block's own order, with the quantisation's error the only difference.
|
||||
__global__ void __launch_bounds__(kThreads) markov_kernel_q8(float* __restrict__ logits, const uint16_t* __restrict__ E,
|
||||
const uint8_t* __restrict__ Hq, const int* __restrict__ tok,
|
||||
int V, int R) {
|
||||
extern __shared__ float er[];
|
||||
const uint16_t* erow = E + (size_t) (*tok) * R;
|
||||
for (int i = threadIdx.x; i < R; i += blockDim.x) er[i] = bf16f(erow[i]);
|
||||
__syncthreads();
|
||||
const int lane = threadIdx.x & 31;
|
||||
const int v = blockIdx.x * (kThreads / 32) + (threadIdx.x >> 5);
|
||||
if (v >= V) return;
|
||||
const uint8_t* hr = Hq + (size_t) v * (size_t) (R / 32) * 34;
|
||||
float a = 0.0f;
|
||||
for (int c = lane * 8; c < R; c += 32 * 8) {
|
||||
const uint8_t* blk = hr + (size_t) (c >> 5) * 34;
|
||||
const float d = __half2float(*(const __half*) blk);
|
||||
const int8_t* q = (const int8_t*) (blk + 2 + (c & 31));
|
||||
float t = 0.0f;
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 8; ++i) t += (float) q[i] * er[c + i];
|
||||
a += d * t;
|
||||
}
|
||||
a = warp_sum(a);
|
||||
if (lane == 0) logits[v] += a;
|
||||
}
|
||||
|
||||
// a member's rows [v0, v0 + vn) of the bias (markov_kernel's sums, the prev token's E row already on the device, BF16)
|
||||
__global__ void __launch_bounds__(kThreads) markov_share_kernel(float* __restrict__ logits,
|
||||
const uint16_t* __restrict__ H,
|
||||
@@ -2135,6 +2162,9 @@ void iota_rows(int* out, int T, int n, int stride, cudaStream_t s) { iota_rows_k
|
||||
void markov_add(float* logits, const uint16_t* E, const uint16_t* H, const int* tok, int V, int R, cudaStream_t s) {
|
||||
markov_kernel<<<cdiv(V, kThreads / 32), kThreads, (size_t) R * sizeof(float), s>>>(logits, E, H, tok, V, R);
|
||||
}
|
||||
void markov_add_q8(float* logits, const uint16_t* E, const uint8_t* Hq, const int* tok, int V, int R, cudaStream_t s) {
|
||||
markov_kernel_q8<<<cdiv(V, kThreads / 32), kThreads, (size_t) R * sizeof(float), s>>>(logits, E, Hq, tok, V, R);
|
||||
}
|
||||
void markov_share(float* logits, const uint16_t* H, const uint16_t* erow, int vn, int R, cudaStream_t s) {
|
||||
markov_share_kernel<<<cdiv(vn, kThreads / 32), kThreads, (size_t) R * sizeof(float), s>>>(logits, H, erow, vn, R);
|
||||
}
|
||||
|
||||
@@ -261,6 +261,8 @@ void hc_mean(const float* h, int T, int hc, int dim, float* out, long long out_s
|
||||
void iota_rows(int* out, int T, int n, int stride, cudaStream_t s);
|
||||
/// The DSpark markov head: logits[v] += E[*tok] . H[v] for v < V (E BF16 [V][R], H F16 [V][R]).
|
||||
void markov_add(float* logits, const uint16_t* E, const uint16_t* H, const int* tok, int V, int R, cudaStream_t s);
|
||||
/// The same bias with the head quantised to Q8_0 blocks of 32 (34 B a block: F16 d and 32 int8, R a multiple of 32).
|
||||
void markov_add_q8(float* logits, const uint16_t* E, const uint8_t* Hq, const int* tok, int V, int R, cudaStream_t s);
|
||||
/// The markov bias over a head group: a member's rows [v0, v0 + vn) of it added to its share of a logits row (erow:
|
||||
/// the previous token's E row, BF16, on the device) - markov_add's sums; the share's argmax (the greedy sampler's rule)
|
||||
/// into a host-mapped slot {value, index, seq}; every member's slot of the step -> the global argmax into *tok and its
|
||||
|
||||
+55
-6
@@ -885,6 +885,7 @@ struct Model::Impl {
|
||||
x3::Mat d_main_proj;
|
||||
float *d_main_norm = nullptr, *d_norm = nullptr, *d_conf = nullptr;
|
||||
uint16_t *d_mk_embed = nullptr, *d_mk_head = nullptr; // BF16 [vocab][rank], F16 [vocab][rank]
|
||||
uint8_t* d_mk_head_q8 = nullptr; // the markov head as Q8_0 blocks (the same bias, half the bytes a step)
|
||||
// a head group of two or more: the markov steps over its members (each its rows of the bias and an argmax of its
|
||||
// share, the global one through host-mapped slots [step][member] {value, index, seq}) in place of the lead's whole
|
||||
// rows - E host-mapped (each member reads the picked token's row), a draft's seq in mk_seq
|
||||
@@ -1619,14 +1620,59 @@ struct Model::Impl {
|
||||
return upload(d, *t, p, err);
|
||||
}
|
||||
|
||||
// The markov bias's head as Q8_0 blocks of 32 (34 B: F16 d + 32 int8) instead of F16 values: the same bias sums with the
|
||||
// quantisation's error, half the bytes the drafter's five markov steps read (66 MB -> 33 MB) and half the memory. The
|
||||
// pack is untouched: the F32 / F16 / BF16 tensor is quantised as it is loaded.
|
||||
bool mk_head_q8(Dev& d, const std::string& name, uint8_t*& p, std::string& err, size_t* acct) {
|
||||
const Tensor* t = pk.get(name);
|
||||
if (t == nullptr || (t->dtype != "F32" && t->dtype != "F16" && t->dtype != "BF16")) {
|
||||
err = name + ": not an F32 / F16 / BF16 tensor";
|
||||
return false;
|
||||
}
|
||||
const size_t n = t->bytes / (t->dtype == "F32" ? 4 : 2);
|
||||
if (n == 0 || n % 32 != 0) {
|
||||
err = name + ": not a whole number of 32-value blocks";
|
||||
return false;
|
||||
}
|
||||
std::vector<uint8_t> raw(t->bytes);
|
||||
if (!pk.read(*t, raw.data())) {
|
||||
err = name + ": read failed";
|
||||
return false;
|
||||
}
|
||||
std::vector<float> v(n);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (t->dtype == "F32") std::memcpy(&v[i], raw.data() + i * 4, 4);
|
||||
else v[i] = t->dtype == "F16" ? f16_to_f32(((const uint16_t*) raw.data())[i])
|
||||
: bf16_to_f32(((const uint16_t*) raw.data())[i]);
|
||||
}
|
||||
const size_t nb = n / 32;
|
||||
std::vector<uint8_t> q(nb * 34);
|
||||
for (size_t b = 0; b < nb; ++b) {
|
||||
const float* s = v.data() + b * 32;
|
||||
float amax = 0.0f;
|
||||
for (int i = 0; i < 32; ++i) amax = std::max(amax, std::fabs(s[i]));
|
||||
const float dd = amax > 0.0f ? amax / 127.0f : 0.0f;
|
||||
const uint16_t dh = strata::kernels::f16_from_f32(dd);
|
||||
std::memcpy(q.data() + b * 34, &dh, 2);
|
||||
int8_t* o = (int8_t*) (q.data() + b * 34 + 2);
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
const float x = dd > 0.0f ? s[i] / dd : 0.0f;
|
||||
o[i] = (int8_t) std::max(-127.0f, std::min(127.0f, std::round(x)));
|
||||
}
|
||||
}
|
||||
if (!dalloc(d, p, nb * 34, err, acct)) return false;
|
||||
cudaSetDevice(d.id);
|
||||
CK(cudaMemcpy(p, q.data(), nb * 34, cudaMemcpyHostToDevice));
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t mat_bytes(const std::string& pre) const {
|
||||
if (const Tensor* t = pk.get(pre + ".weight")) return align256(t->bytes);
|
||||
size_t b = 0;
|
||||
for (const char* s : {".trellis", ".suh", ".svh"})
|
||||
if (const Tensor* t = pk.get(pre + s)) b += align256(t->bytes);
|
||||
return b;
|
||||
}
|
||||
size_t tensor_bytes(const std::string& name) const {
|
||||
} size_t tensor_bytes(const std::string& name) const {
|
||||
const Tensor* t = pk.get(name);
|
||||
return t ? align256(t->bytes * (t->dtype == "F32" ? 1 : 2)) : 0;
|
||||
}
|
||||
@@ -3790,7 +3836,7 @@ struct Model::Impl {
|
||||
return false;
|
||||
}
|
||||
if (!dalloc(d, d_mk_embed, te->bytes / 2, err, acct) || !upload(d, *te, d_mk_embed, err) ||
|
||||
!f16raw(d, Z + "markov_head.head.weight", d_mk_head, err, acct))
|
||||
!mk_head_q8(d, Z + "markov_head.head.weight", d_mk_head_q8, err, acct))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -6845,7 +6891,7 @@ struct Model::Impl {
|
||||
sp.seed = dq_seed;
|
||||
}
|
||||
for (int i = 0; i < T; ++i) { // the markov bias of the token before, then that position's draft
|
||||
markov_add(hd.logits + (size_t) i * V, d_mk_embed, d_mk_head, d_ints + i, V, R, hd.st);
|
||||
markov_add_q8(hd.logits + (size_t) i * V, d_mk_embed, d_mk_head_q8, d_ints + i, V, R, hd.st);
|
||||
if (drafts_q) {
|
||||
sp.counter = dq_counter + (uint64_t) i;
|
||||
strata::dsv41k::sample_draft(hd.logits + (size_t) i * V, 1, V, sp, d_specq + i, d_ints + i + 1, hd.st);
|
||||
@@ -8518,8 +8564,11 @@ struct Model::Impl {
|
||||
const size_t ld = mi == 0 ? (size_t) V : (size_t) vn;
|
||||
cudaSetDevice(d.id);
|
||||
// (an EXL3 head: as many activations at a time as its split-K partials fit the scratch - 8 for a shared head, 4
|
||||
// for a whole one, each pass reading the whole share; a GGUF's: 4 at a time, as before)
|
||||
const int per = d.head.fmt != 0 ? 4 : std::max(1, x3::mv_cols(d.head));
|
||||
// for a whole one, each pass reading the whole share; a GGUF's: 8, so that every window the engine can build (rows
|
||||
// <= kWin = 8) walks the head once instead of twice - measured on the drafter's fixed T=5: 4.55 -> 2.83 ms, its
|
||||
// round 14.49 -> 13.46; the verify window's head 3.48 -> 2.68 ms, the same logits. DS4_HEAD_PER overrides.)
|
||||
const int per = d.head.fmt != 0 ? (std::getenv("DS4_HEAD_PER") ? std::atoi(std::getenv("DS4_HEAD_PER")) : 8)
|
||||
: std::max(1, x3::mv_cols(d.head));
|
||||
for (int c = 0; c < rows; c += per)
|
||||
if (!mv(d, {job(d.head, xn + (size_t) c * D, out + (size_t) c * ld, std::min(per, rows - c), D, ld)}, err))
|
||||
return false;
|
||||
|
||||
@@ -19,8 +19,12 @@ R9700 = [{"name": "Radeon AI PRO R9700", "vram_gb": 32.0}]
|
||||
|
||||
|
||||
class StrixChunkArgs(unittest.TestCase):
|
||||
def test_a_128_gb_unified_pc_gets_the_big_chunk(self):
|
||||
self.assertEqual(setup.dsv41_prefill_chunk_args(HALO, 63.6), ["--prefill-chunk", "8192"])
|
||||
def test_a_128_gb_unified_pc_gets_the_16k_chunk(self):
|
||||
# (2026-10-26, the same box: 16K prompt 152.2 -> 158.6 tok/s, 32K 174.0 -> 179.7, 8K flat, decode unchanged)
|
||||
self.assertEqual(setup.dsv41_prefill_chunk_args(HALO, 63.6), ["--prefill-chunk", "16384"])
|
||||
|
||||
def test_a_96_gb_pool_is_the_line(self):
|
||||
self.assertEqual(setup.dsv41_prefill_chunk_args(HALO, 31.0), ["--prefill-chunk", "8192"])
|
||||
|
||||
def test_a_64_gb_unified_pc_keeps_the_engines_choice(self):
|
||||
self.assertEqual(setup.dsv41_prefill_chunk_args(SMALL_HALO, 31.6), [])
|
||||
|
||||
Reference in new issue
Block a user