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.

NativeApi.LLava.cs 3.3 kB

1 year ago
1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace LLama.Native;
  4. using clip_ctx = IntPtr;
  5. public static unsafe partial class NativeApi
  6. {
  7. /// <summary>
  8. /// Sanity check for clip &lt;-&gt; llava embed size match
  9. /// </summary>
  10. /// <param name="ctxLlama">LLama Context</param>
  11. /// <param name="ctxClip">Llava Model</param>
  12. /// <returns>True if validate successfully</returns>
  13. [DllImport(llavaLibraryName, EntryPoint = "llava_validate_embed_size", CallingConvention = CallingConvention.Cdecl)]
  14. public static extern bool llava_validate_embed_size( SafeLLamaContextHandle ctxLlama, SafeLlavaModelHandle ctxClip);
  15. /// <summary>
  16. /// Build an image embed from image file bytes
  17. /// </summary>
  18. /// <param name="ctx_clip">SafeHandle to the Clip Model</param>
  19. /// <param name="n_threads">Number of threads</param>
  20. /// <param name="image_bytes">Binary image in jpeg format</param>
  21. /// <param name="image_bytes_length">Bytes length of the image</param>
  22. /// <returns>SafeHandle to the Embeddings</returns>
  23. [DllImport(llavaLibraryName, EntryPoint = "llava_image_embed_make_with_bytes",
  24. CallingConvention = CallingConvention.Cdecl)]
  25. public static extern
  26. SafeLlavaImageEmbedHandle llava_image_embed_make_with_bytes(SafeLlavaModelHandle ctx_clip, int n_threads,
  27. byte[] image_bytes, int image_bytes_length);
  28. /// <summary>
  29. /// Build an image embed from a path to an image filename
  30. /// </summary>
  31. /// <param name="ctx_clip">SafeHandle to the Clip Model</param>
  32. /// <param name="n_threads">Number of threads</param>
  33. /// <param name="image_path">Image filename (jpeg) to generate embeddings</param>
  34. /// <returns>SafeHandle to the embeddings</returns>
  35. [DllImport(llavaLibraryName, EntryPoint = "llava_image_embed_make_with_filename", CallingConvention = CallingConvention.Cdecl)]
  36. public static extern
  37. SafeLlavaImageEmbedHandle llava_image_embed_make_with_filename(SafeLlavaModelHandle ctx_clip, int n_threads,
  38. [MarshalAs(UnmanagedType.LPStr)] string image_path);
  39. /// <summary>
  40. /// Free an embedding made with llava_image_embed_make_*
  41. /// </summary>
  42. /// <param name="embed">Embeddings to release</param>
  43. [DllImport(llavaLibraryName, EntryPoint = "llava_image_embed_free", CallingConvention = CallingConvention.Cdecl)]
  44. public static extern void llava_image_embed_free(IntPtr embed);
  45. /// <summary>
  46. /// Write the image represented by embed into the llama context with batch size n_batch, starting at context
  47. /// pos n_past. on completion, n_past points to the next position in the context after the image embed.
  48. /// </summary>
  49. /// <param name="ctx_llama">Llama Context</param>
  50. /// <param name="embed">Embedding handle</param>
  51. /// <returns>True on success</returns>
  52. [DllImport(llavaLibraryName, EntryPoint = "llava_eval_image_embed", CallingConvention = CallingConvention.Cdecl)]
  53. public static extern bool llava_eval_image_embed(SafeLLamaContextHandle ctx_llama, SafeLlavaImageEmbedHandle embed,
  54. int n_batch, ref int n_past);
  55. }