This commit is contained in:
Emreerdog 2025-02-10 09:24:47 +08:00 committed by GitHub
commit d5251da695
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -53,31 +53,40 @@ static void batch_decode(llama_context * ctx, llama_batch & batch, float * outpu
}
}
for (int i = 0; i < batch.n_tokens; i++) {
const float* embd = nullptr;
int embd_pos = 0;
if(pooling_type == LLAMA_POOLING_TYPE_NONE)
{
for (int i = 0; i < batch.n_tokens; i++)
{
if (!batch.logits[i]) {
continue;
}
const float * embd = nullptr;
int embd_pos = 0;
if (pooling_type == LLAMA_POOLING_TYPE_NONE) {
// try to get token embeddings
embd = llama_get_embeddings_ith(ctx, i);
embd_pos = i;
GGML_ASSERT(embd != NULL && "failed to get token embeddings");
} else {
// try to get sequence embeddings - supported only when pooling_type is not NONE
embd = llama_get_embeddings_seq(ctx, batch.seq_id[i][0]);
embd_pos = batch.seq_id[i][0];
GGML_ASSERT(embd != NULL && "failed to get sequence embeddings");
}
float * out = output + embd_pos * n_embd;
common_embd_normalize(embd, out, n_embd, embd_norm);
}
}
else
{
for(int i = 0; i < n_seq; i++)
{
embd = llama_get_embeddings_seq(ctx, i);
embd_pos = i;
GGML_ASSERT(embd != NULL && "failed to get sequence embeddings");
float * out = output + embd_pos * n_embd;
common_embd_normalize(embd, out, n_embd, embd_norm);
}
}
}
int main(int argc, char ** argv) {
common_params params;