pub struct LayerWeights {
pub attn_q: WeightStorage,
pub attn_q_bias: Option<Arc<[f32]>>,
pub attn_k: WeightStorage,
pub attn_k_bias: Option<Arc<[f32]>>,
pub attn_v: WeightStorage,
pub attn_v_bias: Option<Arc<[f32]>>,
pub attn_o: WeightStorage,
pub ffn_gate: WeightStorage,
pub ffn_up: WeightStorage,
pub ffn_down: WeightStorage,
pub attn_norm_gain: Arc<[f32]>,
pub ffn_norm_gain: Arc<[f32]>,
}Expand description
Per-layer weights of a LLaMA transformer block. All tensors are
stored as Arc<[f32]> so they can be loaded once and shared across
every forward pass with zero copy — each call to
LlamaModel::forward clones the Arc (a refcount bump) when it
builds fresh const nodes for this layer.
LLaMA proper has no biases anywhere in the attention block, so the
*_bias fields are None for LLaMA family models. Qwen2 and a few
related architectures do add biases on Q/K/V (but not on the output
projection), so the loader stores them here when the safetensors
file contains them.
Fields§
§attn_q: WeightStorage[dim, dim] query projection. Supports bf16 or f32.
attn_q_bias: Option<Arc<[f32]>>[dim] query projection bias (Qwen2-style; LLaMA has none).
attn_k: WeightStorage[dim, dim] key projection.
attn_k_bias: Option<Arc<[f32]>>[kv_dim] key projection bias.
attn_v: WeightStorage[dim, dim] value projection.
attn_v_bias: Option<Arc<[f32]>>[kv_dim] value projection bias.
attn_o: WeightStorage[dim, dim] output projection.
ffn_gate: WeightStorage[dim, ffn_dim] gate projection for SwiGLU.
ffn_up: WeightStorage[dim, ffn_dim] up projection for SwiGLU.
ffn_down: WeightStorage[ffn_dim, dim] down projection for SwiGLU.
attn_norm_gain: Arc<[f32]>[dim] RmsNorm gain for the pre-attention norm. Stays f32
— norm gains are small and precision-sensitive.
ffn_norm_gain: Arc<[f32]>[dim] RmsNorm gain for the pre-FFN norm.
Trait Implementations§
Source§impl Clone for LayerWeights
impl Clone for LayerWeights
Auto Trait Implementations§
impl Freeze for LayerWeights
impl RefUnwindSafe for LayerWeights
impl Send for LayerWeights
impl Sync for LayerWeights
impl Unpin for LayerWeights
impl UnsafeUnpin for LayerWeights
impl UnwindSafe for LayerWeights
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more