Skip to main content

A small TinyStories LM with SAEs and transcoders

Project description

TinyModel

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 tinystoriesmodel

from tiny_model import TinyModel, tokenizer

lm = TinyModel()

# for inference
tok_ids, attn_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinystoriesmodel-0.1.4.post8.tar.gz (77.0 kB view details)

Uploaded Source

Built Distribution

tinystoriesmodel-0.1.4.post8-py3-none-any.whl (76.0 kB view details)

Uploaded Python 3

File details

Details for the file tinystoriesmodel-0.1.4.post8.tar.gz.

File metadata

  • Download URL: tinystoriesmodel-0.1.4.post8.tar.gz
  • Upload date:
  • Size: 77.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for tinystoriesmodel-0.1.4.post8.tar.gz
Algorithm Hash digest
SHA256 ff0385f462dc9ebc4d0fb3a9d1b7c412fa00b32e35cc112527e0a49d7d11d87e
MD5 f812a77661e6d78b2c4898656cbb13f3
BLAKE2b-256 7726bf8c10f5e8c86accd6b3a05cdde425d9564103f1d41c9e0eceefb98e9171

See more details on using hashes here.

File details

Details for the file tinystoriesmodel-0.1.4.post8-py3-none-any.whl.

File metadata

File hashes

Hashes for tinystoriesmodel-0.1.4.post8-py3-none-any.whl
Algorithm Hash digest
SHA256 b11758ebacd86eed33ae7ebba115e046fb40fa351a6a262e4fecbe0187fac2ad
MD5 d0e2265bef7b7066287fb55ab04bf69b
BLAKE2b-256 ffbcda568f10b0986b2af33c1aff42ef2bd59e332ed96f66048bedafdd535623

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page