Views
No views yet
sae.py module allows for easy loading and integration of the trained models into your own projects.sae.py: A self-contained Python module with the SAE and MSAE model implementations to run the inference.clip_disect_20k.txt: A vocabulary file containing 20,000 concept names used for interpreting the learned features.ViT-L_14/: Contains the trained SAE models for the CLIP ViT-L/14 image encoder.ViT-B_16/: Contains the trained SAE models for the CLIP ViT-B/16 image encoder.ViT-L_14 and ViT-B_16) is further subdivided into:centered/: Models trained on mean-centered features.not_centered/: Models trained on non-centered features..pth files for the model weights and .npy files for the concept matching scores.{n_latents}_{n_inputs}_{activation}_{k}_{weighting}_{tied}_{normalized}_{soft_cap}_{dataset}.pthn_latents: The number of latent features in the SAE.n_inputs: The input dimensionality (e.g., 768 for ViT-L/14, 512 for ViT-B/16).activation: The activation function used (e.g., TopKReLU).k: The number of smallest trained active latents for the TopK activation.weighting: Whether the model was trained with uniform weighting (UW) or reverse weighting (RW).tied: Indicates if the model encoder is tied to the decoder.normalized: Indicates if the model was trained with normalized inputs.soft_cap: Indicates if the model uses soft capping for the latent features.dataset: The dataset used for training (e.g., cc3m)..npy files with a similar naming convention: Concept_Interpreter_{model_name}_{vocab_name}.npy, where vocab_name indicates the vocabulary used for concept matching.pip install torch numpysae.py file to your working directory. Then, you can load a model and its corresponding concept vocabulary as follows:1import torch
2import numpy as np
3from sae import SAE
4from huggingface_hub import hf_hub_download
5
6# Download the SAE model weights
7weights_path = hf_hub_download(
8 repo_id="WolodjaZ/MSAE",
9 filename="ViT-L_14/centered/6144_768_TopKReLU_64_RW_False_False_0.0_cc3m_ViT-L~14_train_image_2905936_768.pth"
10)
11sae_model = SAE(weights_path)
12
13# Download the concept matching scores for the model
14vocab_path = hf_hub_download(
15 repo_id="WolodjaZ/MSAE",
16 filename="ViT-L_14/centered/Concept_Interpreter_6144_768_TopKReLU_64_RW_False_False_0.0_cc3m_ViT-L~14_train_image_2905936_768_disect_ViT-L~14_-1_text_20000_768.npy"
17)
18concept_match_scores = np.load(vocab_path)
19
20# Load the vocabulary names
21with open('clip_disect_20k.txt', 'r') as f:
22 vocab_names = [line.strip() for line in f.readlines()]
23
24print(f"Concept match scores shape: {concept_match_scores.shape}")
25print(f"Vocabulary size: {len(vocab_names)}")
26
27# Now you can use the model to encode and decode your own data
28# For a detailed example, please refer to the demo notebook in the original repository:
29# https://github.com/WolodjaZ/MSAE/blob/main/demo.ipynbfilename in hf_hub_download to load any of the other available models. For a complete guide on how to use the model for feature extraction and steering, please refer to the demo notebook in the original MSAE repository.