Repository navigation
Expand file tree
/
Copy pathdspark_head.h
More file actions
53 lines (46 loc) · 2.79 KB
/
Copy pathdspark_head.h
File metadata and controls
53 lines (46 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "dflash_target.h"
#include "internal.h"
#include <cstdint>
#include <vector>
namespace dflash::common {
bool dspark_markov_correct_greedy_chain(const DraftWeights & dw,
ggml_backend_t backend,
DFlashTarget & target,
const float * local_hidden,
int q_len,
int32_t last_tok,
float confidence_threshold,
std::vector<int32_t> & draft_tok);
// Fused variant: base logits (one lm_head matmul over all candidates) +
// unrolled Markov correction chain + in-graph argmax feeding the next
// step's get_rows, all in ONE graph on the draft backend. No host logits
// round-trip. When confidence_out is non-null and the checkpoint has a
// compatible confidence head, returns one score per candidate from the same
// graph and host synchronization as the token ids. `confidence_hidden`, when
// non-null, has the same padded layout as `local_hidden` and supplies the
// pre-output-norm state expected by the confidence head. Callers without a
// separate state retain the legacy behavior by leaving it null.
bool dspark_markov_correct_greedy_chain_fused(const DraftWeights & dw,
ggml_backend_t backend,
ggml_tensor * lm_head,
const float * local_hidden,
int q_len,
int32_t last_tok,
std::vector<int32_t> & draft_tok,
std::vector<float> * confidence_out = nullptr,
const float * confidence_hidden = nullptr);
// DDTree candidate generation with the Markov correction: base logits for
// all n_tokens positions in ONE lm_head matmul; rows 1..n-1 get the low-rank
// previous-token bias chained along the main (argmax) path; top-K extracted
// on host via extract_draft_topk. Output contract matches
// DFlashTarget::project_hidden_to_topk (row 0 = seed position, uncorrected).
bool dspark_markov_project_topk(const DraftWeights & dw,
ggml_backend_t backend,
ggml_tensor * lm_head,
const float * hidden,
int n_tokens, int K, float temperature,
int32_t last_tok,
std::vector<float> & top_log_probs,
std::vector<int32_t> & top_token_ids);
} // namespace dflash::common