// Automatically generated by Interoptopus. #pragma warning disable 0105 using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using EdgeTransformers.FFI; #pragma warning restore 0105 namespace EdgeTransformers.FFI { public static partial class Interop { public const string NativeLib = "edge_transformers"; static Interop() { } /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_env_destroy")] public static extern FFIError onnx_env_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_env_new")] public static extern FFIError onnx_env_new(ref IntPtr context); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_string_batch_destroy")] public static extern FFIError onnx_string_batch_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_string_batch_new")] public static extern FFIError onnx_string_batch_new(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_string_batch_add")] public static extern FFIError onnx_string_batch_add(IntPtr context, string add_string); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_string_batch_get")] public static extern IntPtr onnx_string_batch_get(IntPtr context, uint id); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_string_batch_length")] public static extern uint onnx_string_batch_length(IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_string_batch_clear")] public static extern FFIError onnx_string_batch_clear(IntPtr context); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_destroy")] public static extern FFIError onnx_cond_gen_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_from_pretrained")] public static extern FFIError onnx_cond_gen_from_pretrained(ref IntPtr context, IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_create_from_files")] public static extern FFIError onnx_cond_gen_create_from_files(ref IntPtr context, IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_generate_topk_sampling")] public static extern IntPtr onnx_cond_gen_generate_topk_sampling(IntPtr context, string input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_generate_random_sampling")] public static extern IntPtr onnx_cond_gen_generate_random_sampling(IntPtr context, string input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_generate_argmax")] public static extern IntPtr onnx_cond_gen_generate_argmax(IntPtr context, string input, int max_length); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_generate_topk_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_cond_gen_generate_topk_sampling_batch(IntPtr s, IntPtr input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_generate_random_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_cond_gen_generate_random_sampling_batch(IntPtr s, IntPtr input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_generate_argmax_batch")] public static extern SliceUseAsciiStringPattern onnx_cond_gen_generate_argmax_batch(IntPtr s, IntPtr input, int max_length); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_destroy")] public static extern FFIError onnx_cond_gen_pkvs_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_from_pretrained")] public static extern FFIError onnx_cond_gen_pkvs_from_pretrained(ref IntPtr context, IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_create_from_paths")] public static extern FFIError onnx_cond_gen_pkvs_create_from_paths(ref IntPtr context, IntPtr env, string model, string tokenizer_config, string special_tokens_map, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_generate_topk_sampling")] public static extern IntPtr onnx_cond_gen_pkvs_generate_topk_sampling(IntPtr context, string input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_generate_random_sampling")] public static extern IntPtr onnx_cond_gen_pkvs_generate_random_sampling(IntPtr context, string input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_generate_argmax")] public static extern IntPtr onnx_cond_gen_pkvs_generate_argmax(IntPtr context, string input, int max_length); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_generate_topk_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_cond_gen_pkvs_generate_topk_sampling_batch(IntPtr s, IntPtr input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_generate_random_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_cond_gen_pkvs_generate_random_sampling_batch(IntPtr s, IntPtr input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_cond_gen_pkvs_generate_argmax_batch")] public static extern SliceUseAsciiStringPattern onnx_cond_gen_pkvs_generate_argmax_batch(IntPtr s, IntPtr input, int max_length); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_emb_destroy")] public static extern FFIError onnx_emb_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_emb_from_pretrained")] public static extern FFIError onnx_emb_from_pretrained(ref IntPtr context, IntPtr env, string model_id, PoolingStrategyFFI pooling_strategy, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_emb_create_from_files")] public static extern FFIError onnx_emb_create_from_files(ref IntPtr context, IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, PoolingStrategyFFI pooling_strategy, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_emb_embed")] public static extern EmbeddingFFI onnx_emb_embed(IntPtr s, string input); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_emb_embed_batch")] public static extern SliceEmbeddingFFI onnx_emb_embed_batch(IntPtr s, IntPtr input); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_token_classification_destroy")] public static extern FFIError onnx_token_classification_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_token_classification_from_pretrained")] public static extern FFIError onnx_token_classification_from_pretrained(ref IntPtr context, IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_token_classification_create_from_files")] public static extern FFIError onnx_token_classification_create_from_files(ref IntPtr context, IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_token_classification_tag")] public static extern TaggedStringFFI onnx_token_classification_tag(IntPtr s, string input); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_token_classification_tag_batch")] public static extern SliceTaggedStringFFI onnx_token_classification_tag_batch(IntPtr s, IntPtr input); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_classification_destroy")] public static extern FFIError onnx_classification_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_classification_from_pretrained")] public static extern FFIError onnx_classification_from_pretrained(ref IntPtr context, IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_classification_create_from_files")] public static extern FFIError onnx_classification_create_from_files(ref IntPtr context, IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_classification_classify")] public static extern PredictionFFI onnx_classification_classify(IntPtr s, string input); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_classification_classify_batch")] public static extern SlicePredictionFFI onnx_classification_classify_batch(IntPtr s, IntPtr input); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_destroy")] public static extern FFIError onnx_optimum_seq2seq_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_from_pretrained")] public static extern FFIError onnx_optimum_seq2seq_from_pretrained(ref IntPtr context, IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_create_from_files")] public static extern FFIError onnx_optimum_seq2seq_create_from_files(ref IntPtr context, IntPtr env, string encoder_model_path, string decoder_model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_generate_topk_sampling")] public static extern IntPtr onnx_optimum_seq2seq_generate_topk_sampling(IntPtr context, string input, string decoder_input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_generate_random_sampling")] public static extern IntPtr onnx_optimum_seq2seq_generate_random_sampling(IntPtr context, string input, string decoder_input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_generate_argmax")] public static extern IntPtr onnx_optimum_seq2seq_generate_argmax(IntPtr context, string input, string decoder_input, int max_length); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_generate_topk_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_optimum_seq2seq_generate_topk_sampling_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_generate_random_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_optimum_seq2seq_generate_random_sampling_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_generate_argmax_batch")] public static extern SliceUseAsciiStringPattern onnx_optimum_seq2seq_generate_argmax_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_destroy")] public static extern FFIError onnx_optimum_seq2seq_pkvs_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_from_pretrained")] public static extern FFIError onnx_optimum_seq2seq_pkvs_from_pretrained(ref IntPtr context, IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_create_from_files")] public static extern FFIError onnx_optimum_seq2seq_pkvs_create_from_files(ref IntPtr context, IntPtr env, string encoder_model_path, string decoder_model_path, string decoder_model_pkvs_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization_level); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_generate_topk_sampling")] public static extern IntPtr onnx_optimum_seq2seq_pkvs_generate_topk_sampling(IntPtr context, string input, string decoder_input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_generate_random_sampling")] public static extern IntPtr onnx_optimum_seq2seq_pkvs_generate_random_sampling(IntPtr context, string input, string decoder_input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_generate_argmax")] public static extern IntPtr onnx_optimum_seq2seq_pkvs_generate_argmax(IntPtr context, string input, string decoder_input, int max_length); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_generate_topk_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_optimum_seq2seq_pkvs_generate_topk_sampling_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_generate_random_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_optimum_seq2seq_pkvs_generate_random_sampling_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_optimum_seq2seq_pkvs_generate_argmax_batch")] public static extern SliceUseAsciiStringPattern onnx_optimum_seq2seq_pkvs_generate_argmax_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length); /// Destroys the given instance. /// /// # Safety /// /// The passed parameter MUST have been created with the corresponding init function; /// passing any other value results in undefined behavior. [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_destroy")] public static extern FFIError onnx_seq2seq_destroy(ref IntPtr context); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_from_pretrained")] public static extern FFIError onnx_seq2seq_from_pretrained(ref IntPtr context, IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_create_from_files")] public static extern FFIError onnx_seq2seq_create_from_files(ref IntPtr context, IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_generate_topk_sampling")] public static extern IntPtr onnx_seq2seq_generate_topk_sampling(IntPtr context, string input, string decoder_input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_generate_random_sampling")] public static extern IntPtr onnx_seq2seq_generate_random_sampling(IntPtr context, string input, string decoder_input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_generate_argmax")] public static extern IntPtr onnx_seq2seq_generate_argmax(IntPtr context, string input, string decoder_input, int max_length); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_generate_topk_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_seq2seq_generate_topk_sampling_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length, int topk, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_generate_random_sampling_batch")] public static extern SliceUseAsciiStringPattern onnx_seq2seq_generate_random_sampling_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length, float temperature); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "onnx_seq2seq_generate_argmax_batch")] public static extern SliceUseAsciiStringPattern onnx_seq2seq_generate_argmax_batch(IntPtr s, IntPtr input, OptionStringBatch decoder_input, int max_length); } public enum DeviceFFI { CPU = 0, DML = 1, } public enum GraphOptimizationLevelFFI { Disable = 0, Level1 = 1, Level2 = 2, Level3 = 99, } public enum PoolingStrategyFFI { Mean = 0, Max = 1, First = 2, } [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct ClassPredictionFFI { public string label; public float score; } [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct EmbeddingFFI { public Slicef32 embedding; } [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct PredictionFFI { public ClassPredictionFFI best; public SliceClassPredictionFFI all; } [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct TaggedStringFFI { public string input_string; public SliceTokenClassPredictionFFI tags; } [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct TokenClassPredictionFFI { public ClassPredictionFFI best; public SliceClassPredictionFFI all; public uint start; public uint end; } [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct UseAsciiStringPattern { public string ascii_string; } public enum FFIError { Ok = 0, Null = 100, Panic = 200, Fail = 300, } ///A pointer to an array of data someone else owns which may not be modified. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct SliceClassPredictionFFI { ///Pointer to start of immutable data. IntPtr data; ///Number of elements. ulong len; } public partial struct SliceClassPredictionFFI : IEnumerable { public SliceClassPredictionFFI(GCHandle handle, ulong count) { this.data = handle.AddrOfPinnedObject(); this.len = count; } public SliceClassPredictionFFI(IntPtr handle, ulong count) { this.data = handle; this.len = count; } public ClassPredictionFFI this[int i] { get { if (i >= Count) throw new IndexOutOfRangeException(); var size = Marshal.SizeOf(typeof(ClassPredictionFFI)); var ptr = new IntPtr(data.ToInt64() + i * size); return Marshal.PtrToStructure(ptr); } } public ClassPredictionFFI[] Copied { get { var rval = new ClassPredictionFFI[len]; for (var i = 0; i < (int) len; i++) { rval[i] = this[i]; } return rval; } } public int Count => (int) len; public IEnumerator GetEnumerator() { for (var i = 0; i < (int)len; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } ///A pointer to an array of data someone else owns which may not be modified. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct SliceEmbeddingFFI { ///Pointer to start of immutable data. IntPtr data; ///Number of elements. ulong len; } public partial struct SliceEmbeddingFFI : IEnumerable { public SliceEmbeddingFFI(GCHandle handle, ulong count) { this.data = handle.AddrOfPinnedObject(); this.len = count; } public SliceEmbeddingFFI(IntPtr handle, ulong count) { this.data = handle; this.len = count; } public EmbeddingFFI this[int i] { get { if (i >= Count) throw new IndexOutOfRangeException(); var size = Marshal.SizeOf(typeof(EmbeddingFFI)); var ptr = new IntPtr(data.ToInt64() + i * size); return Marshal.PtrToStructure(ptr); } } public EmbeddingFFI[] Copied { get { var rval = new EmbeddingFFI[len]; for (var i = 0; i < (int) len; i++) { rval[i] = this[i]; } return rval; } } public int Count => (int) len; public IEnumerator GetEnumerator() { for (var i = 0; i < (int)len; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } ///A pointer to an array of data someone else owns which may not be modified. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct SlicePredictionFFI { ///Pointer to start of immutable data. IntPtr data; ///Number of elements. ulong len; } public partial struct SlicePredictionFFI : IEnumerable { public SlicePredictionFFI(GCHandle handle, ulong count) { this.data = handle.AddrOfPinnedObject(); this.len = count; } public SlicePredictionFFI(IntPtr handle, ulong count) { this.data = handle; this.len = count; } public PredictionFFI this[int i] { get { if (i >= Count) throw new IndexOutOfRangeException(); var size = Marshal.SizeOf(typeof(PredictionFFI)); var ptr = new IntPtr(data.ToInt64() + i * size); return Marshal.PtrToStructure(ptr); } } public PredictionFFI[] Copied { get { var rval = new PredictionFFI[len]; for (var i = 0; i < (int) len; i++) { rval[i] = this[i]; } return rval; } } public int Count => (int) len; public IEnumerator GetEnumerator() { for (var i = 0; i < (int)len; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } ///A pointer to an array of data someone else owns which may not be modified. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct SliceTaggedStringFFI { ///Pointer to start of immutable data. IntPtr data; ///Number of elements. ulong len; } public partial struct SliceTaggedStringFFI : IEnumerable { public SliceTaggedStringFFI(GCHandle handle, ulong count) { this.data = handle.AddrOfPinnedObject(); this.len = count; } public SliceTaggedStringFFI(IntPtr handle, ulong count) { this.data = handle; this.len = count; } public TaggedStringFFI this[int i] { get { if (i >= Count) throw new IndexOutOfRangeException(); var size = Marshal.SizeOf(typeof(TaggedStringFFI)); var ptr = new IntPtr(data.ToInt64() + i * size); return Marshal.PtrToStructure(ptr); } } public TaggedStringFFI[] Copied { get { var rval = new TaggedStringFFI[len]; for (var i = 0; i < (int) len; i++) { rval[i] = this[i]; } return rval; } } public int Count => (int) len; public IEnumerator GetEnumerator() { for (var i = 0; i < (int)len; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } ///A pointer to an array of data someone else owns which may not be modified. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct SliceTokenClassPredictionFFI { ///Pointer to start of immutable data. IntPtr data; ///Number of elements. ulong len; } public partial struct SliceTokenClassPredictionFFI : IEnumerable { public SliceTokenClassPredictionFFI(GCHandle handle, ulong count) { this.data = handle.AddrOfPinnedObject(); this.len = count; } public SliceTokenClassPredictionFFI(IntPtr handle, ulong count) { this.data = handle; this.len = count; } public TokenClassPredictionFFI this[int i] { get { if (i >= Count) throw new IndexOutOfRangeException(); var size = Marshal.SizeOf(typeof(TokenClassPredictionFFI)); var ptr = new IntPtr(data.ToInt64() + i * size); return Marshal.PtrToStructure(ptr); } } public TokenClassPredictionFFI[] Copied { get { var rval = new TokenClassPredictionFFI[len]; for (var i = 0; i < (int) len; i++) { rval[i] = this[i]; } return rval; } } public int Count => (int) len; public IEnumerator GetEnumerator() { for (var i = 0; i < (int)len; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } ///A pointer to an array of data someone else owns which may not be modified. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct SliceUseAsciiStringPattern { ///Pointer to start of immutable data. IntPtr data; ///Number of elements. ulong len; } public partial struct SliceUseAsciiStringPattern : IEnumerable { public SliceUseAsciiStringPattern(GCHandle handle, ulong count) { this.data = handle.AddrOfPinnedObject(); this.len = count; } public SliceUseAsciiStringPattern(IntPtr handle, ulong count) { this.data = handle; this.len = count; } public UseAsciiStringPattern this[int i] { get { if (i >= Count) throw new IndexOutOfRangeException(); var size = Marshal.SizeOf(typeof(UseAsciiStringPattern)); var ptr = new IntPtr(data.ToInt64() + i * size); return Marshal.PtrToStructure(ptr); } } public UseAsciiStringPattern[] Copied { get { var rval = new UseAsciiStringPattern[len]; for (var i = 0; i < (int) len; i++) { rval[i] = this[i]; } return rval; } } public int Count => (int) len; public IEnumerator GetEnumerator() { for (var i = 0; i < (int)len; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } ///A pointer to an array of data someone else owns which may not be modified. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct Slicef32 { ///Pointer to start of immutable data. IntPtr data; ///Number of elements. ulong len; } public partial struct Slicef32 : IEnumerable { public Slicef32(GCHandle handle, ulong count) { this.data = handle.AddrOfPinnedObject(); this.len = count; } public Slicef32(IntPtr handle, ulong count) { this.data = handle; this.len = count; } public float this[int i] { get { if (i >= Count) throw new IndexOutOfRangeException(); var size = Marshal.SizeOf(typeof(float)); var ptr = new IntPtr(data.ToInt64() + i * size); return Marshal.PtrToStructure(ptr); } } public float[] Copied { get { var rval = new float[len]; for (var i = 0; i < (int) len; i++) { rval[i] = this[i]; } return rval; } } public int Count => (int) len; public IEnumerator GetEnumerator() { for (var i = 0; i < (int)len; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } ///Option type containing boolean flag and maybe valid data. [Serializable] [StructLayout(LayoutKind.Sequential)] public partial struct OptionStringBatch { ///Element that is maybe valid. IntPtr t; ///Byte where `1` means element `t` is valid. byte is_some; } public partial struct OptionStringBatch { public static OptionStringBatch FromNullable(IntPtr? nullable) { var result = new OptionStringBatch(); if (nullable.HasValue) { result.is_some = 1; result.t = nullable.Value; } return result; } public IntPtr? ToNullable() { return this.is_some == 1 ? this.t : (IntPtr?)null; } } /// Holds text embedding with model specific threshold for cosine similarity. public partial class EnvContainer : IDisposable { private IntPtr _context; private EnvContainer() {} public static EnvContainer New() { var self = new EnvContainer(); var rval = Interop.onnx_env_new(ref self._context); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_env_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public IntPtr Context => _context; } public partial class StringBatch : IDisposable { private IntPtr _context; private StringBatch() {} public static StringBatch New() { var self = new StringBatch(); var rval = Interop.onnx_string_batch_new(ref self._context); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_string_batch_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public void Add(string add_string) { var rval = Interop.onnx_string_batch_add(_context, add_string); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public string Get(uint id) { var s = Interop.onnx_string_batch_get(_context, id); return Marshal.PtrToStringAnsi(s); } public uint Length() { return Interop.onnx_string_batch_length(_context); } public void Clear() { var rval = Interop.onnx_string_batch_clear(_context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public IntPtr Context => _context; } public partial class ConditionalGenerationPipelineFFI : IDisposable { private IntPtr _context; private ConditionalGenerationPipelineFFI() {} public static ConditionalGenerationPipelineFFI FromPretrained(IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new ConditionalGenerationPipelineFFI(); var rval = Interop.onnx_cond_gen_from_pretrained(ref self._context, env, model_id, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static ConditionalGenerationPipelineFFI CreateFromFiles(IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new ConditionalGenerationPipelineFFI(); var rval = Interop.onnx_cond_gen_create_from_files(ref self._context, env, model_path, tokenizer_config_path, special_tokens_map_path, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_cond_gen_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public string GenerateTopkSampling(string input, int max_length, int topk, float temperature) { var s = Interop.onnx_cond_gen_generate_topk_sampling(_context, input, max_length, topk, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateRandomSampling(string input, int max_length, float temperature) { var s = Interop.onnx_cond_gen_generate_random_sampling(_context, input, max_length, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateArgmax(string input, int max_length) { var s = Interop.onnx_cond_gen_generate_argmax(_context, input, max_length); return Marshal.PtrToStringAnsi(s); } public SliceUseAsciiStringPattern GenerateTopkSamplingBatch(IntPtr input, int max_length, int topk, float temperature) { return Interop.onnx_cond_gen_generate_topk_sampling_batch(_context, input, max_length, topk, temperature); } public SliceUseAsciiStringPattern GenerateRandomSamplingBatch(IntPtr input, int max_length, float temperature) { return Interop.onnx_cond_gen_generate_random_sampling_batch(_context, input, max_length, temperature); } public SliceUseAsciiStringPattern GenerateArgmaxBatch(IntPtr input, int max_length) { return Interop.onnx_cond_gen_generate_argmax_batch(_context, input, max_length); } public IntPtr Context => _context; } public partial class ConditionalGenerationPipelineWithPKVsFFI : IDisposable { private IntPtr _context; private ConditionalGenerationPipelineWithPKVsFFI() {} public static ConditionalGenerationPipelineWithPKVsFFI FromPretrained(IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new ConditionalGenerationPipelineWithPKVsFFI(); var rval = Interop.onnx_cond_gen_pkvs_from_pretrained(ref self._context, env, model_id, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static ConditionalGenerationPipelineWithPKVsFFI CreateFromPaths(IntPtr env, string model, string tokenizer_config, string special_tokens_map, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new ConditionalGenerationPipelineWithPKVsFFI(); var rval = Interop.onnx_cond_gen_pkvs_create_from_paths(ref self._context, env, model, tokenizer_config, special_tokens_map, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_cond_gen_pkvs_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public string GenerateTopkSampling(string input, int max_length, int topk, float temperature) { var s = Interop.onnx_cond_gen_pkvs_generate_topk_sampling(_context, input, max_length, topk, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateRandomSampling(string input, int max_length, float temperature) { var s = Interop.onnx_cond_gen_pkvs_generate_random_sampling(_context, input, max_length, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateArgmax(string input, int max_length) { var s = Interop.onnx_cond_gen_pkvs_generate_argmax(_context, input, max_length); return Marshal.PtrToStringAnsi(s); } public SliceUseAsciiStringPattern GenerateTopkSamplingBatch(IntPtr input, int max_length, int topk, float temperature) { return Interop.onnx_cond_gen_pkvs_generate_topk_sampling_batch(_context, input, max_length, topk, temperature); } public SliceUseAsciiStringPattern GenerateRandomSamplingBatch(IntPtr input, int max_length, float temperature) { return Interop.onnx_cond_gen_pkvs_generate_random_sampling_batch(_context, input, max_length, temperature); } public SliceUseAsciiStringPattern GenerateArgmaxBatch(IntPtr input, int max_length) { return Interop.onnx_cond_gen_pkvs_generate_argmax_batch(_context, input, max_length); } public IntPtr Context => _context; } public partial class EmbeddingPipelineFFI : IDisposable { private IntPtr _context; private EmbeddingPipelineFFI() {} public static EmbeddingPipelineFFI FromPretrained(IntPtr env, string model_id, PoolingStrategyFFI pooling_strategy, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new EmbeddingPipelineFFI(); var rval = Interop.onnx_emb_from_pretrained(ref self._context, env, model_id, pooling_strategy, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static EmbeddingPipelineFFI CreateFromFiles(IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, PoolingStrategyFFI pooling_strategy, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new EmbeddingPipelineFFI(); var rval = Interop.onnx_emb_create_from_files(ref self._context, env, model_path, tokenizer_config_path, special_tokens_map_path, pooling_strategy, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_emb_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public EmbeddingFFI Embed(string input) { return Interop.onnx_emb_embed(_context, input); } public SliceEmbeddingFFI EmbedBatch(IntPtr input) { return Interop.onnx_emb_embed_batch(_context, input); } public IntPtr Context => _context; } public partial class TokenClassificationPipelineFFI : IDisposable { private IntPtr _context; private TokenClassificationPipelineFFI() {} public static TokenClassificationPipelineFFI FromPretrained(IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new TokenClassificationPipelineFFI(); var rval = Interop.onnx_token_classification_from_pretrained(ref self._context, env, model_id, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static TokenClassificationPipelineFFI CreateFromFiles(IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new TokenClassificationPipelineFFI(); var rval = Interop.onnx_token_classification_create_from_files(ref self._context, env, model_path, tokenizer_config_path, special_tokens_map_path, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_token_classification_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public TaggedStringFFI Tag(string input) { return Interop.onnx_token_classification_tag(_context, input); } public SliceTaggedStringFFI TagBatch(IntPtr input) { return Interop.onnx_token_classification_tag_batch(_context, input); } public IntPtr Context => _context; } public partial class SequenceClassificationPipelineFFI : IDisposable { private IntPtr _context; private SequenceClassificationPipelineFFI() {} public static SequenceClassificationPipelineFFI FromPretrained(IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new SequenceClassificationPipelineFFI(); var rval = Interop.onnx_classification_from_pretrained(ref self._context, env, model_id, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static SequenceClassificationPipelineFFI CreateFromFiles(IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new SequenceClassificationPipelineFFI(); var rval = Interop.onnx_classification_create_from_files(ref self._context, env, model_path, tokenizer_config_path, special_tokens_map_path, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_classification_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public PredictionFFI Classify(string input) { return Interop.onnx_classification_classify(_context, input); } public SlicePredictionFFI ClassifyBatch(IntPtr input) { return Interop.onnx_classification_classify_batch(_context, input); } public IntPtr Context => _context; } public partial class OptimumSeq2SeqPipelineFFI : IDisposable { private IntPtr _context; private OptimumSeq2SeqPipelineFFI() {} public static OptimumSeq2SeqPipelineFFI FromPretrained(IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new OptimumSeq2SeqPipelineFFI(); var rval = Interop.onnx_optimum_seq2seq_from_pretrained(ref self._context, env, model_id, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static OptimumSeq2SeqPipelineFFI CreateFromFiles(IntPtr env, string encoder_model_path, string decoder_model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new OptimumSeq2SeqPipelineFFI(); var rval = Interop.onnx_optimum_seq2seq_create_from_files(ref self._context, env, encoder_model_path, decoder_model_path, tokenizer_config_path, special_tokens_map_path, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_optimum_seq2seq_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public string GenerateTopkSampling(string input, string decoder_input, int max_length, int topk, float temperature) { var s = Interop.onnx_optimum_seq2seq_generate_topk_sampling(_context, input, decoder_input, max_length, topk, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateRandomSampling(string input, string decoder_input, int max_length, float temperature) { var s = Interop.onnx_optimum_seq2seq_generate_random_sampling(_context, input, decoder_input, max_length, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateArgmax(string input, string decoder_input, int max_length) { var s = Interop.onnx_optimum_seq2seq_generate_argmax(_context, input, decoder_input, max_length); return Marshal.PtrToStringAnsi(s); } public SliceUseAsciiStringPattern GenerateTopkSamplingBatch(IntPtr input, OptionStringBatch decoder_input, int max_length, int topk, float temperature) { return Interop.onnx_optimum_seq2seq_generate_topk_sampling_batch(_context, input, decoder_input, max_length, topk, temperature); } public SliceUseAsciiStringPattern GenerateRandomSamplingBatch(IntPtr input, OptionStringBatch decoder_input, int max_length, float temperature) { return Interop.onnx_optimum_seq2seq_generate_random_sampling_batch(_context, input, decoder_input, max_length, temperature); } public SliceUseAsciiStringPattern GenerateArgmaxBatch(IntPtr input, OptionStringBatch decoder_input, int max_length) { return Interop.onnx_optimum_seq2seq_generate_argmax_batch(_context, input, decoder_input, max_length); } public IntPtr Context => _context; } public partial class OptimumSeq2SeqPipelineWithPKVsFFI : IDisposable { private IntPtr _context; private OptimumSeq2SeqPipelineWithPKVsFFI() {} public static OptimumSeq2SeqPipelineWithPKVsFFI FromPretrained(IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new OptimumSeq2SeqPipelineWithPKVsFFI(); var rval = Interop.onnx_optimum_seq2seq_pkvs_from_pretrained(ref self._context, env, model_id, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static OptimumSeq2SeqPipelineWithPKVsFFI CreateFromFiles(IntPtr env, string encoder_model_path, string decoder_model_path, string decoder_model_pkvs_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization_level) { var self = new OptimumSeq2SeqPipelineWithPKVsFFI(); var rval = Interop.onnx_optimum_seq2seq_pkvs_create_from_files(ref self._context, env, encoder_model_path, decoder_model_path, decoder_model_pkvs_path, tokenizer_config_path, special_tokens_map_path, device, optimization_level); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_optimum_seq2seq_pkvs_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public string GenerateTopkSampling(string input, string decoder_input, int max_length, int topk, float temperature) { var s = Interop.onnx_optimum_seq2seq_pkvs_generate_topk_sampling(_context, input, decoder_input, max_length, topk, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateRandomSampling(string input, string decoder_input, int max_length, float temperature) { var s = Interop.onnx_optimum_seq2seq_pkvs_generate_random_sampling(_context, input, decoder_input, max_length, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateArgmax(string input, string decoder_input, int max_length) { var s = Interop.onnx_optimum_seq2seq_pkvs_generate_argmax(_context, input, decoder_input, max_length); return Marshal.PtrToStringAnsi(s); } public SliceUseAsciiStringPattern GenerateTopkSamplingBatch(IntPtr input, OptionStringBatch decoder_input, int max_length, int topk, float temperature) { return Interop.onnx_optimum_seq2seq_pkvs_generate_topk_sampling_batch(_context, input, decoder_input, max_length, topk, temperature); } public SliceUseAsciiStringPattern GenerateRandomSamplingBatch(IntPtr input, OptionStringBatch decoder_input, int max_length, float temperature) { return Interop.onnx_optimum_seq2seq_pkvs_generate_random_sampling_batch(_context, input, decoder_input, max_length, temperature); } public SliceUseAsciiStringPattern GenerateArgmaxBatch(IntPtr input, OptionStringBatch decoder_input, int max_length) { return Interop.onnx_optimum_seq2seq_pkvs_generate_argmax_batch(_context, input, decoder_input, max_length); } public IntPtr Context => _context; } public partial class Seq2SeqGenerationPipelineFFI : IDisposable { private IntPtr _context; private Seq2SeqGenerationPipelineFFI() {} public static Seq2SeqGenerationPipelineFFI FromPretrained(IntPtr env, string model_id, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new Seq2SeqGenerationPipelineFFI(); var rval = Interop.onnx_seq2seq_from_pretrained(ref self._context, env, model_id, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public static Seq2SeqGenerationPipelineFFI CreateFromFiles(IntPtr env, string model_path, string tokenizer_config_path, string special_tokens_map_path, DeviceFFI device, GraphOptimizationLevelFFI optimization) { var self = new Seq2SeqGenerationPipelineFFI(); var rval = Interop.onnx_seq2seq_create_from_files(ref self._context, env, model_path, tokenizer_config_path, special_tokens_map_path, device, optimization); if (rval != FFIError.Ok) { throw new InteropException(rval); } return self; } public void Dispose() { var rval = Interop.onnx_seq2seq_destroy(ref _context); if (rval != FFIError.Ok) { throw new InteropException(rval); } } public string GenerateTopkSampling(string input, string decoder_input, int max_length, int topk, float temperature) { var s = Interop.onnx_seq2seq_generate_topk_sampling(_context, input, decoder_input, max_length, topk, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateRandomSampling(string input, string decoder_input, int max_length, float temperature) { var s = Interop.onnx_seq2seq_generate_random_sampling(_context, input, decoder_input, max_length, temperature); return Marshal.PtrToStringAnsi(s); } public string GenerateArgmax(string input, string decoder_input, int max_length) { var s = Interop.onnx_seq2seq_generate_argmax(_context, input, decoder_input, max_length); return Marshal.PtrToStringAnsi(s); } public SliceUseAsciiStringPattern GenerateTopkSamplingBatch(IntPtr input, OptionStringBatch decoder_input, int max_length, int topk, float temperature) { return Interop.onnx_seq2seq_generate_topk_sampling_batch(_context, input, decoder_input, max_length, topk, temperature); } public SliceUseAsciiStringPattern GenerateRandomSamplingBatch(IntPtr input, OptionStringBatch decoder_input, int max_length, float temperature) { return Interop.onnx_seq2seq_generate_random_sampling_batch(_context, input, decoder_input, max_length, temperature); } public SliceUseAsciiStringPattern GenerateArgmaxBatch(IntPtr input, OptionStringBatch decoder_input, int max_length) { return Interop.onnx_seq2seq_generate_argmax_batch(_context, input, decoder_input, max_length); } public IntPtr Context => _context; } public class InteropException : Exception { public T Error { get; private set; } public InteropException(T error): base($"Something went wrong: {error}") { Error = error; } } }