pub struct Lfm2Model {
pub embed_tokens: Tensor,
pub embedding_norm: Option<RMSNorm>,
pub layers: Vec<Lfm2Block>,
pub norm_f: RMSNorm,
pub lm_head: Linear,
/* private fields */
}Expand description
A decoder-only language model: LFM2 (mixed conv/attention blocks) or
Llama-style (every block is attention), as built by
Lfm2ModelBuilder.
Fields§
§embed_tokens: TensorEmbedding table [vocab, hidden].
embedding_norm: Option<RMSNorm>Optional norm applied right after the embedding (neither Llama nor
Hugging Face LFM2 use one; LFM2’s embedding_norm is its final norm).
layers: Vec<Lfm2Block>Blocks.
norm_f: RMSNormFinal norm.
lm_head: LinearProjection to vocabulary logits.
Implementations§
Source§impl Lfm2Model
impl Lfm2Model
Sourcepub fn new(
embed_tokens: Tensor,
embedding_norm: Option<RMSNorm>,
layers: Vec<Lfm2Block>,
norm_f: RMSNorm,
lm_head: Linear,
) -> Self
pub fn new( embed_tokens: Tensor, embedding_norm: Option<RMSNorm>, layers: Vec<Lfm2Block>, norm_f: RMSNorm, lm_head: Linear, ) -> Self
Assemble a model from its parts.
Sourcepub fn supports_kv_cache(&self) -> bool
pub fn supports_kv_cache(&self) -> bool
Whether every block is attention, so incremental decoding with a
KVCache is exact (conv blocks keep no state).
Sourcepub fn new_kv_cache(&self, max_seq: usize) -> Option<KVCache>
pub fn new_kv_cache(&self, max_seq: usize) -> Option<KVCache>
An empty KV cache for sequences of up to max_seq tokens, or None
when supports_kv_cache is false.
Sourcepub fn forward(
&self,
engine: &ComputeEngine,
input_ids: &[u32],
pos: usize,
cache: Option<&mut KVCache>,
mask: Option<&UnifiedTensor>,
) -> Tensor
pub fn forward( &self, engine: &ComputeEngine, input_ids: &[u32], pos: usize, cache: Option<&mut KVCache>, mask: Option<&UnifiedTensor>, ) -> Tensor
Logits [1, seq, vocab] for input_ids, the first of which is at pos.
Sourcepub fn lora_params(&self) -> Vec<Tensor>
pub fn lora_params(&self) -> Vec<Tensor>
Only the LoRA adapter tensors (what LoRA fine-tuning updates).
Sourcepub fn named_params(&self) -> HashMap<String, Tensor>
pub fn named_params(&self) -> HashMap<String, Tensor>
All parameters keyed by Hugging Face-style names.
Sourcepub fn named_lora_params(&self) -> HashMap<String, Tensor>
pub fn named_lora_params(&self) -> HashMap<String, Tensor>
LoRA tensors keyed by name.
Auto Trait Implementations§
impl !Freeze for Lfm2Model
impl !RefUnwindSafe for Lfm2Model
impl !Send for Lfm2Model
impl !Sync for Lfm2Model
impl !UnwindSafe for Lfm2Model
impl Unpin for Lfm2Model
impl UnsafeUnpin for Lfm2Model
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