Skip to main content

QwenModel

Struct QwenModel 

Source
pub struct QwenModel { /* private fields */ }
Expand description

A loaded, ready-to-run Qwen-family transformer.

Implementations§

Source§

impl QwenModel

Source

pub fn from_loaded_model(model: &LoadedModel) -> Result<Self>

Builds a QwenModel from an already-parsed LoadedModel (kopitiam_loader::load_model’s result): resolves QwenConfig::from_metadata, loads and dequantizes every weight tensor via [crate::weights::ModelWeights::load], and precomputes RoPE’s rotation tables up to the model’s context window.

Source

pub fn config(&self) -> &QwenConfig

Source

pub fn backend(&self) -> &CpuBackend

Trait Implementations§

Source§

impl Model for QwenModel

Source§

fn forward(&self, token_ids: &[u32], cache: &mut KvCache) -> Result<Tensor>

Runs a forward pass over token_ids — new tokens only (a multi-token prompt on the first call, ordinarily one token per call thereafter) — using and extending cache. Returns logits shaped [token_ids.len(), vocab_size]: one row of unnormalized per-vocabulary scores for every input position, in the same order as token_ids.
Source§

fn vocab_size(&self) -> usize

The vocabulary size logits’ last dimension is sized to.
Source§

fn max_context(&self) -> usize

The context window cache should be constructed with via KvCache::new to run this model without hitting kopitiam_core::Error::IndexOutOfBounds from KvCache::append.
Source§

fn new_cache(&self) -> KvCache

Builds a fresh, empty KvCache sized correctly for this model (layer count and context window). This is the only correct way to construct a cache for a given model — KvCache::new takes those two numbers as bare usizes and trusts the caller to get them right, which is fine for KvCache’s own unit tests but exactly the kind of easy-to-mismatch call crate::generate::generate (generic over any Model, not just crate::model::QwenModel) should never have to get right by hand.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.