Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
SAETrainer.load_trainer_statecallstorch.loadwithoutmap_location, so the restored tensors come back on whatever device the checkpoint was written from instead of the device the trainer is configured for.act_freq_scoresandn_forward_passes_since_firedare created oncfg.devicein__init__and reset oncfg.devicein_reset_running_sparsity_stats, so only the restore path disagrees with the rest of the class. Every othertorch.loadin the codebase already passesmap_location, which is the five call sites inpretrained_sae_loaders.py, and this is the only one that does not.It is reachable through the ordinary resume path, since
LanguageModelSAETrainingRunnercallsload_trainer_stateforresume_from_checkpointandMultiSAETrainercalls it per SAE. Resuming a run on a different device from the one it was trained on then fails on the first sparsity accumulation in_train_step:Resuming a CUDA checkpoint on a machine without CUDA is worse, since it raises inside
torch.loadbefore any state is restored.The fix passes the trainer's own configured device:
Nothing changes when a checkpoint is saved and resumed on the same device, which is why the existing round-trip test did not catch it, since it builds both trainers on the default device.
Type of change
Checklist:
Two tests, both failing on current
main:test_load_trainer_state_reads_the_checkpoint_onto_the_configured_deviceassertstorch.loadreceivesmap_location, and runs everywhere including CPU-only CI. Onmainit fails asassert None == 'cpu'.test_load_trainer_state_moves_an_accelerator_checkpoint_onto_cpuwrites the checkpoint from an accelerator and resumes on CPU. It is skipped without a second device, following the GPU-gated tests intest_activations_store.py. Onmainit fails asassert 'mps' == 'cpu'.Reverting the one-line change while keeping both tests fails both. The full
tests/training/test_sae_trainer.pypasses at 24 passed and 1 skipped, where the skip is the pre-existing fp16 case.You have tested formatting, typing and tests
make check-cito check format and linting.ruff checkandruff format --checkare clean.pyrightreports three more instances ofType of parameter "ts_model" is unknown, the same pre-existing report the otherts_modeltests in that file already produce, since the fixture is untyped.Performance Check.
Not applicable. This only changes which device the running-sparsity tensors are restored onto when resuming, so L0, CE loss, MSE loss and feature dashboards are unaffected.