Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

wayruntime

License: BUSL-1.1API surface: Apache-2.0Apache contributions: DCO 1.1

The public API surface is open source under Apache-2.0. The runtime core is source-available under BUSL-1.1 and becomes Apache-2.0 on 2030-08-30. The whole repository is therefore not open source before that date.

A self-contained CPU inference runtime for GGUF language models. One static library, one public header, one CLI. It loads a GGUF file with a hostile-input posture, tokenizes, runs the transformer decode with a per-session KV cache, samples, and streams tokens back — with zero third-party code and zero network code in the tree.

Lineage. wayruntime is extracted from the AI stack of an unreleased, from-scratch operating system, where local inference is a built-in system service rather than an application dependency. This is that engine, matured and ported to Linux and Windows. The OS ships later; this runs today.

Why

  • No dependency surface. The library is 100% first-party C11: no BLAS, no vendored parsers, no HTTP client — the tree contains no network code at all (grep -ri socket src include comes back empty). What you audit is what runs.
  • Determinism as a feature. Parallel matmul is bit-exact: output is identical for any worker-thread count. Batched decode is bit-exact versus serial stepping. Samplers are seeded and replay deterministically. Greedy output is byte-identical between the Linux and Windows builds of the same model.
  • Verified against the reference. Greedy decode agrees with llama.cpp 20/20 on teacher-forced argmax over the same GGUF (Qwen3-0.6B); byte-level tokenization is canonical BPE with the Qwen2-family pretokenizer, scoring 78/78 exact id-sequence matches against llama.cpp's tokenizer on a mixed corpus.
  • Errors, never guesses. Unsupported architectures and tensor dtypes are refused explicitly. Context overflow is an error, not a silent truncation. A requested SIMD level the host cannot bind is an error, never a silent fallback.

What's inside

  • GGUF loader, hardened: header version gate, tensor bounds and overlap validation against the real file size, hostile-input posture throughout (see docs/SECURITY.md)
  • BPE tokenizer with byte-level and SentencePiece modes
  • Transformer decode for llama-family, Qwen3, and Gemma-class (experimental) models: GQA, flash-attention tiling, RoPE, F16 KV cache
  • Quantized weights: F32, F16, BF16, Q4_0, Q8_0, Q4_K, Q5_K, Q6_K compute paths; Q4_1/Q5_0/Q5_1 are refused explicitly rather than mis-executed
  • Runtime SIMD dispatch: scalar, AVX2, AVX-512, NEON — probed at engine creation, switchable at runtime
  • Persistent worker pool with bit-exact parallel matmul
  • Batched decode: up to 16 sessions stepped together, their LM-head projections coalesced into one GEMM, bit-exact versus serial
  • Sampler: greedy, temperature, top-k, top-p, repetition penalty; seeded, deterministic replay
  • Streaming token callback and grammar/token-mask constrained decoding (see examples/grammar_mask.c)
  • Chat-template autodetect: ChatML variants including Qwen3 /no_think handling, Gemma turn markers

Quick start

make && make test# offline gate: gcc, make, python3; zero warnings
make check # + integration suite; needs one small GGUF (docs/TESTING.md)
./build/posix/wayrt verify model.gguf # load, print metadata, unload
./build/posix/wayrt generate --prompt "The capital of France is" model.gguf
./build/posix/wayrt chat model.gguf # interactive, streaming
./build/posix/wayrt bench model.gguf # tokens/s + engine counters

Windows: make WIN=1 cross-compiles build/win/wayrt.exe (mingw-w64). Same commands, same output — greedy generation is byte-identical to the Linux build.

Model weights use a read-only file mapping by default, reducing weight copies and startup memory. If mapping is unavailable the loader falls back to streamed reads automatically. Use the global --no-mmap flag when an environment requires copied weight storage.

Using the library

Everything is behind one header, include/wayruntime/wayruntime.h (Apache-2.0, freestanding, C11): engine → model → session → generate.

#include<stdio.h>#include<wayruntime/wayruntime.h>intmain(intargc, char**argv)
{
(void)argc;
wr_engine*eng; wr_model*mdl; wr_session*ses;
if (wr_engine_create(NULL, &eng) !=WR_OK) return1;
if (wr_model_load(eng, argv[1], NULL, &mdl) !=WR_OK) return1;
if (wr_session_create(mdl, NULL, &ses) !=WR_OK) return1;
wr_generate_paramsp= { .prompt="The capital of France is",
.max_tokens=32, .stop_token=-1 };
wr_generate_resultout;
if (wr_generate(ses, &p, &out) ==WR_OK) { printf("%s\n", out.text); wr_free(out.text); }
wr_session_destroy(ses); wr_model_free(mdl); wr_engine_destroy(eng);
return0;
}
gcc -std=c11 -O2 -Wall -Wextra -Iinclude hello.c build/posix/libwayruntime.a -lpthread -lm
./a.out model.gguf

This example compiles warning-free and runs, exactly as shown, against the built library. Lower-level control (prefill/step loops, raw logits, batched stepping, token masks) is the same header; the wr_generate facade is just the short path.

Passing NULL model parameters (as above) prefers mmap with a safe streamed fallback. To opt out explicitly, zero-initialize wr_model_params, set use_mmap = WR_MMAP_DISABLED, and pass its address to wr_model_load.

Status — what works, what doesn't

Works today, and is covered by layered tests (unit + golden numeric self-tests, an offline integration suite, real-model CLI runs, a differential suite against llama.cpp, and native Windows runs — see docs/TESTING.md for how to run each layer and what it proves):

  • zero-warning C11 build on gcc and mingw-w64 (-Wall -Wextra -Wshadow -Wvla)
  • 57/57 unit checks, including 10 golden numeric self-tests, plus a 77-check integration battery (hostile-GGUF refusals and a concurrent-sessions-vs-sequential gate included)
  • greedy decode verified 20/20 teacher-forced argmax agreement with llama.cpp on the same GGUF (Qwen3-0.6B)
  • tokenization verified against llama.cpp's tokenizer on the same GGUF: 78/78 exact id-sequence matches on a mixed corpus (prose, code, multi-space runs, CJK, contractions, special tokens)
  • byte-identical greedy output, Linux vs Windows
  • no libm dependency in the default build's hot path (first-party polynomial math; make MATH_APPROX=0 selects libm instead)

Not yet (deliberately, v0.1):

  • CPU only — no GPU backends
  • library + CLI only — no server, no streaming HTTP endpoint
  • little-endian hosts only (big-endian is refused at engine creation, not mis-run)
  • gcc / mingw-w64 only: the kernels use GCC vector extensions; MSVC is out of scope by design
  • the byte-level pretokenizer classifies Unicode with compact range tables, not the full Unicode database: scripts outside the tables can split at different boundaries than upstream (bytes are never altered); the SentencePiece mode has no pretokenizer, matching the origin engine it was validated against
  • Gemma-class model support is experimental and not yet real-model-tested
  • default context cap is 4096 tokens (raise per model via wr_model_params.max_context, up to the compiled attention cap)
  • no external security audit — see docs/SECURITY.md

Layout

include/wayruntime/ the public C API — one freestanding header
src/core/ engine, SIMD kernels, quant codecs, GGUF loader,
tokenizer, model graph, sessions, batch, sampler
src/platform/posix,win/ threads, file mapping, CPU feature probes
src/cli/ the wayrt command-line tool
examples/ Apache-2.0 SDK examples (grammar-masked decoding)
test/ unit + golden, integration, real-model suites
docs/ SECURITY.md, TESTING.md

Security

The trust boundary is the GGUF file: it is treated as hostile input until validated. docs/SECURITY.md describes the threat model and how to report vulnerabilities privately — do not open public issues for security reports.

License

This is a mixed-license repository. Embedded SPDX identifiers and REUSE.toml define the exact boundary; the complete explanation is in LICENSING.md.

  • Core (src/: engine, kernels, loader, tokenizer, sessions, sampler, CLI): Business Source License 1.1. Non-production use and the limited production uses in LICENSE are free. Other production use needs a separate commercial license until the fixed Change Date, 2030-08-30.
  • API surface (the public header, the examples, the Makefile, and the repository's test scripts and metadata as mapped in REUSE.toml): Apache-2.0. Code you write against the header is yours under Apache-2.0; the library you link (libwayruntime.a) is built from BUSL sources, so BUSL terms govern binaries that contain the core until the Change Date.

BUSL permits redistribution and restricts production use; it does not promise payment for every form of resale or support. See COMMERCIAL-LICENSING.md for the commercial-production route.

External code contributions are currently accepted only for the Apache-2.0 surface and require DCO 1.1 sign-off. The BUSL core does not accept outside code, and no CLA is currently required. See CONTRIBUTING.md and DCO. What the binaries link against is inventoried in THIRD-PARTY-NOTICES.md.

About

Self-contained C11 CPU inference runtime for GGUF language models, with deterministic decoding, hardened loading, and zero third-party dependencies.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages