Skip to content

Commit

Permalink
Update run_experiment.py
Browse files Browse the repository at this point in the history
  • Loading branch information
evanatyourservice committed Aug 15, 2024
1 parent 2bb797f commit 70851d2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions image_classification_jax/run_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,16 @@ def loss_fn(params, batch_stats, rng, images, labels):
path = "/" + "/".join(key)
if "kernel" in path:
to_l2.append(jnp.linalg.norm(value))
l2_loss = jnp.linalg.norm(jnp.array(to_l2)) ** 2
l2_loss = jnp.linalg.norm(jnp.array(to_l2))

if randomize_l2_reg:
rng, subkey = jax.random.split(rng)
multiplier = jax.random.uniform(subkey)
else:
multiplier = 0.5
multiplier = jax.random.uniform(
subkey, dtype=jnp.float32, minval=0.0, maxval=2.0
)
l2_loss *= multiplier

loss += multiplier * l2_regularization * l2_loss
loss += l2_regularization * l2_loss

return loss, (new_model_state, logits, orig_loss)

Expand Down

0 comments on commit 70851d2

Please sign in to comment.