Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embeddings correction #674

Merged
merged 8 commits into from
Apr 19, 2024
Merged

Embeddings correction #674

merged 8 commits into from
Apr 19, 2024

Conversation

zsogitbe
Copy link
Contributor

No description provided.

@zsogitbe
Copy link
Contributor Author

This supports all types of models. Until we do not need more than one sequence or pooling we should use this code.

CMakeLists.txt Outdated Show resolved Hide resolved
var embeddings = NativeApi.llama_get_embeddings_seq(Context.NativeHandle, LLamaSeqId.Zero);
if (embeddings.Length == 0)
return Array.Empty<float>();
var embeddings = NativeApi.llama_get_embeddings(Context.NativeHandle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my own branch for investigating this issue I have rewritten the various get_embeddings methods to return a raw float*, instead of a Span<float> (just exposing the llama.cpp symbol directly, instead of wrapping it). Can I suggest making the same change in your PR?

Since null is a valid value for these functions to return a Span isn't really a suitable wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to float* is a lot of work because you need to change several functions... maybe it is better if you merge this PR and then change it as you like. Pointers are 'unsafe', so I am not sure if that is a good idea, but I trust that you know what you are doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll have a look at that once this one is merged :)

@martindevans
Copy link
Member

Looks good, I'll merge it once the tests pass. Thanks for helping me investigate the embeddings issue and working on this PR.

@martindevans martindevans merged commit 89217f7 into SciSharp:master Apr 19, 2024
2 checks passed
@martindevans
Copy link
Member

Oops, I pushed my followup changes to straight to master into of a PR branch 🤦‍♂️

@zsogitbe here's my followup - hopefully this looks ok to you? 3c76440

@zsogitbe
Copy link
Contributor Author

zsogitbe commented Apr 19, 2024

Oops, I pushed my followup changes to straight to master into of a PR branch 🤦‍♂️

@zsogitbe here's my followup - hopefully this looks ok to you? 3c76440

Maybe double check that if (embeddings == null) is enough. C++ may return an empty list and then it will not be NULL...
if (embeddings == null || embeddings.Length == 0) ...

@martindevans
Copy link
Member

martindevans commented Apr 19, 2024

The C++ side doesn't return a size, just a pointer to the first element. So it's either null or a valid embedding vector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants