Skip to content

Is llama_context.logits a 2d array, and where is it allocated? #9345

Answered by compilade
shakfu asked this question in Q&A
Discussion options

You must be logged in to vote

llama_context.logits is allocated in llama_output_reserve:

lctx.logits = has_logits ? output_base : nullptr;

Is it a 2d array of n_output * n_vocab stored as a single contiguous block or just an array of floats?

Yes, it's just a buffer of floats. Each "output" has n_vocab logits. They are stored contiguously.

Also what is the relationship between llama_batch.logits and llama_context.logits?

llama_batch.logits is a user-facing API which allows choosing which outputs to calculate. It's an array of bool.

llama_context.logits will only contain the logits for the tokens corresponding to each truthy value in llama_batch.logits.…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@shakfu
Comment options

Answer selected by shakfu
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants