Explain how I can modify this repository so that it outputs the logits before and after…
- User
Explain how I can modify this repository so that it outputs the logits before and after each sampling.
Assistant
The provided code doesn't have built-in functionality to print logits before and after each sampling step. You'll need to modify
common/sampling.cppto achieve this. Here's how you can do it:-
Include necessary headers: Ensure you have
<iostream>included insampling.cppfor printing to the console. -
Print logits before sampling: Inside the
common_sampler_samplefunction, after the call togsmpl->set_logits(ctx, idx)and before the firstllama_sampler_applycall (whether grammar_first is true or not), add code to print the logits. Here's an example:
cppllama_token common_sampler_sample(struct common_sampler * gsmpl, struct llama_context * ctx, int idx, bool grammar_first) { gsmpl->set_logits(ctx, idx); std::cout << "Logits before sampling:" << std::endl; for (size_t i = 0; i < gsmpl->cur.size(); ++i) { std::cout << gsmpl->cur[i].id << ": " << gsmpl->cur[i].logit << ", "; } std::cout << std::endl; // ... (rest of the existing code)This loop iterates through the
curvector, which holds thellama_token_dataand prints the token ID and its corresponding logit.- Print logits after sampling: After the
llama_sampler_apply(chain, &cur_p);line and before the assertion, add similar code to print the logits after they've been modified by the sampler:
cppllama_sampler_apply(chain, &cur_p); std::cout << "Logits after sampling:" << std::endl; for (size_t i = 0; i < gsmpl->cur_p.size; ++i) { std::cout << gsmpl->cur_p.data[i].id << ": " << gsmpl->cur_p.data[i].logit << ", "; } std::cout << std::endl; GGML_ASSERT(cur_p.selected != -1 && "no selected token during sampling - check your sampling configuration"); // ... (rest of the existing code)-
- User
Explain how I can extend it to log after each logit, and how to nicely bundle each information to either present it to the user, or to send it via a separate debugging API.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.