pub struct LlamaModel<B: Backend> { /* private fields */ }Expand description
Llama-family causal LM.
Trait Implementations§
Source§impl<B: Backend> GenerativeModel<B> for LlamaModel<B>
impl<B: Backend> GenerativeModel<B> for LlamaModel<B>
Source§fn metadata(&self) -> &ModelMetadata
fn metadata(&self) -> &ModelMetadata
Metadata this model was built from.
Source§fn load(source: &dyn ModelSource, device: &Device<B>) -> Result<Self>
fn load(source: &dyn ModelSource, device: &Device<B>) -> Result<Self>
Loads all weights from a
ModelSource onto device.Source§fn create_kv_cache(&self, config: &CacheConfig) -> Box<dyn KVCache<B>>
fn create_kv_cache(&self, config: &CacheConfig) -> Box<dyn KVCache<B>>
Creates a fresh KV cache for a new generation session, sized and
implemented according to
config (paged arena vs contiguous
baseline).Source§fn embed(&self, tokens: Tensor<B, 2, Int>) -> Tensor<B, 3>
fn embed(&self, tokens: Tensor<B, 2, Int>) -> Tensor<B, 3>
Embeds token ids:
[batch, seq] -> [batch, seq, hidden].Source§fn prefill(
&mut self,
input: Tensor<B, 3>,
cache: &mut dyn KVCache<B>,
pos: Range<u32>,
) -> Tensor<B, 2>
fn prefill( &mut self, input: Tensor<B, 3>, cache: &mut dyn KVCache<B>, pos: Range<u32>, ) -> Tensor<B, 2>
Runs (a chunk of) the prompt through the model, filling the KV cache
for positions
pos. pos.end - pos.start must equal the input
sequence length, and pos.start must equal the cache’s current
length (dense contiguous chunks). Returns the logits of the last
position, shape [batch, vocab].Source§fn decode(
&mut self,
input: Tensor<B, 3>,
cache: &mut dyn KVCache<B>,
) -> Tensor<B, 2>
fn decode( &mut self, input: Tensor<B, 3>, cache: &mut dyn KVCache<B>, ) -> Tensor<B, 2>
Runs one decode step (single new position at the end of the cache).
Returns the logits of that position, shape
[batch, vocab].Source§fn embed_multimodal(
&self,
tokens: Tensor<B, 2, Int>,
images: &[Tensor<B, 4>],
) -> Result<Tensor<B, 3>>
fn embed_multimodal( &self, tokens: Tensor<B, 2, Int>, images: &[Tensor<B, 4>], ) -> Result<Tensor<B, 3>>
Embeds token ids, splicing vision-tower features into the image-token
spans.
images are preprocessed pixel batches [1, channels, H, W],
one per image-token span, in order. Text-only models keep the default
impl, which rejects non-empty media and otherwise defers to embed.Auto Trait Implementations§
impl<B> Freeze for LlamaModel<B>where
<B as BackendTypes>::FloatTensorPrimitive: Freeze,
<B as BackendTypes>::QuantizedTensorPrimitive: Freeze,
impl<B> RefUnwindSafe for LlamaModel<B>where
<B as BackendTypes>::FloatTensorPrimitive: RefUnwindSafe,
<B as BackendTypes>::QuantizedTensorPrimitive: RefUnwindSafe,
impl<B> Send for LlamaModel<B>
impl<B> Sync for LlamaModel<B>
impl<B> Unpin for LlamaModel<B>where
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
impl<B> UnsafeUnpin for LlamaModel<B>where
<B as BackendTypes>::FloatTensorPrimitive: UnsafeUnpin,
<B as BackendTypes>::QuantizedTensorPrimitive: UnsafeUnpin,
impl<B> UnwindSafe for LlamaModel<B>where
<B as BackendTypes>::FloatTensorPrimitive: UnwindSafe,
<B as BackendTypes>::QuantizedTensorPrimitive: UnwindSafe,
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
Mutably borrows from an owned value. Read more