MCPcopy Create free account
hub / github.com/cactus-compute/cactus / decode

Method decode

cactus/models/model_needle.cpp:293–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291}
292
293uint32_t NeedleModel::decode(const std::vector<uint32_t>& tokens,
294 float temperature, float top_p, size_t top_k,
295 const std::string& profile_file, float* out_entropy,
296 float /*min_p*/, float /*repetition_penalty*/) {
297 if (temperature < 0) temperature = config_.default_temperature;
298 if (top_p < 0) top_p = config_.default_top_p;
299 if (top_k == 0) top_k = config_.default_top_k;
300
301 auto* gb = static_cast<CactusGraph*>(graph_handle_);
302 gb->soft_reset();
303 reset_graph_side_cache_nodes();
304
305 bool cold_start = kv_cache_.is_empty();
306 std::vector<uint32_t> cold_tokens;
307 const std::vector<uint32_t>* dec_tokens = &tokens;
308 if (!encoder_ready_) {
309 reset_cache(); gb->soft_reset();
310 std::vector<uint32_t> enc(tokens.begin(), tokens.end() - 1);
311 cold_tokens.assign(tokens.end() - 1, tokens.end());
312 run_encoder(enc);
313 encoder_ready_ = true;
314 dec_tokens = &cold_tokens;
315 cold_start = true;
316 }
317
318 size_t logits = cold_start
319 ? run_decoder_step(*dec_tokens, false, false)
320 : run_decoder_step(tokens, true, tokens.size() == 1);
321
322 if (config_.final_logit_softcapping > 0.0f) {
323 float inv = 1.0f / config_.final_logit_softcapping;
324 logits = gb->scalar_multiply(gb->tanh(gb->scalar_multiply(logits, inv)), config_.final_logit_softcapping);
325 }
326
327 auto sampled = sample_token(gb, logits, temperature, top_p, top_k, 0.0f, 1.0f);
328 if (!profile_file.empty()) gb->execute(profile_file); else gb->execute();
329
330 compute_entropy(gb, logits, out_entropy);
331 post_execute_updates(gb, tokens.size());
332 update_kv_cache(gb, dec_tokens->size());
333 return *static_cast<uint32_t*>(gb->get_output(sampled));
334}
335
336} // namespace engine
337} // namespace cactus

Callers

nothing calls this directly

Calls 8

reset_cacheFunction · 0.85
soft_resetMethod · 0.80
sizeMethod · 0.80
scalar_multiplyMethod · 0.80
is_emptyMethod · 0.45
tanhMethod · 0.45
executeMethod · 0.45
get_outputMethod · 0.45

Tested by

no test coverage detected