tensomite.cr
tensomite.cr
A small pure-Crystal tensor maths runtime with a minimal native seam to BLAS and the GPU.
Tensomite gives Crystal lazy tensors with automatic gradients, for training models and running them. Its kernels run on the CPU, written in Crystal, through BLAS (Accelerate or OpenBLAS), on Apple GPUs through Metal, or on NVIDIA GPUs through CUDA, and repeat their results exactly from run to run.
It loads GPT-2 and Llama-family models, such as SmolLM2, from Hugging Face's safetensors files (F32, F16 or BF16, with tokenizer.json) and from GGUF files, and reads tiktoken tokenisers converted by a script. Weights can be quantised to Q8_0, Q4_0 or Q4_1, with ggml's bytes, and multiplied in those formats on every device; on the CPU, quantised decoding runs on all cores.
require "tensomite"
include Tensomite
x = Tensor.from([1, 2, 3].map(&.to_f32), [3])
loss = (x * x).sum
Tensomite.grad(loss, [x]).first.to_a(Float32) # => [2.0, 4.0, 6.0]
Using it
- User's guide: the API, with small examples.
- Tutorial: train a tiny network to multiply, then use it.
examples/shakespeare.crtrains a character-level GPT;examples/gpt2_diagram.crdraws GPT-2's structure.apps/serverserves GPT-2 and Llama-family models over HTTP, in an OpenAI-style API, and chats in the terminal.apps/finetunefine-tunes GPT-2 on a text, with checkpoints that resume bit for bit.- Claude Code skills in
.claude/skills/:train-a-modelandfinetune-a-modelteach a Claude session in another project to train and fine-tune with tensomite; link them fromlib/tensomite/.claude/skills/.
Working on it
PLAN.md: goals, milestones, and an index of decisions.DECISIONS.md: every decision in full, with its reasoning and measurements.DESIGN.md: how it works, and its measured performance.DEVELOPMENT.md: setup, commands, conventions and workflow.HANDOFF.md: where things stand, for the next session.faq/: short questions and answers on how and why it works, grouped by theme.
Licensed under the MPL-2.0.
tensomite.cr
- 0
- 0
- 7
- 1
- 1
- about 13 hours ago
- October 22, 2026
Mozilla Public License 2.0
Mon, 23 Nov 2026 05:17:40 GMT