80 1 month ago

A small chat model written entirely in assembly, trained from scratch on one home graphics card. Outputs are not the best, but considering size and budget they're very good (also sometimes hilarious).

126m 300m 755m
ollama run supergoatscriptguy/mnemonic:300m-q4_0

Details

1 month ago

2a978846b6be · 189MB

llama
·
304M
·
Q4_0
{ "num_ctx": 2048, "stop": [ "<|end|>" ], "temperature": 0.7, "top_k": 6
{{- range .Messages }}<|{{ .Role }}|>{{ .Content }}<|end|>{{ end }}<|assistant|>

Readme

Mnemonic

A small chat model written entirely in assembly, trained from scratch on one home graphics card.

Everything that made this model is hand-written x86-64 assembly (NASM) and hand-written PTX for the GPU: downloading and parsing the data, training the tokenizer, pretraining, chat fine-tuning, quantization, and even the tool that wrote these GGUF files. There’s no Python, no PyTorch and no CUDA toolkit anywhere in the pipeline, only the Windows API and the NVIDIA driver.

ollama run supergoatscriptguy/mnemonic

Tags

Tag Model Format Size Notes
latest, 755m 755M Q8_0 803 MB the default, about the same quality as full precision
755m-q4_0 755M Q4_0 451 MB smaller and faster, slightly worse
755m-f16 755M F16 1.5 GB 16-bit, for reference
300m 300M Q8_0 324 MB the second version
300m-q4_0 300M Q4_0 189 MB
300m-f16 300M F16 610 MB
126m 126M Q8_0 135 MB the first version
126m-q4_0 126M Q4_0 85 MB
126m-f16 126M F16 253 MB

What to expect

Mnemonic is small: 755 million parameters for the current version, many times smaller than the models people usually chat with. It’s good at:

  • friendly conversation
  • simple explanations and how-tos
  • short lists, tips, poems and small code snippets

It isn’t reliable for facts, math or long answers. It will confidently make things up, so don’t trust its dates and numbers. It works best one question at a time; start a new chat when you change topic.

Each version is a clear step up from the one before: the 755M knows more, gets more of its explanations right, and holds a conversation better than the 300M.

The models

755M 300M 126M
Architecture Llama-style decoder: RoPE, RMSNorm, SwiGLU, grouped-query attention, tied embeddings, no biases same same
Parameters 755M 304M 126M
Layers 28 24 16
Width 1536, 24 query heads, 8 key/value heads 1024, 16 query heads, 4 key/value heads 768, 12 query heads, 4 key/value heads
Feed-forward 4096 2816 2048
Context 2048 tokens 2048 tokens 1024 tokens
Vocabulary 32,768, byte-level BPE trained from scratch same same

How it was trained

All three models were trained on a single RTX 5070 Ti at home.

  1. Pretraining on FineWeb-Edu:
    • 755M: 15 billion tokens in about 8.3 days, at about 21K tokens/s (106 TFLOPS). The matmuls ran in MXFP8 (8-bit floats with a shared scale per block of 32) and AdamW’s moments were kept in bf16, which is what let a model this size train in 16 GB. Final validation loss: 2.63, against the 300M’s 2.84 on the same text.
    • 300M: 10 billion tokens in about 90 hours, at about 32K tokens/s (68 TFLOPS). Final validation loss: 2.84.
    • 126M: 5 billion tokens in 19 hours. Final validation loss: 3.10.
  2. Chat fine-tuning on smol-smoltalk, with the loss on the assistant’s replies only. For the 755M it was one pass of 389M tokens at 2048 context, in 5.1 hours. Long conversations were cut only at whole turns, so every reply it learned from ends properly.
  3. Identity: about 2,100 conversations mixed into the fine-tuning, so it knows its name, who made it and how it was built.

The GPU side uses tensor-core matmuls (mma.sync, bf16 and MXFP8 with fp32 accumulation) and flash attention, all written in PTX. Every fast kernel is checked against a simple reference kernel, and the backward pass is checked with finite differences.

Chat format

<|bos|><|user|>Hi! Who are you?<|end|><|assistant|>Hi! I'm Mnemonic, an AI assistant. What can I help you with today?<|end|>

The template and stop token are already set up. The default sampling is temperature 0.7, top-p 0.9, top-k 64. For more predictable answers, lower the temperature:

/set parameter temperature 0.3

Good to know

  • Language: English only.
  • Numbers: Mnemonic’s own tokenizer splits digits into groups of one or two. llama.cpp has no exact equivalent, so numbers with 3 or more digits are split slightly differently here than in training. Everything else tokenizes exactly the same, and greedy output matches Mnemonic’s own engine word for word.

Links

Made by Supergoatscriptguy.