|
1 | 1 | #include "arg.h" |
2 | 2 | #include "common.h" |
| 3 | +#include "chat.h" |
3 | 4 | #include "sampling.h" |
4 | 5 | #include "speculative.h" |
5 | 6 | #include "log.h" |
6 | 7 | #include "llama.h" |
7 | 8 |
|
8 | 9 | #include <clocale> |
9 | 10 | #include <cstdio> |
| 11 | +#include <cstdlib> |
10 | 12 | #include <cstring> |
11 | 13 | #include <cinttypes> |
12 | 14 | #include <string> |
@@ -102,9 +104,32 @@ int main(int argc, char ** argv) { |
102 | 104 | LOG_INF("speculative decoding will use checkpoints (context does not support partial sequence removal)\n"); |
103 | 105 | } |
104 | 106 |
|
| 107 | + // DFlash drafters are trained on chat-formatted data, so apply the target's chat template |
| 108 | + // (and, with LLAMA_SPEC_NO_THINK set, disable thinking). Without this a raw prompt gives very |
| 109 | + // low acceptance; the blog reports thinking-off raising acceptance from a few % to ~90%. |
| 110 | + std::string prompt = params.prompt; |
| 111 | + if (is_dflash) { |
| 112 | + auto chat_templates = common_chat_templates_init(model_tgt, params.chat_template); |
| 113 | + if (common_chat_templates_was_explicit(chat_templates.get())) { |
| 114 | + common_chat_msg msg; |
| 115 | + msg.role = "user"; |
| 116 | + msg.content = params.prompt; |
| 117 | + |
| 118 | + common_chat_templates_inputs cinputs; |
| 119 | + cinputs.messages = { msg }; |
| 120 | + cinputs.add_generation_prompt = true; |
| 121 | + if (const char * nt = std::getenv("LLAMA_SPEC_NO_THINK"); nt && std::string(nt) != "0") { |
| 122 | + cinputs.enable_thinking = false; // Qwen3 / Qwen3.5 |
| 123 | + cinputs.chat_template_kwargs["reasoning_effort"] = "\"low\""; // gpt-oss |
| 124 | + } |
| 125 | + prompt = common_chat_templates_apply(chat_templates.get(), cinputs).prompt; |
| 126 | + LOG_INF("%s: DFlash chat template applied\n", __func__); |
| 127 | + } |
| 128 | + } |
| 129 | + |
105 | 130 | // Tokenize the prompt |
106 | 131 | std::vector<llama_token> inp; |
107 | | - inp = common_tokenize(ctx_tgt, params.prompt, true, true); |
| 132 | + inp = common_tokenize(ctx_tgt, prompt, true, true); |
108 | 133 |
|
109 | 134 | if (llama_n_ctx(ctx_tgt) < (uint32_t) inp.size()) { |
110 | 135 | LOG_ERR("%s: the prompt exceeds the context size (%d tokens, ctx %d)\n", __func__, (int) inp.size(), llama_n_ctx(ctx_tgt)); |
|
0 commit comments