Skip to content

Evaluate the KL divergence of the spliced model on an eval split - #147

Open
flyingdoubleG wants to merge 1 commit into
EleutherAI:mainfrom
flyingdoubleG:kl-eval
Open

flyingdoubleG wants to merge 1 commit into
EleutherAI:mainfrom
flyingdoubleG:kl-eval

Conversation

@flyingdoubleG

Copy link
Copy Markdown

Closes #100.

Adds --eval_split. Every save_every steps, the trainer splices all the SAEs into the model at once (excluded tokens keep their original activations) and logs the mean KL divergence between the next-token distributions of the clean and the spliced model as eval/kl. This is the actual KL, unlike the kl training loss, which drops the entropy term of the clean distribution.

Notes:

  • Trainer takes an optional eval_dataset; __main__ loads it from the same dataset as the training split. The eval set is sharded across ranks under DDP and the sums are all-reduced.
  • ScheduleFree optimizers are switched to eval mode while evaluating.
  • It raises for configurations where splicing all SAEs at once isn't well defined yet: distribute_modules, multiple init_seeds, and the ce loss with transcoders. It also raises for memmap datasets, which have no splits.

I know #117 was closed because you planned to write this yourself. If you'd rather keep doing that, feel free to close this.

Tests (tests/test_kl_eval.py, CPU): the KL matches a reference that splices GPT-2 block by block, it is zero when every token is excluded or the SAEs reconstruct perfectly, fit evaluates at every save, and the unsupported configurations raise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluate SAEs with KL divergence when grafted into the model

1 participant