MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / set_logits

Method set_logits

common/sampling.cpp:130–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128 }
129
130 void set_logits(struct llama_context * ctx, int idx) {
131 const float * sampled_probs = llama_get_sampled_probs_ith (ctx, idx);
132 const float * sampled_logits = llama_get_sampled_logits_ith (ctx, idx);
133 const llama_token * sampled_ids = llama_get_sampled_candidates_ith(ctx, idx);
134
135 const llama_model * model = llama_get_model(ctx);
136 const llama_vocab * vocab = llama_model_get_vocab(model);
137
138 const int n_vocab = llama_vocab_n_tokens(vocab);
139
140 if (sampled_probs) {
141 const uint32_t sampled_probs_count = llama_get_sampled_probs_count_ith(ctx, idx);
142 cur.resize(sampled_probs_count);
143 for (uint32_t i = 0; i < sampled_probs_count; ++i) {
144 cur[i] = llama_token_data{sampled_ids[i], sampled_logits[i], sampled_probs[i]};
145 }
146 } else if (sampled_logits) {
147 const uint32_t sampled_logits_count = llama_get_sampled_logits_count_ith(ctx, idx);
148 cur.resize(sampled_logits_count);
149 for (uint32_t i = 0; i < sampled_logits_count; i++) {
150 cur[i] = llama_token_data{sampled_ids[i], sampled_logits[i], 0.0f};
151 }
152 } else {
153 const auto * logits = llama_get_logits_ith(ctx, idx);
154 GGML_ASSERT(logits != nullptr);
155 cur.resize(n_vocab);
156 for (llama_token token_id = 0; token_id < n_vocab; token_id++) {
157 cur[token_id] = llama_token_data{token_id, logits[token_id], 0.0f};
158 }
159 }
160
161 cur_p = { cur.data(), cur.size(), -1, false };
162 }
163
164 common_time_meas tm() {
165 return common_time_meas(t_total_us, params.no_perf);

Callers 1

common_sampler_sampleFunction · 0.80

Calls 12

llama_get_modelFunction · 0.85
llama_model_get_vocabFunction · 0.85
llama_vocab_n_tokensFunction · 0.85
llama_get_logits_ithFunction · 0.85
resizeMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected