Trivikrama
A tiny chip, a giant model.
Trivikrama runs full-size, pretrained transformer encoders (BERT / ModernBERT family) on microcontrollers by streaming weights from an SD card, one tile at a time. A board with ~50 KB of free RAM can compute a 400M-parameter model, exactly as released, if you are willing to wait.
In the Vamana story, a dwarf asks for three steps of land, then grows into Trivikrama and measures the universe in three strides. The chip is Vamana. The model it runs is Trivikrama.
The three strides
1. convert (PC, Python) Hugging Face checkpoint -> .trv file (int8, per-row scales)
2. stream (MCU, C) .trv on SD card -> one weight tile in RAM at a time
3. infer (MCU, C) tile applied to ALL tokens, so every weight is read once
Why it works in tiny RAM
| Trick | Effect |
|---|---|
| Token-batched weight tiles | Each weight is read from storage once per inference, not once per token |
| Per-token FFN | The wide FFN intermediate never exists in full |
| Per-head attention with online softmax | No T x T score matrix; attention fits in a few KB |
| Sliding-window masks | Matches ModernBERT's local-attention layers natively |
| Pluggable weight source | SD card, SPI flash, a file on a PC, or anything with a read() |
Status
| Part | State |
|---|---|
.trv model format (writer + C reader) |
✅ |
| Int8 tiled streaming linear layer | ✅ verified against NumPy |
| LayerNorm, GELU, RoPE | ✅ verified against NumPy |
| Windowed attention with online softmax | ✅ verified against NumPy |
| ModernBERT encoder forward pass | 🚧 next |
| Laya decision head example | 🚧 |
| Ports: ESP8266, ESP32-S3, RP2040 / RP2350 | 🚧 |
| Resident mode for small distilled models | 🚧 |
Quick start (PC)
pip install -e . # installs the `trivi` CLI
make test # builds the C core with gcc and checks it against NumPy
trivi convert model.safetensors -o model.trv # needs: pip install safetensors
trivi inspect model.trv
The C core is plain C99 with no allocations and no OS dependencies. Develop and test on your laptop; the same code compiles for the microcontroller.
Layout
core/include/trivikrama.h public C API
core/src/trv_kernels.c linear (int8, streamed), layernorm, gelu, rope, attention
core/src/trv_model.c .trv reader over any weight source
core/src/trv_source_file.c stdio weight source (PC builds and tests)
python/trivikrama/ converter, format writer, NumPy reference, `trivi` CLI
tests/ C harness + NumPy comparison
Prior work
Trivikrama builds on ideas from:
- Miao & Lin, Enabling Large Neural Networks on Tiny Microcontrollers with Swapping (out-of-core MCU inference)
- Yang et al., MCUBERT: Memory-Efficient BERT Inference on Commodity Microcontrollers
- Jung et al., Optimizing the Deployment of Tiny Transformers on Low-Power MCUs (pulp-transformer)
- OnnxStream (weight streaming on single-board computers)
- Dao et al., FlashAttention (online softmax)
Author
Created by Vadhyar Sai Charan.
If you use Trivikrama in a project, report, or paper, please credit it. GitHub's
"Cite this repository" button uses CITATION.cff.
License
Apache License 2.0. See LICENSE and NOTICE.
Redistributions must keep the NOTICE file.
Metadata
Release files for trivikrama 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trivikrama-0.1.0.tar.gz | 13.5 kB | Without provenance | Details for trivikrama-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trivikrama-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for trivikrama-0.1.0-py3-none-any.whl |
Total release size: 27.0 kB
Release files / trivikrama-0.1.0.tar.gz
| Download URL | trivikrama-0.1.0.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea3956cc80ace23ee52a6d24f2f892e8a2c182471a4b83e6e2bfacd7a3af757a
|
|
BLAKE2b-256 checksum How to use checksums |
12c6eebbfdfaf5c7f3a07bbc0526ed6a5e12656d3055ea068e6bbd367a12cefe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.4
|
Release files / trivikrama-0.1.0-py3-none-any.whl
| Download URL | trivikrama-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47c8e41f559a393962c6a270584ffe57bc9c2e5b83bb13d6d6949bbb080b17a5
|
|
BLAKE2b-256 checksum How to use checksums |
19d5f8d5620590592e3190967388e985cf153ced356c5f0c990c8a427dbe57fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.4
|
Security for trivikrama 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.