@@ -41,24 +41,50 @@ internal struct mtmd_context_params
4141 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_context_params_default" , CallingConvention = CallingConvention . Cdecl ) ]
4242 internal static extern mtmd_context_params mtmd_context_params_default ( ) ;
4343
44+ /// <summary>
45+ /// whether we need to set non-causal mask before llama_decode
46+ /// if chunk is nullptr, we assume the default case where chunk is an image chunk
47+ /// </summary>
48+ /// <param name="ctx"></param>
49+ /// <returns></returns>
4450 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_decode_use_non_causal" , CallingConvention = CallingConvention . Cdecl ) ]
4551 [ return : MarshalAs ( UnmanagedType . I1 ) ]
4652 internal static extern bool mtmd_decode_use_non_causal ( SafeMtmdModelHandle ctx ) ;
4753
54+ /// <summary>
55+ /// whether the current model use M-RoPE for llama_decode
56+ /// </summary>
57+ /// <param name="ctx"></param>
58+ /// <returns></returns>
4859 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_decode_use_mrope" , CallingConvention = CallingConvention . Cdecl ) ]
4960 [ return : MarshalAs ( UnmanagedType . I1 ) ]
5061 internal static extern bool mtmd_decode_use_mrope ( SafeMtmdModelHandle ctx ) ;
5162
63+ /// <summary>
64+ /// whether the current model supports vision input
65+ /// </summary>
66+ /// <param name="ctx"></param>
67+ /// <returns></returns>
5268 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_support_vision" , CallingConvention = CallingConvention . Cdecl ) ]
5369 [ return : MarshalAs ( UnmanagedType . I1 ) ]
5470 internal static extern bool mtmd_support_vision ( SafeMtmdModelHandle ctx ) ;
5571
72+ /// <summary>
73+ /// whether the current model supports audio input
74+ /// </summary>
75+ /// <param name="ctx"></param>
76+ /// <returns></returns>
5677 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_support_audio" , CallingConvention = CallingConvention . Cdecl ) ]
5778 [ return : MarshalAs ( UnmanagedType . I1 ) ]
5879 internal static extern bool mtmd_support_audio ( SafeMtmdModelHandle ctx ) ;
5980
60- [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_get_audio_bitrate" , CallingConvention = CallingConvention . Cdecl ) ]
61- internal static extern int mtmd_get_audio_bitrate ( SafeMtmdModelHandle ctx ) ;
81+ /// <summary>
82+ /// get audio sample rate in Hz, for example 16000 for Whisper
83+ /// </summary>
84+ /// <param name="ctx"></param>
85+ /// <returns></returns>
86+ [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_get_audio_sample_rate" , CallingConvention = CallingConvention . Cdecl ) ]
87+ internal static extern int mtmd_get_audio_sample_rate ( SafeMtmdModelHandle ctx ) ;
6288
6389 // bitmap ------------------------------------------------------------
6490
@@ -153,9 +179,11 @@ internal static unsafe void mtmd_bitmap_set_id(SafeMtmdEmbed bitmap, string? id)
153179 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_image_tokens_get_n_tokens" , CallingConvention = CallingConvention . Cdecl ) ]
154180 internal static extern UIntPtr mtmd_image_tokens_get_n_tokens ( IntPtr image_tokens ) ;
155181
182+ [ Obsolete ( "use mtmd_image_tokens_get_decoder_pos() instead" ) ]
156183 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_image_tokens_get_nx" , CallingConvention = CallingConvention . Cdecl ) ]
157184 internal static extern UIntPtr mtmd_image_tokens_get_nx ( IntPtr image_tokens ) ;
158185
186+ [ Obsolete ( "use mtmd_image_tokens_get_decoder_pos() instead" ) ]
159187 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_image_tokens_get_ny" , CallingConvention = CallingConvention . Cdecl ) ]
160188 internal static extern UIntPtr mtmd_image_tokens_get_ny ( IntPtr image_tokens ) ;
161189
@@ -165,6 +193,28 @@ internal static unsafe void mtmd_bitmap_set_id(SafeMtmdEmbed bitmap, string? id)
165193 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_image_tokens_get_n_pos" , CallingConvention = CallingConvention . Cdecl ) ]
166194 internal static extern int mtmd_image_tokens_get_n_pos ( IntPtr image_tokens ) ;
167195
196+ [ StructLayout ( LayoutKind . Explicit ) ]
197+ internal struct mtmd_decoder_pos
198+ {
199+ [ FieldOffset ( 0 ) ]
200+ uint t ;
201+
202+ [ FieldOffset ( 4 ) ]
203+ uint x ;
204+
205+ [ FieldOffset ( 8 ) ]
206+ uint y ;
207+ } ;
208+
209+ /// <summary>
210+ /// get position for decoder attention, to be used by M-RoPE models
211+ /// </summary>
212+ /// <param name="image_tokens"></param>
213+ /// <param name="i">i is the index of the embedding token, ranging from 0 to mtmd_image_tokens_get_n_tokens() - 1</param>
214+ /// <returns>return relative position (for example, embedding 0 will have position (0, 0, 0); remember to adjust it to the current absolute position)</returns>
215+ [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_image_tokens_get_decoder_pos" , CallingConvention = CallingConvention . Cdecl ) ]
216+ internal static extern mtmd_decoder_pos mtmd_image_tokens_get_decoder_pos ( IntPtr image_tokens , nuint i ) ;
217+
168218 // tokenize ----------------------------------------------------------
169219
170220 /// <summary>
@@ -259,6 +309,11 @@ internal static unsafe IntPtr mtmd_helper_bitmap_init_from_file(SafeMtmdModelHan
259309 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_helper_get_n_pos" , CallingConvention = CallingConvention . Cdecl ) ]
260310 internal static extern int mtmd_helper_get_n_pos ( SafeMtmdInputChunks chunks ) ;
261311
312+ [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_helper_image_get_decoder_pos" , CallingConvention = CallingConvention . Cdecl ) ]
313+ // helper to get the list of relative positions corresponding to the embedding tokens, to be used by M-RoPE
314+ // out_pos must have length == mtmd_helper_get_n_tokens(image)
315+ internal static extern void mtmd_helper_image_get_decoder_pos ( IntPtr /* mtmd_image_tokens* */ image , IntPtr /* mtmd_decoder_pos* */ out_pos ) ;
316+
262317 [ DllImport ( mtmdLibraryName , EntryPoint = "mtmd_helper_eval_chunks" , CallingConvention = CallingConvention . Cdecl ) ]
263318 internal static extern int mtmd_helper_eval_chunks (
264319 SafeMtmdModelHandle ctx ,
0 commit comments