-
Notifications
You must be signed in to change notification settings - Fork 383
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
Llava api #563
Merged
Merged
Llava api #563
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fc42471
Add llava_binaries, update all binaries to make the test
SignalRT 6307a2f
Llava API + LlavaTest
SignalRT b1fe9ab
First prototype of Load + Unit Test
SignalRT 042d6d1
Temporary run test con branch LlavaAPI
SignalRT de01e2c
Disable Embed test to review the rest of the test
SignalRT 2f730dc
Restore Embedding test
SignalRT 384fcef
Use BatchThread to eval image embeddings
SignalRT fcf60b4
Rename test file
SignalRT 8418a33
Update action versions
SignalRT 71a1ff5
Test only one method, no release embeddings
SignalRT fd467ad
Revert "Test only one method, no release embeddings"
SignalRT a13b3c1
Correct API call
SignalRT 2d75de3
Only test llava related functionality
SignalRT 0110745
Cuda and Cblast binaries
SignalRT da8b3fa
Restore build policy
SignalRT cc0bcfe
Changes related with code review
SignalRT d04bfc4
Add SafeHandles
SignalRT d87f355
Set overwrite to upload-artifact@v4
SignalRT 5fc2264
Revert to upload-artifact@v3
SignalRT 72fba18
revert to upload-artifact@v3
SignalRT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace LLama.Native; | ||
|
||
/// <summary> | ||
/// LLaVa Image embeddings | ||
/// </summary> | ||
[StructLayout(LayoutKind.Sequential)] | ||
unsafe public struct LLavaImageEmbed | ||
{ | ||
public float* embed; | ||
public int n_image_pos; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using LLama; | ||
|
@@ -15,7 +16,7 @@ public sealed class SafeLlavaModelHandle | |
: SafeLLamaHandleBase | ||
{ | ||
|
||
internal protected SafeLlavaModelHandle(IntPtr handle) | ||
public SafeLlavaModelHandle(IntPtr handle) | ||
: base(handle, true) | ||
{ | ||
} | ||
|
@@ -38,13 +39,29 @@ protected override bool ReleaseHandle() | |
/// <exception cref="RuntimeError"></exception> | ||
public static SafeLlavaModelHandle LoadFromFile(string modelPath, int verbosity ) | ||
{ | ||
SignalRT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var ctxContext = NativeApi.clip_model_load(modelPath, verbosity ); | ||
|
||
// Try to open the model file, this will check: | ||
// - File exists (automatically throws FileNotFoundException) | ||
// - File is readable (explicit check) | ||
// This provides better error messages that llama.cpp, which would throw an access violation exception in both cases. | ||
using (var fs = new FileStream(modelPath, FileMode.Open)) | ||
if (!fs.CanRead) | ||
throw new InvalidOperationException($"Llava MMP Model file '{modelPath}' is not readable"); | ||
|
||
var ctxContext = NativeApi.clip_model_load(modelPath, verbosity ); | ||
|
||
if (ctxContext == IntPtr.Zero) | ||
throw new RuntimeError($"Failed to load LLaVa model {modelPath}."); | ||
|
||
return new SafeLlavaModelHandle(ctxContext); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can modify |
||
|
||
} | ||
|
||
/// <summary> | ||
/// Load and embed image | ||
/// </summary> | ||
/// <param name="imagePath">Image path on jpeg format</param> | ||
/// <param name="threads"></param> | ||
public void LoadImage( string imagePath, int threads ) | ||
SignalRT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
unsafe | ||
|
@@ -75,7 +92,7 @@ public bool EmbedImage(LLamaContext ctxLlama, string image, ref int n_past) | |
/// Embed the image from binary in llama context | ||
/// </summary> | ||
/// <param name="ctxLlama"></param> | ||
/// <param name="image"></param> | ||
/// <param name="image">jpeg image</param> | ||
/// <param name="n_past"></param> | ||
/// <returns></returns> | ||
public bool EmbedImage(LLamaContext ctxLlama, Byte[] image, ref int n_past ) | ||
SignalRT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
SignalRT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Binary file not shown.
SignalRT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Binary file not shown.
SignalRT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Binary file not shown.
SignalRT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a
LLavaImageEmbed
is being allocated in some methods and free in another it should be handled with aSafeHandle
to absolutely ensure it is disposed properly.Sorry I didn't spot this in my last review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless it's extremely short lived, in which case it can be handled with try/finally everywhere it's used. But a
SafeHandle
is probably easier and safer.