llava.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * llama.cpp - commit ba1cb19cdd0d92e012e0f6e009e0620f854b6afd - do not edit this file
  3. *
  4. * MIT License
  5. *
  6. * Copyright (c) 2023-2024 The ggml authors
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all
  16. * copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. */
  26. #ifndef LLAVA_H
  27. #define LLAVA_H
  28. #include "ggml.h"
  29. #ifdef LLAMA_SHARED
  30. # if defined(_WIN32) && !defined(__MINGW32__)
  31. # ifdef LLAMA_BUILD
  32. # define LLAVA_API __declspec(dllexport)
  33. # else
  34. # define LLAVA_API __declspec(dllimport)
  35. # endif
  36. # else
  37. # define LLAVA_API __attribute__ ((visibility ("default")))
  38. # endif
  39. #else
  40. # define LLAVA_API
  41. #endif
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. struct clip_ctx;
  46. struct llava_image_embed {
  47. float * embed;
  48. int n_image_pos;
  49. };
  50. /** sanity check for clip <-> llava embed size match */
  51. LLAVA_API bool llava_validate_embed_size(const struct llama_context * ctx_llama, const struct clip_ctx * ctx_clip);
  52. LLAVA_API bool llava_image_embed_make_with_clip_img(struct clip_ctx * ctx_clip, int n_threads, const struct clip_image_u8 * img, float ** image_embd_out, int * n_img_pos_out);
  53. /** build an image embed from image file bytes */
  54. LLAVA_API struct llava_image_embed * llava_image_embed_make_with_bytes(struct clip_ctx * ctx_clip, int n_threads, const unsigned char * image_bytes, int image_bytes_length);
  55. /** build an image embed from a path to an image filename */
  56. LLAVA_API struct llava_image_embed * llava_image_embed_make_with_filename(struct clip_ctx * ctx_clip, int n_threads, const char * image_path);
  57. /** free an embedding made with llava_image_embed_make_* */
  58. LLAVA_API void llava_image_embed_free(struct llava_image_embed * embed);
  59. /** write the image represented by embed into the llama context with batch size n_batch, starting at context pos n_past. on completion, n_past points to the next position in the context after the image embed. */
  60. LLAVA_API bool llava_eval_image_embed(struct llama_context * ctx_llama, const struct llava_image_embed * embed, int n_batch, int * n_past);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif