Skip to content

About

High-performance AI training & inference runtime in pure TokenVector, achieving 2.09x faster training speeds than PyTorch. Engineered with strict Zero-GC memory management, native CUDA acceleration, and an in-process micro-serving engine.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

🚀 TokenVector.Inference: Pure-.tkv Deep Learning Runtime & Training Engine

License: MIT Language: TokenVector .tkv Compiler: tkvc

TokenVector logo

TokenVector.Inference is a deep learning runtime written in TokenVector (.tkv) — inference (graph optimization, quantization, micro-serving) and GPT2-medium / GPT-2 124M training engines benchmarked head-to-head against PyTorch (latest numbers verified 2026-11-28, see below).

Current status, verified 2026-11-28 (Kaggle T4, HEAD 1da48ef):

  • GPT2-medium real weights, 12 updates per side: PyTorch eager 465.2 ms/step, loss 0.1457; TokenVector .tkv 222.4 ms/step (2.09x), loss 0.1693, 0 increasing steps. TKV loss is still 0.0236 nats higher — the TKV <= PyTorch target is NOT met.
  • TKV self-saves weights via fwrite P/Invoke and reloads them for CE / generation: train 0.1275, held-out 8.1774 (baseline 4.0695) → memorization of the repeated batch, not real language learning.
  • Historical GPU full-step (2026-11-20): 40.0 ms/step @seq1024 vs torch 289.1 ms (~7.2x), @seq2048 212.6 vs 599.5 ms (~2.8x). Native CPU EXACT path unchanged. Details: docs/BENCHMARK_GUIDE.md.
  • Sources are .tkv; no C++/torch in the TKV execution path.

docs/internal/HANDOFF.md is the running engineering journal (append-only). Every known gap, and every wrong turn taken to find them, is documented there.

What ships today

Area State
Inference runtime (graph, PTQ INT8/FP8, ONNX reader, batcher) Working, tested; see docs/TEST_REPORT.md
GPT-2 124M training (fwd/bwd/AdamW/clip/checkpoint) Working; see benchmark/BENCHMARKS.md
Native SIMD kernels (GEMM, fused bwd, AdamW) Shipped via compiler repo (tkv_simd_native.dll)
GPU full-step (T4) 7.2x faster than eager torch @seq1024 (40.0 vs 289.1 ms); native CPU path unchanged
GPT2-medium real-weight trainer (16-head, CUDA/cuBLAS + PTX, no C++/torch) 2.09x vs eager torch @12 updates; self-saves weights; see benchmark/README.md

Requirements

  • TokenVector compiler, current self-hosted build (referred to here as $tkvc). The reference build is D:\TokenVector\Release\dist\tkvc-tv.exe.

  • .NET 10 runtime to run the compiled executables. tkvc-tv does not emit a .runtimeconfig.json next to the output — without it you get hostpolicy.dll not found. Create one:

    {"runtimeOptions":{"tfm":"net10.0","framework":{"name":"Microsoft.NETCore.App","version":"10.0.0"}}}

    (or run via dotnet <app>.exe with the file present, cf. benchmark/README.md).

Repository layout

src/            TokenVector sources (engine)
  runtime/     graph runtime, session, arena, SIMD matmul (.tkv)
  training/    autograd, AdamW/clip, GPT-2 124M reference (.tkv)
  tests/       gate suites (fixtures not committed; see below)
  tools/       CLI, trainer demo
tools/         host-side verification: gate_f32.sh (135/135), run_cases.ps1,
               verify_*.ps1 (parity), fixture generators (gen_*.py)
benchmark/     final benchmark: scripts + notebooks + README.md guide
docs/          user-facing docs; docs/internal/ = dev logs
packaging/     NuGet packaging (TokenVector.Inference.nuspec, pack.ps1) — build via packaging/pack.ps1
demo/          2 Kaggle notebooks: benchmark + independent TKV train/test (see benchmark/README.md)
benchmark/README.md  huong dan benchmark (EN/VI)
docs/internal/HANDOFF.md     engineering journal (append-only)

GPT-2 124M parity fixtures (~2.3 GB) are not in git; regenerate with python tools/gen_gpt2_fixture.py (see docs/internal/handoff-gpt2-124m-fixture-design.md).

Quick start

$tkvc = "D:\TokenVector\Release\dist\tkvc-tv.exe"

# Inference quickstart (graph -> session -> one forward pass)
& $tkvc src/examples/quickstart.tkv benchmark/quickstart.exe main
Set-Content benchmark/quickstart.runtimeconfig.json '{"runtimeOptions":{"tfm":"net10.0","framework":{"name":"Microsoft.NETCore.App","version":"10.0.0"}}}'
dotnet benchmark/quickstart.exe      # prints: Y[0] = 2.25  /  quickstart: OK

The API is graph-based; there is no src.inference.load_onnx() and no NDArray. See USER_GUIDE.md for the API walkthrough and docs/TOKENVECTOR_SYNTAX_SPEC.md for the language rules that bite (module-level constants are not importable; record __init__ is skipped; TkvInt …).

Build & test

$tkvc = "D:\TokenVector\Release\dist\tkvc-tv.exe"

# Inference case suites (each case in its own process)
powershell -File tools\run_cases.ps1 -Compiler $tkvc

# f32 kernel gate, 10 suites, 135 assertions
bash tools/gate_f32.sh

# Trainer gate (MLP, AdamW vs PyTorch reference): 15/15 expected
& $tkvc src/tests/trainer_tests.tkv benchmark\trainer_tests.exe main
dotnet benchmark\trainer_tests.exe

Benchmark vs PyTorch

Xem benchmark/README.md de chay lai (Kaggle T4, GPT2-medium, 12 update):

python benchmark/train_real.py <repo>        # PyTorch vs TokenVector
python benchmark/train_tkv_only.py <repo> 2e-4  # chi TKV + tu luu weight
python benchmark/test_trained.py             # test model PyTorch
python benchmark/test_tkv_trained.py         # test weight do TKV luu

Docs map

  • docs/BENCHMARK_GUIDE.md - how to reproduce GPU/CPU benchmarks (Colab T4)
  • docs/DEVELOPMENT_HISTORY.md - repo development history (2026-09 → 2026-11)
  • demo/KAGGLE_TKV_INDEPENDENT_2026-11-28.ipynb - train AI with TKV only + self-saved weights
  • docs/internal/HANDOFF.md — engineering journal, every investigation and wrong turn
  • USER_GUIDE.md / USER_GUIDE_VI.md — API user guide
  • TOKENVECTOR_SYNTAX_SPEC(_VI).md — language syntax rules
  • docs/internal/COMPILER-NOTES-2026-10-16.md — compiler team notes (2026-10-16)
  • docs/numerics-contract.md — fp32 numerics contract (what is/ isn't bit-exact vs PyTorch)
  • docs/internal/COMPILER_TEAM_REQUEST*.md — requests to the compiler team (#1–#14)
  • RELEASE_NOTES(_VI).md — release history
  • docs/internal/ROADMAP_TRAIN.md — training roadmap (campaign complete)

Ecosystem

TokenVector is a next-generation AI/HPC ecosystem built on the .tkv language and tkvc compiler:

About

High-performance AI training & inference runtime in pure TokenVector, achieving 2.09x faster training speeds than PyTorch. Engineered with strict Zero-GC memory management, native CUDA acceleration, and an in-process micro-serving engine.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages