Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions gemma/gm/nn/gemma4/_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ def __call__(self, eqn: str, x: jax.Array) -> jax.Array:
self.dtype if self.dtype is not None else None,
)
# Workaround for behavior with nn.share_scope in parent modules:
# self.param might return a dict {'w': tensor} instead of the bare tensor.
# The key appears to be the default class weight_name 'w'.
if isinstance(w, dict):
if 'w' in w:
w = w['w']
# self.param might return a dict {self.weight_name: tensor} instead of the
# bare tensor.
if isinstance(w, dict) and self.weight_name in w:
w = w[self.weight_name]
if self.w_scale is not None:
w *= self.w_scale
return jnp.einsum(eqn, x, w)
Expand All @@ -64,9 +63,8 @@ def __call__(self, eqn: str, x: jax.Array) -> jax.Array:
self.shape,
self.dtype if self.dtype is not None else None,
)
if isinstance(w, dict):
if 'w' in w:
w = w['w']
if isinstance(w, dict) and self.weight_name in w:
w = w[self.weight_name]
if self.w_scale is not None:
w *= self.w_scale

Expand Down
Loading