Skip to content

Commit

Permalink
update test setting
Browse files Browse the repository at this point in the history
  • Loading branch information
muyo8692 committed Nov 17, 2024
1 parent 85b0669 commit ca3a179
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/unit/training/test_coefficient_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_coefficient_scheduler_initialization_no_warmup():
cfg = build_sae_cfg(
sparsity_coefficient=5,
training_tokens=100 * 4, # train batch size (so 100 steps)
coefficient_warm_up_steps=10,
coefficient_warm_up_steps=0,
)

coefficient_scheduler = CoefficientScheduler(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/training/test_gated_sae.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_gated_sae_loss():

train_step_output = sae.training_forward_pass(
sae_in=x,
current_l1_coefficient=sae.cfg.l1_coefficient,
current_sparsity_coefficient=sae.cfg.sparsity_coefficient,
)

assert train_step_output.sae_out.shape == (batch_size, d_in)
Expand All @@ -77,7 +77,7 @@ def test_gated_sae_loss():
sae_in_centered = x - sae.b_dec
via_gate_feature_magnitudes = torch.relu(sae_in_centered @ sae.W_enc + sae.b_gate)
preactivation_l1_loss = (
sae.cfg.l1_coefficient * torch.sum(via_gate_feature_magnitudes, dim=-1).mean()
sae.cfg.sparsity_coefficient * torch.sum(via_gate_feature_magnitudes, dim=-1).mean()
)

via_gate_reconstruction = (
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_gated_sae_training_forward_pass():
x = torch.randn(batch_size, d_in)
train_step_output = sae.training_forward_pass(
sae_in=x,
current_l1_coefficient=sae.cfg.l1_coefficient,
current_sparsity_coefficient=sae.cfg.sparsity_coefficient,
)

assert train_step_output.sae_out.shape == (batch_size, d_in)
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/training/test_jumprelu_sae.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def test_jumprelu_sae_training_forward_pass():
x = torch.randn(batch_size, d_in)
train_step_output = sae.training_forward_pass(
sae_in=x,
current_l1_coefficient=sae.cfg.l1_coefficient,
current_l0_lambda=sae.cfg.l0_lambda,
current_sparsity_coefficient=sae.cfg.sparsity_coefficient,
)

assert train_step_output.sae_out.shape == (batch_size, d_in)
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/training/test_sae_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_sae_forward(training_sae: TrainingSAE):
x = torch.randn(batch_size, d_in)
train_step_output = training_sae.training_forward_pass(
sae_in=x,
current_l1_coefficient=training_sae.cfg.l1_coefficient,
current_sparsity_coefficient=training_sae.cfg.sparsity_coefficient,
)

assert train_step_output.sae_out.shape == (batch_size, d_in)
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_sae_forward(training_sae: TrainingSAE):
)
assert (
pytest.approx(train_step_output.losses["l1_loss"].item(), rel=1e-3) # type: ignore
== training_sae.cfg.l1_coefficient * expected_l1_loss.detach().float()
== training_sae.cfg.sparsity_coefficient * expected_l1_loss.detach().float()
)


Expand All @@ -206,7 +206,7 @@ def test_sae_forward_with_mse_loss_norm(
x = torch.randn(batch_size, d_in)
train_step_output = training_sae.training_forward_pass(
sae_in=x,
current_l1_coefficient=training_sae.cfg.l1_coefficient,
current_sparsity_coefficient=training_sae.cfg.sparsity_coefficient,
)

assert train_step_output.sae_out.shape == (batch_size, d_in)
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_sae_forward_with_mse_loss_norm(
)
assert (
pytest.approx(train_step_output.losses["l1_loss"].item(), rel=1e-3) # type: ignore
== training_sae.cfg.l1_coefficient * expected_l1_loss.detach().float()
== training_sae.cfg.sparsity_coefficient * expected_l1_loss.detach().float()
)


Expand All @@ -262,7 +262,7 @@ def test_SparseAutoencoder_forward_ghost_grad_loss_non_zero(
x = torch.randn(batch_size, d_in)
train_step_output = training_sae.training_forward_pass(
sae_in=x,
current_l1_coefficient=training_sae.cfg.l1_coefficient,
current_sparsity_coefficient=training_sae.cfg.sparsity_coefficient,
dead_neuron_mask=torch.ones_like(
training_sae.b_enc
).bool(), # all neurons are dead.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/training/test_training_sae.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_TrainingSAE_training_forward_pass_can_scale_sparsity_penalty_by_decoder
x = torch.randn(32, 3)
train_step_output = training_sae.training_forward_pass(
sae_in=x,
current_l1_coefficient=2.0,
current_sparsity_coefficient=2.0,
)
feature_acts = train_step_output.feature_acts
decoder_norm = training_sae.W_dec.norm(dim=1)
Expand Down

0 comments on commit ca3a179

Please sign in to comment.