Skip to main content

TinyModel

There's currently an issue where Python 3.13 doesn't work with TinyModel, please use Python 3.11 or 3.12 instead. Python 3.11.11 definitely works.

TinyModel is a 4 layer, 44M parameter model trained on TinyStories V2 for mechanistic interpretability. It uses ReLU activations and no layernorms. It comes with trained SAEs and transcoders.

It can be installed with pip install tinymodel for Python 3.11 and higher.

This library is in an alpha state, it probably has some bugs. Please let me know if you find any or you're having any trouble with the library, I can be emailed at my full name @ gmail.com or messaged on twitter. You can also add GitHub issues.

from tinymodel import TinyModel, tokenizer

lm = TinyModel()

# for inference
tok_ids, padding_mask = tokenizer(['Once upon a time', 'In the forest'])
logprobs = lm(tok_ids)

# Get SAE/transcoder acts
# See 'SAEs/Transcoders' section for more information.
feature_acts = lm['M1N123'](tok_ids)
all_feat_acts = lm['M2'](tok_ids)

# Generation
lm.generate('Once upon a time, Ada was happily walking through a magical forest with')

# To decode tok_ids you can use
tokenizer.decode(tok_ids)

It was trained for 3 epochs on a preprocessed version of TinyStoriesV2. Pre-tokenized dataset here. I recommend using this dataset for getting SAE/transcoder activations.

SAEs/transcoders

Some sparse SAEs/transcoders are provided along with the model.

For example, acts = lm['M2N100'](tok_ids)

To get sparse acts, choose which part of the transformer block you want to look at (currently sparse MLP/transcoder and SAEs on attention out are available, under the tags 'M' and 'A' respectively). Residual stream and MLP out SAEs exist, they just haven't been added yet, bug me on e.g. Twitter if you want this to happen fast.

Then, add the layer. A sparse MLP at layer 2 would be 'M2'. Finally, optionally add a particular neuron. For example 'M0N10000'.

Tokenization

Tokenization is done as follows:

  • the top-10K most frequent tokens using the GPT-NeoX tokenizer are selected and sorted by frequency.
  • To tokenize a document, first tokenize with the GPT-NeoX tokenizer. Then replace tokens not in the top 10K tokens with a special [UNK] token id. All token ids are then mapped to be between 1 and 10K, roughly sorted from most frequent to least.
  • Finally, prepend the document with a [BEGIN] token id.

Release files for tinymodel 0.1.2.2.post9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tinymodel 0.1.2.2.post9
File Size Uploaded
tinymodel-0.1.2.2.post9.tar.gz 77.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tinymodel 0.1.2.2.post9
File Interpreter ABI Platform
tinymodel-0.1.2.2.post9-py3-none-any.whl Python 3 none any Details

Total release size: 153.3 kB

Release files / tinymodel-0.1.2.2.post9.tar.gz

Download URL tinymodel-0.1.2.2.post9.tar.gz
Size 77.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6cf2433cacc309ec0cedb54d8d21ef6b587aeb050bad2bfa5d5aaf2923a64815
BLAKE2b-256 checksum
How to use checksums
f46a5db5a7087e184a56bc5cdf99ee1742ff20be3c9affd9b3a78b9d2083961a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.1 Darwin/23.5.0

Release files / tinymodel-0.1.2.2.post9-py3-none-any.whl

Download URL tinymodel-0.1.2.2.post9-py3-none-any.whl
Size 76.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2288e9590d8964aa7df5bdab21a2832afb4210fc284ca7a8925719e4d52c0d2
BLAKE2b-256 checksum
How to use checksums
fea641de47526c71ab1ea72ebc9cb94f1ba6cb334b804ecdf03e2449ff078dcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.1 Darwin/23.5.0
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page