pub struct Attention {
pub q_proj: Linear,
pub k_proj: Linear,
pub v_proj: Linear,
pub o_proj: Linear,
pub n_heads: usize,
pub head_dim: usize,
pub num_kv_heads: usize,
pub dropout_prob: f32,
pub rope_theta: f32,
}Expand description
Causal grouped-query self-attention with RoPE (Llama style).
Fields§
§q_proj: LinearQuery projection [hidden, n_heads * head_dim].
k_proj: LinearKey projection [hidden, num_kv_heads * head_dim].
v_proj: LinearValue projection [hidden, num_kv_heads * head_dim].
o_proj: LinearOutput projection [n_heads * head_dim, hidden].
n_heads: usizeNumber of query heads.
head_dim: usizeDimension of each head (at most 128).
num_kv_heads: usizeNumber of key/value heads; divides n_heads.
dropout_prob: f32Attention dropout probability.
rope_theta: f32RoPE base frequency (rope_theta in Hugging Face configs).
Implementations§
Source§impl Attention
impl Attention
Sourcepub fn forward(
&self,
engine: &ComputeEngine,
x: &Tensor,
pos: usize,
cache: Option<&KVCacheLayer>,
mask: Option<&UnifiedTensor>,
) -> Tensor
pub fn forward( &self, engine: &ComputeEngine, x: &Tensor, pos: usize, cache: Option<&KVCacheLayer>, mask: Option<&UnifiedTensor>, ) -> Tensor
Attends over x ([batch, seq, hidden]) whose first token is at
position pos. With cache, the new keys/values are written at pos
and the queries attend to the whole cache up to their own position.
Sourcepub fn named_params(&self, prefix: &str) -> HashMap<String, Tensor>
pub fn named_params(&self, prefix: &str) -> HashMap<String, Tensor>
Parameters keyed by Hugging Face-style names under prefix.
Sourcepub fn lora_params(&self) -> Vec<Tensor>
pub fn lora_params(&self) -> Vec<Tensor>
Only the LoRA adapter tensors (what LoRA fine-tuning updates).
Auto Trait Implementations§
impl !RefUnwindSafe for Attention
impl !Send for Attention
impl !Sync for Attention
impl !UnwindSafe for Attention
impl Freeze for Attention
impl Unpin for Attention
impl UnsafeUnpin for Attention
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
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