Archived
Use F32 draft logits for the DSpark Markov walk
Score the walk on F32 head logits, reject non-I32 anchors in libref, and assert the real proposal path. Near-tie policy vs the reference is still open.
This commit is contained in:
1 parent
445bf8e0d9
commit
9ca20a1fba
14 files changed
+284
-56
No files matched your search
@@ -133,6 +133,7 @@ int ref_gated_quant_fp8 (const RadArgs*, RadStream);
|
||||
int ref_gemm_nt_q_gated (const RadArgs*, RadStream);
|
||||
int ref_dflash_select (const RadArgs*, RadStream);
|
||||
int ref_dflash_markov_greedy(const RadArgs*, RadStream);
|
||||
int ref_dflash_markov_greedy_f32(const RadArgs*, RadStream);
|
||||
int ref_dflash_tree (const RadArgs*, RadStream);
|
||||
int ref_gram_accum (const RadArgs*, RadStream);
|
||||
int ref_rmsnorm_had_quant_i8(const RadArgs*, RadStream);
|
||||
@@ -415,6 +416,7 @@ REF_SHAPE_FN(ref_gated_quant_fp8);
|
||||
REF_SHAPE_FN(ref_gemm_nt_q_gated);
|
||||
REF_SHAPE_FN(ref_dflash_select);
|
||||
REF_SHAPE_FN(ref_dflash_markov_greedy);
|
||||
REF_SHAPE_FN(ref_dflash_markov_greedy_f32);
|
||||
REF_SHAPE_FN(ref_dflash_tree);
|
||||
REF_SHAPE_FN(ref_gram_accum);
|
||||
REF_SHAPE_FN(ref_rmsnorm_had_quant_i8);
|
||||
|
||||
+15
-3
@@ -832,16 +832,18 @@ int ref_dflash_select(const RadArgs* a, RadStream) {
|
||||
* `dflash_select`: no top-K candidate restriction is applied, and the result at one position is
|
||||
* the predecessor for the next. Scratch is a 64-token tile decomposition used by the device row;
|
||||
* the reference writes the same tile winners before selecting the global winner. */
|
||||
int ref_dflash_markov_greedy(const RadArgs* a, RadStream) {
|
||||
static int ref_markov_greedy(const RadArgs* a, uint32_t logits_dtype) {
|
||||
if (a->n_t < 7) return RAD_E_INVAL;
|
||||
const RadTensor *logits = &a->t[0], *anchor = &a->t[1], *pred = &a->t[2];
|
||||
const RadTensor *succ = &a->t[3], *tile_scores = &a->t[4], *tile_tokens = &a->t[5];
|
||||
const RadTensor *out = &a->t[6];
|
||||
if (!logits->data || !anchor->data || !pred->data || !succ->data ||
|
||||
!tile_scores->data || !tile_tokens->data || !out->data) return RAD_E_INVAL;
|
||||
if (logits->dtype != RAD_BF16 || pred->dtype != RAD_BF16 || succ->dtype != RAD_BF16 ||
|
||||
if (logits->dtype != logits_dtype || pred->dtype != RAD_BF16 || succ->dtype != RAD_BF16 ||
|
||||
tile_scores->dtype != RAD_F32 || tile_tokens->dtype != RAD_I32 || out->dtype != RAD_I32)
|
||||
return RAD_E_DTYPE;
|
||||
/* The device requires I32 anchors and reports invalid anchor tensors as shape errors. */
|
||||
if (anchor->dtype != RAD_I32) return RAD_E_SHAPE;
|
||||
|
||||
const int64_t steps = p_int(a, "steps", 0);
|
||||
const int64_t R = p_int(a, "rank", 0);
|
||||
@@ -879,10 +881,12 @@ int ref_dflash_markov_greedy(const RadArgs* a, RadStream) {
|
||||
int64_t best_token = first;
|
||||
const int64_t lb = rowoff(logits, row, V);
|
||||
for (int64_t token = first; token < end; ++token) {
|
||||
float score = ldt(logits, lb + token * ls);
|
||||
const float base = ldt(logits, lb + token * ls);
|
||||
float score = logits_dtype == RAD_F32 ? 0.0f : base;
|
||||
const int64_t sb = rowoff(succ, token, R);
|
||||
for (int64_t r = 0; r < R; ++r)
|
||||
score += previous[(size_t)r] * ldt(succ, sb + r * ss);
|
||||
if (logits_dtype == RAD_F32) score += base;
|
||||
if (score > best || (score == best && token < best_token)) {
|
||||
best = score;
|
||||
best_token = token;
|
||||
@@ -903,6 +907,14 @@ int ref_dflash_markov_greedy(const RadArgs* a, RadStream) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int ref_dflash_markov_greedy(const RadArgs* a, RadStream) {
|
||||
return ref_markov_greedy(a, RAD_BF16);
|
||||
}
|
||||
|
||||
int ref_dflash_markov_greedy_f32(const RadArgs* a, RadStream) {
|
||||
return ref_markov_greedy(a, RAD_F32);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- dflash_tree */
|
||||
/* `cand`, `unary`, `hp`?, `anchor`, `pred`w, `succ`w -> `tokens`, `parents`
|
||||
*
|
||||
|
||||
@@ -1386,6 +1386,8 @@ static const RadOpSchema kSchemas[] = {
|
||||
"The DSpark reference walk: score all vocabulary ids at each position as draft_logit[token] + "
|
||||
"sum_r pred[previous_token][r] * succ[token][r], select the greatest score (lower id breaks "
|
||||
"ties), then use that token as the next predecessor." },
|
||||
{ "dflash_markov_greedy_f32", ARR(pDflashMarkov), ARR(oDflashMarkov),
|
||||
"Full-vocabulary greedy Markov walk with F32 base logits and BF16 codebooks." },
|
||||
{ "dflash_tree", ARR(pDflashTree), ARR(oDflashTree),
|
||||
"dflash_select's lattice and edge scores grown best-first into a tree of `nodes` nodes: node 0 "
|
||||
"is the anchor, each selected node's children are the valid candidates at the next position "
|
||||
@@ -2400,6 +2402,10 @@ SIMPLE("ref_dflash_markov_greedy", "dflash_markov_greedy", "draft",
|
||||
"DSpark's full-vocabulary greedy Markov walk",
|
||||
"bf16 logits and codebooks, f32/i32 tile winners, i32 tokens out",
|
||||
ref_dflash_markov_greedy),
|
||||
SIMPLE("ref_dflash_markov_greedy_f32", "dflash_markov_greedy_f32", "draft",
|
||||
"Full-vocabulary greedy Markov walk with F32 base logits",
|
||||
"f32 logits, bf16 codebooks, f32/i32 tile winners, i32 tokens out",
|
||||
ref_dflash_markov_greedy_f32),
|
||||
SIMPLE("ref_dflash_tree", "dflash_tree", "draft",
|
||||
"DFlash2's candidate lattice grown best-first into a tree",
|
||||
"i32 candidates, bf16 codebooks, i32 tokens and parents out", ref_dflash_tree),
|
||||
|
||||
+11
-3
@@ -2240,7 +2240,8 @@ int ref_dflash_select_shape(const RadParam* p, int n_p, int operand, RadOpdDesc*
|
||||
}
|
||||
|
||||
/* The full-vocabulary DSpark Markov walk. Its tile planes hold one exact local max per 64 ids. */
|
||||
int ref_dflash_markov_greedy_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
static int ref_markov_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out,
|
||||
uint32_t logits_dtype, const char* op) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t steps = gi(p, n_p, "steps", 0);
|
||||
const int64_t R = gi(p, n_p, "rank", 0);
|
||||
@@ -2251,14 +2252,21 @@ int ref_dflash_markov_greedy_shape(const RadParam* p, int n_p, int operand, RadO
|
||||
const int64_t rows = M * steps;
|
||||
const int64_t tiles = (nv + 63) / 64;
|
||||
Opd o;
|
||||
o.t((uint32_t)RAD_BF16, { rows, nv }); /* logits */
|
||||
o.t(logits_dtype, { rows, nv }); /* logits */
|
||||
o.t_idx_dt((uint32_t)RAD_I32, { M * astr }, nv, -1, 0); /* anchor */
|
||||
o.t((uint32_t)RAD_BF16, { nv, R }); /* pred */
|
||||
o.t((uint32_t)RAD_BF16, { nv, R }); /* succ */
|
||||
o.t((uint32_t)RAD_F32, { M, tiles }); /* tile_scores */
|
||||
o.t_idx_dt((uint32_t)RAD_I32, { M, tiles }, nv, -1, 0); /* tile_tokens */
|
||||
o.t_idx_dt((uint32_t)RAD_I32, { M, steps }, nv, -1, 0); /* tokens */
|
||||
return o.finish("dflash_markov_greedy", operand, out);
|
||||
return o.finish(op, operand, out);
|
||||
}
|
||||
|
||||
int ref_dflash_markov_greedy_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
return ref_markov_shape(p, n_p, operand, out, RAD_BF16, "dflash_markov_greedy");
|
||||
}
|
||||
int ref_dflash_markov_greedy_f32_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
return ref_markov_shape(p, n_p, operand, out, RAD_F32, "dflash_markov_greedy_f32");
|
||||
}
|
||||
|
||||
/* dflash_select's operands, then `nodes` tokens and parents a sequence. */
|
||||
|
||||
Reference in new issue
Block a user