Repository navigation
Plain C11 Win32 app running bert-base-NER, MiniLM and distilbart-mnli via the ORT C API (CPU + optional CUDA EP) #33234
aivrar (aivrar)
started this conversation in
Show & Tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I wanted to share a small project that uses the ONNX Runtime C API from plain C11 (no C++), in case it's useful to anyone doing the same on Windows.
It's a Win32 desktop SEO tool that runs three Hugging Face models locally through ORT:
input_ids/attention_mask/token_type_ids; argmax over the per-tokenlogits, then##subwords are merged back into entities.last_hidden_state(it falls back tooutput_0for exports that name the output differently).vocab.json+merges.txt); softmax over the 3logits, reading entailment from index 2 (BART-MNLI order: contradiction, neutral, entailment).A few things that worked well:
OrtEnv+OrtSessionOptions(ORT_ENABLE_ALL, 4 intra-op threads) shared by all sessions, with inputs passed viaCreateTensorWithDataAsOrtValueover caller-ownedint64_tbuffers, so there's no extra copying.GetProcAddress(GetModuleHandleA("onnxruntime.dll"), "OrtSessionOptionsAppendExecutionProvider_CUDA")and falls back to CPU if the symbol is missing or the call fails. The CPU zip is 6 MB; the GPU zip ships the CUDA provider DLLs.Source (MIT): https://github.com/aivrar/serp-to-prompt-writer. The ORT code is in
src/onnx_nlp.candsrc/nli.c.Disclosure: I'm the author, and it was built with heavy AI coding assistance; I've run and tested it myself. Happy to answer questions about using ORT from C.
All reactions