gm.nn.Block#
- class gemma.gm.nn.Block(
- num_heads: int,
- num_kv_heads: int,
- embed_dim: int,
- head_dim: int,
- hidden_dim: int,
- use_post_attn_norm: bool,
- use_post_ffw_norm: bool,
- attn_type: gemma.gm.nn._modules.AttentionType,
- query_pre_attn_scalar: float,
- transpose_gating_einsum: bool,
- rope_base_frequency: int = 10000,
- rope_scale_factor: float = 1.0,
- attn_logits_soft_cap: float | None = None,
- sliding_window_size: int | None = None,
- use_qk_norm: bool = False,
- parent: flax.linen.module.Module | flax.core.scope.Scope | flax.linen.module._Sentinel | None = <flax.linen.module._Sentinel object>,
- name: str | None = None,
Bases:
flax.linen.module.ModuleTransformer block.
- num_heads: int
- num_kv_heads: int
- embed_dim: int
- head_dim: int
- hidden_dim: int
- use_post_attn_norm: bool
- use_post_ffw_norm: bool
- attn_type: gemma.gm.nn._modules.AttentionType
- query_pre_attn_scalar: float
- transpose_gating_einsum: bool
- rope_base_frequency: int = 10000
- rope_scale_factor: float = 1.0
- attn_logits_soft_cap: float | None = None
- sliding_window_size: int | None = None
- use_qk_norm: bool = False
- setup()[source]
Initializes a Module lazily (similar to a lazy
__init__).setupis called once lazily on a module instance when a module is bound, immediately before any other methods like__call__are invoked, or before asetup-defined attribute onselfis accessed.This can happen in three cases:
Immediately when invoking
apply(),init()orinit_and_output().Once the module is given a name by being assigned to an attribute of another module inside the other module’s
setupmethod (see__setattr__()):>>> class MyModule(nn.Module): ... def setup(self): ... submodule = nn.Conv(...) ... # Accessing `submodule` attributes does not yet work here. ... # The following line invokes `self.__setattr__`, which gives ... # `submodule` the name "conv1". ... self.conv1 = submodule ... # Accessing `submodule` attributes or methods is now safe and ... # either causes setup() to be called once.
Once a module is constructed inside a method wrapped with
compact(), immediately before another method is called orsetupdefined attribute is accessed.
- name: str | None = None
- parent: flax.linen.module.Module | flax.core.scope.Scope | flax.linen.module._Sentinel | None = None
- scope: flax.core.scope.Scope | None = None