|
35 | 35 |
|
36 | 36 |
|
37 | 37 | # Specify the base name of the shared library to load |
38 | | -_libllava_base_name = "llava" |
39 | | -_libllava_override_path = os.environ.get("LLAVA_CPP_LIB") |
40 | | -_libllava_base_path = pathlib.Path(os.path.abspath(os.path.dirname(__file__))) / "lib" if _libllava_override_path is None else pathlib.Path() |
| 38 | +_libmtmd_base_name = "mtmd" |
| 39 | +_libmtmd_override_path = os.environ.get("mtmd_CPP_LIB") |
| 40 | +_libmtmd_base_path = pathlib.Path(os.path.abspath(os.path.dirname(__file__))) / "lib" if _libmtmd_override_path is None else pathlib.Path() |
41 | 41 |
|
42 | 42 | # Load the library |
43 | | -_libllava = load_shared_library(_libllava_base_name, _libllava_base_path) |
| 43 | +_libmtmd = load_shared_library(_libmtmd_base_name, _libmtmd_base_path) |
44 | 44 |
|
45 | | -ctypes_function = ctypes_function_for_shared_library(_libllava) |
| 45 | +ctypes_function = ctypes_function_for_shared_library(_libmtmd) |
46 | 46 |
|
47 | 47 |
|
48 | 48 | ################################################ |
49 | | -# llava.h |
| 49 | +# mtmd.h |
50 | 50 | ################################################ |
51 | 51 |
|
52 | 52 | # struct clip_ctx; |
53 | 53 | clip_ctx_p = NewType("clip_ctx_p", int) |
54 | 54 | clip_ctx_p_ctypes = c_void_p |
55 | 55 |
|
56 | 56 |
|
57 | | -# struct llava_image_embed { |
| 57 | +# struct mtmd_image_embed { |
58 | 58 | # float * embed; |
59 | 59 | # int n_image_pos; |
60 | 60 | # }; |
61 | | -class llava_image_embed(Structure): |
| 61 | +class mtmd_image_embed(Structure): |
62 | 62 | _fields_ = [ |
63 | 63 | ("embed", POINTER(c_float)), |
64 | 64 | ("n_image_pos", c_int), |
65 | 65 | ] |
66 | 66 |
|
67 | 67 |
|
68 | | -# /** sanity check for clip <-> llava embed size match */ |
69 | | -# LLAVA_API bool llava_validate_embed_size(const llama_context * ctx_llama, const clip_ctx * ctx_clip); |
| 68 | +# /** sanity check for clip <-> mtmd embed size match */ |
| 69 | +# mtmd_API bool mtmd_validate_embed_size(const llama_context * ctx_llama, const clip_ctx * ctx_clip); |
70 | 70 | @ctypes_function( |
71 | | - "llava_validate_embed_size", |
| 71 | + "mtmd_validate_embed_size", |
72 | 72 | [llama_cpp.llama_context_p_ctypes, clip_ctx_p_ctypes], |
73 | 73 | c_bool, |
74 | 74 | ) |
75 | | -def llava_validate_embed_size( |
| 75 | +def mtmd_validate_embed_size( |
76 | 76 | ctx_llama: llama_cpp.llama_context_p, ctx_clip: clip_ctx_p, / |
77 | 77 | ) -> bool: |
78 | 78 | ... |
79 | 79 |
|
80 | 80 |
|
81 | 81 | # /** build an image embed from image file bytes */ |
82 | | -# 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); |
| 82 | +# mtmd_API struct mtmd_image_embed * mtmd_image_embed_make_with_bytes(struct clip_ctx * ctx_clip, int n_threads, const unsigned char * image_bytes, int image_bytes_length); |
83 | 83 | @ctypes_function( |
84 | | - "llava_image_embed_make_with_bytes", |
| 84 | + "mtmd_image_embed_make_with_bytes", |
85 | 85 | [clip_ctx_p_ctypes, c_int, POINTER(c_uint8), c_int], |
86 | | - POINTER(llava_image_embed), |
| 86 | + POINTER(mtmd_image_embed), |
87 | 87 | ) |
88 | | -def llava_image_embed_make_with_bytes( |
| 88 | +def mtmd_image_embed_make_with_bytes( |
89 | 89 | ctx_clip: clip_ctx_p, |
90 | 90 | n_threads: Union[c_int, int], |
91 | 91 | image_bytes: CtypesArray[c_uint8], |
92 | 92 | image_bytes_length: Union[c_int, int], |
93 | 93 | /, |
94 | | -) -> "_Pointer[llava_image_embed]": |
| 94 | +) -> "_Pointer[mtmd_image_embed]": |
95 | 95 | ... |
96 | 96 |
|
97 | 97 |
|
98 | 98 | # /** build an image embed from a path to an image filename */ |
99 | | -# LLAVA_API struct llava_image_embed * llava_image_embed_make_with_filename(struct clip_ctx * ctx_clip, int n_threads, const char * image_path); |
| 99 | +# mtmd_API struct mtmd_image_embed * mtmd_image_embed_make_with_filename(struct clip_ctx * ctx_clip, int n_threads, const char * image_path); |
100 | 100 | @ctypes_function( |
101 | | - "llava_image_embed_make_with_filename", |
| 101 | + "mtmd_image_embed_make_with_filename", |
102 | 102 | [clip_ctx_p_ctypes, c_int, c_char_p], |
103 | | - POINTER(llava_image_embed), |
| 103 | + POINTER(mtmd_image_embed), |
104 | 104 | ) |
105 | | -def llava_image_embed_make_with_filename( |
| 105 | +def mtmd_image_embed_make_with_filename( |
106 | 106 | ctx_clip: clip_ctx_p, n_threads: Union[c_int, int], image_path: bytes, / |
107 | | -) -> "_Pointer[llava_image_embed]": |
| 107 | +) -> "_Pointer[mtmd_image_embed]": |
108 | 108 | ... |
109 | 109 |
|
110 | 110 |
|
111 | | -# LLAVA_API void llava_image_embed_free(struct llava_image_embed * embed); |
112 | | -# /** free an embedding made with llava_image_embed_make_* */ |
113 | | -@ctypes_function("llava_image_embed_free", [POINTER(llava_image_embed)], None) |
114 | | -def llava_image_embed_free(embed: "_Pointer[llava_image_embed]", /): |
| 111 | +# mtmd_API void mtmd_image_embed_free(struct mtmd_image_embed * embed); |
| 112 | +# /** free an embedding made with mtmd_image_embed_make_* */ |
| 113 | +@ctypes_function("mtmd_image_embed_free", [POINTER(mtmd_image_embed)], None) |
| 114 | +def mtmd_image_embed_free(embed: "_Pointer[mtmd_image_embed]", /): |
115 | 115 | ... |
116 | 116 |
|
117 | 117 |
|
118 | 118 | # /** 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. */ |
119 | | -# LLAVA_API bool llava_eval_image_embed(struct llama_context * ctx_llama, const struct llava_image_embed * embed, int n_batch, int * n_past); |
| 119 | +# mtmd_API bool mtmd_eval_image_embed(struct llama_context * ctx_llama, const struct mtmd_image_embed * embed, int n_batch, int * n_past); |
120 | 120 | @ctypes_function( |
121 | | - "llava_eval_image_embed", |
| 121 | + "mtmd_eval_image_embed", |
122 | 122 | [ |
123 | 123 | llama_cpp.llama_context_p_ctypes, |
124 | | - POINTER(llava_image_embed), |
| 124 | + POINTER(mtmd_image_embed), |
125 | 125 | c_int, |
126 | 126 | POINTER(c_int), |
127 | 127 | ], |
128 | 128 | c_bool, |
129 | 129 | ) |
130 | | -def llava_eval_image_embed( |
| 130 | +def mtmd_eval_image_embed( |
131 | 131 | ctx_llama: llama_cpp.llama_context_p, |
132 | | - embed: "_Pointer[llava_image_embed]", |
| 132 | + embed: "_Pointer[mtmd_image_embed]", |
133 | 133 | n_batch: Union[c_int, int], |
134 | 134 | n_past: "_Pointer[c_int]", |
135 | 135 | /, |
|
0 commit comments