jbloomAus / SAELens

Training Sparse Autoencoders on Language Models
https://jbloomaus.github.io/SAELens/
MIT License
490 stars 127 forks source link

feat: Topk SAE training #370

Closed chanind closed 1 week ago

chanind commented 2 weeks ago

Description

This PR implements topk SAE training by adding the topk auxiliary loss. This PR makes several design choices:

Our implementation of topk training is likely less efficient than Eleuther's as they use a custom sparse kernel for the SAE decoder (see https://github.com/EleutherAI/sae/blob/main/sae/kernels.py). We can try to support something like this in the future, but it will likely require a bit of refactoring before we can support a special decoder kernel just for topk.

I'm currently running some test training runs to make sure things look decent, and will upgrade this PR from draft when those are complete.

Fixes #202

training test run dashboard: https://api.wandb.ai/links/chanind/zju8dl70

Type of change

Please delete options that are not relevant.

Checklist:

You have tested formatting, typing and unit tests (acceptance tests not currently in use)

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 84.09091% with 7 lines in your changes missing coverage. Please review.

Project coverage is 72.88%. Comparing base (17506ac) to head (b49fece). Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
sae_lens/training/training_sae.py 85.18% 2 Missing and 2 partials :warning:
sae_lens/sae_training_runner.py 0.00% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #370 +/- ## ========================================== + Coverage 72.74% 72.88% +0.13% ========================================== Files 22 22 Lines 3266 3297 +31 Branches 431 438 +7 ========================================== + Hits 2376 2403 +27 - Misses 762 764 +2 - Partials 128 130 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features: