mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 18:45:00 +00:00
fix: remove trailing 0s from embeddings
This happens when no max_tokens are set, so by default go-llama allocates more space for the slice and padding happens.
This commit is contained in:
parent
b49721cdd1
commit
e62ee2bc06
1 changed files with 13 additions and 1 deletions
|
@ -78,7 +78,19 @@ func ModelEmbedding(s string, loader *model.ModelLoader, c Config) (func() ([]fl
|
||||||
l.Lock()
|
l.Lock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
|
|
||||||
return fn()
|
embeds, err := fn()
|
||||||
|
if err != nil {
|
||||||
|
return embeds, err
|
||||||
|
}
|
||||||
|
// Remove trailing 0s
|
||||||
|
for i := len(embeds) - 1; i >= 0; i-- {
|
||||||
|
if embeds[i] == 0.0 {
|
||||||
|
embeds = embeds[:i]
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return embeds, nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue