Skip to main content

latent-sae

Train Sparse Autoencoders on sentence embedding representations. Decomposes dense embedding vectors into sparse, interpretable features.

Fork of EleutherAI/sae, focused on sentence transformer embeddings with fast disk-based data loading, Modal GPU training, and a comprehensive experiment framework.

Published Models

Model Subfolder Embedding Features k Best For
sae-all-MiniLM-L6-v2-FineWeb-RedPajama-Pile-150M 128_4 MiniLM (384D) 1,536 128 Fine-grained classification
128_8 MiniLM (384D) 3,072 128 Retrieval
64_8 MiniLM (384D) 3,072 64 Maximum feature coverage
sae-nomic-text-v1.5-FineWeb-edu-100BT 64_32 nomic-v1.5 (768D) 24,576 64 Legacy (taxonomy)

Quick Start

# pip install latentsae
from latentsae import Sae
from sentence_transformers import SentenceTransformer
import torch

# Load SAE
sae = Sae.load_from_hub("enjalot/sae-all-MiniLM-L6-v2-FineWeb-RedPajama-Pile-150M", "128_4")

# Embed text
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
embeddings = model.encode(["Hello world", "Sparse autoencoders decompose embeddings"],
                          convert_to_tensor=True, normalize_embeddings=True)

# Extract sparse features
features = sae.encode(embeddings)
print(features.top_indices)  # which features activated
print(features.top_acts)     # how strongly

Training

With YAML config (recommended)

# Single run on Modal A10G
modal run train_modal.py --config experiments/configs/minilm_30M_3source.yaml --gpu-type a10g

# Parameter sweep (parallel)
modal run train_modal.py --config experiments/configs/arch_sweep_base.yaml \
  --sweep experiments/configs/arch_sweep_type.yaml --gpu-type a10g

# Local training on M2 Mac
python -m experiments.run_experiment experiments/configs/smoke_test.yaml --device mps

With CLI args (quick experiments)

modal run train_modal.py --batch-size 1024 --k 128 --expansion-factor 4 --gpu-type a10g
python train_local.py --batch_size 512 --k 64 --expansion_factor 8

Experiment Framework

YAML-driven experiment system with config hashing, cartesian sweeps, and WandB integration. See experiments/ for configs and results.

# Dry-run a sweep to see what would execute
python -m experiments.run_experiment experiments/configs/arch_sweep_base.yaml \
  --sweep experiments/configs/arch_sweep_type.yaml --dry-run

# Compare results
python -m experiments.compare_results experiments/results/

# Evaluate a trained SAE
python -m experiments.eval_probes --sae-path checkpoints/sae_topk_128_4.xxx \
  --embedding-model sentence-transformers/all-MiniLM-L6-v2 --suite hard

Evaluation Suite

Task Type What it tests
AG News 4-class classification Coarse topic features
SST-2 2-class classification Sentiment features
BANKING77 77-class classification Fine-grained intent features
CLINC150 150-class classification Very fine-grained (hardest)
STS-B Similarity (spearman) Continuous semantic structure
SciFact Retrieval (nDCG@10) Information preservation
MMCS Feature quality Decoder weight redundancy

Architecture

Supported SAE types: TopK (recommended), Gated, JumpReLU, LISTA.

Training features: auxk dead feature revival, k-annealing, tilted ERM, decoder decorrelation loss, fire rate penalty, mixed precision (AMP), cosine LR schedule.

Key Research Findings

  • Expansion factor 4-8x is optimal for embeddings (not 32x like LLM layers)
  • k=128 dramatically beats k=64 on fine-grained tasks (CLINC150: 79.6% vs 64.6%)
  • 30M diverse samples retains 97% of 150M quality at 6.4x lower cost
  • 3-source data mix matters more than any training regularization
  • A10G at batch_size=1024 is the cost-optimal GPU config ($2.60/100M samples)

Data Preparation

Training data (pre-computed embeddings) is prepared in latent-data-modal. See the Latent Taxonomy methodology for details.

Part of the latent-* ecosystem

Metadata

Release files for latentsae 0.2.0

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

Source distribution (sdist)

Source distribution for latentsae 0.2.0
File Size Uploaded
latentsae-0.2.0.tar.gz 52.3 kB Details

Built distribution (wheel)

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

Total release size: 96.1 kB

Release files / latentsae-0.2.0.tar.gz

Download URL latentsae-0.2.0.tar.gz
Size 52.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e9b9549686987019d905f1f30b53ec8d8c77ada72d5b2feec7d744f1e8b4f1c8
BLAKE2b-256 checksum
How to use checksums
74e09f6f535bfe3fef2df1fcf7d0c22c10f1fcfdfc2a3527aa6023deba038974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / latentsae-0.2.0-py3-none-any.whl

Download URL latentsae-0.2.0-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
567ca4bcec866042de820d80d99933a769aff814a1280fe74c3c2f39a5aeca66
BLAKE2b-256 checksum
How to use checksums
53a6fde61f9954b104abd758cca73d780419fc4f57a43b16ed50e99ccdd80e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

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