You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LLavaWeightsTests.cs 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using LLama.Common;
  2. using LLama.Native;
  3. namespace LLama.Unittest
  4. {
  5. // Test the same things as llama model + image embedings
  6. //
  7. public sealed class LLavaWeightTests
  8. : IDisposable
  9. {
  10. private readonly LLamaWeights _llamaWeights;
  11. private readonly LLavaWeights _lLavaWeights;
  12. private readonly LLamaContext _context;
  13. public LLavaWeightTests()
  14. {
  15. var @params = new ModelParams(Constants.ModelPath)
  16. {
  17. // Llava models requires big context
  18. ContextSize = 4096
  19. };
  20. _llamaWeights = LLamaWeights.LoadFromFile(@params);
  21. _lLavaWeights = LLavaWeights.LoadFromFile(Constants.LLavaMmpPath);
  22. _context = _llamaWeights.CreateContext(@params);
  23. }
  24. public void Dispose()
  25. {
  26. _llamaWeights.Dispose();
  27. _lLavaWeights.Dispose();
  28. }
  29. [Fact]
  30. public void EmbedImageAsFileName()
  31. {
  32. int n_past = 0;
  33. SafeLlavaImageEmbedHandle emb = _lLavaWeights.CreateImageEmbeddings(_context, Constants.LLavaImage);
  34. Assert.True( _lLavaWeights.EvalImageEmbed( _context, emb, ref n_past ) );
  35. }
  36. [Fact]
  37. public void EmbedImageAsBinary()
  38. {
  39. int n_past = 0;
  40. byte[] image = System.IO.File.ReadAllBytes(Constants.LLavaImage);
  41. SafeLlavaImageEmbedHandle emb = _lLavaWeights.CreateImageEmbeddings(_context, image);
  42. Assert.True( _lLavaWeights.EvalImageEmbed( _context, emb, ref n_past ) );
  43. }
  44. }
  45. }