forked from SciSharp/LLamaSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add llava_binaries, update all binaries to make the test * Llava API + LlavaTest Preliminary * First prototype of Load + Unit Test * Temporary run test con branch LlavaAPI * Disable Embed test to review the rest of the test * Restore Embedding test * Use BatchThread to eval image embeddings Test Threads default value to ensure it doesn´t produce problems. * Rename test file * Update action versions * Test only one method, no release embeddings * Revert "Test only one method, no release embeddings" This reverts commit 264e176. * Correct API call * Only test llava related functionality * Cuda and Cblast binaries * Restore build policy * Changes related with code review * Add SafeHandles * Set overwrite to upload-artifact@v4 * Revert to upload-artifact@v3 * revert to upload-artifact@v3
- Loading branch information
Showing
14 changed files
with
441 additions
and
17 deletions.
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
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
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,53 @@ | ||
using LLama.Common; | ||
using LLama.Native; | ||
|
||
namespace LLama.Unittest | ||
{ | ||
// Test the same things as llama model + image embedings | ||
// | ||
public sealed class LLavaWeightTests | ||
: IDisposable | ||
{ | ||
private readonly LLamaWeights _llamaWeights; | ||
private readonly LLavaWeights _lLavaWeights; | ||
private readonly LLamaContext _context; | ||
|
||
public LLavaWeightTests() | ||
{ | ||
var @params = new ModelParams(Constants.ModelPath) | ||
{ | ||
// Llava models requires big context | ||
ContextSize = 4096 | ||
}; | ||
_llamaWeights = LLamaWeights.LoadFromFile(@params); | ||
_lLavaWeights = LLavaWeights.LoadFromFile(Constants.LLavaMmpPath); | ||
|
||
_context = _llamaWeights.CreateContext(@params); | ||
|
||
} | ||
|
||
public void Dispose() | ||
{ | ||
_llamaWeights.Dispose(); | ||
_lLavaWeights.Dispose(); | ||
} | ||
|
||
|
||
|
||
[Fact] | ||
public void EmbedImageAsFileName() | ||
{ | ||
int n_past = 0; | ||
Assert.True( _lLavaWeights.EmbedImage( _context, Constants.LLavaImage, ref n_past ) ); | ||
} | ||
|
||
[Fact] | ||
public void EmbedImageAsBinary() | ||
{ | ||
int n_past = 0; | ||
byte[] image = System.IO.File.ReadAllBytes(Constants.LLavaImage); | ||
Assert.True( _lLavaWeights.EmbedImage( _context, image, ref n_past ) ); | ||
} | ||
|
||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,51 @@ | ||
|
||
using System; | ||
using LLama.Native; | ||
|
||
namespace LLama; | ||
|
||
public sealed class LLavaWeights : IDisposable | ||
{ | ||
public SafeLlavaModelHandle NativeHandle { get; } | ||
|
||
internal LLavaWeights(SafeLlavaModelHandle weights) | ||
{ | ||
NativeHandle = weights; | ||
} | ||
|
||
public static LLavaWeights LoadFromFile(string mmProject) | ||
{ | ||
var weights = SafeLlavaModelHandle.LoadFromFile(mmProject, 1); | ||
return new LLavaWeights(weights); | ||
} | ||
|
||
/// <summary> | ||
/// Embed the image from file into llama context | ||
/// </summary> | ||
/// <param name="ctxLlama"></param> | ||
/// <param name="Image"></param> | ||
/// <param name="n_past"></param> | ||
/// <returns></returns> | ||
public bool EmbedImage(LLamaContext ctxLlama, string Image, ref int n_past ) | ||
{ | ||
return NativeHandle.EmbedImage(ctxLlama, Image, ref n_past ); | ||
} | ||
|
||
/// <summary> | ||
/// Embed the image from binary into llama context. | ||
/// </summary> | ||
/// <param name="ctxLlama"></param> | ||
/// <param name="Image"></param> | ||
/// <param name="n_past"></param> | ||
/// <returns></returns> | ||
public bool EmbedImage(LLamaContext ctxLlama, Byte[] Image, ref int n_past ) | ||
{ | ||
return NativeHandle.EmbedImage(ctxLlama, Image, ref n_past ); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
NativeHandle.Dispose(); | ||
} | ||
|
||
} |
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; | ||
} |
Oops, something went wrong.