Skip to main content

QwenConfig

Struct QwenConfig 

Source
pub struct QwenConfig {
    pub n_layers: usize,
    pub n_heads: usize,
    pub n_kv_heads: usize,
    pub hidden_size: usize,
    pub head_dim: usize,
    pub ffn_hidden_size: usize,
    pub vocab_size: usize,
    pub max_context: usize,
    pub rope_theta: f32,
    pub rope_dimension_count: usize,
    pub norm_eps: f32,
}
Expand description

The resolved shape of a Qwen-family transformer: everything the forward pass needs to know about the model it is about to run, with no further Options or metadata lookups once construction succeeds.

§Why “Qwen-family” and not “generic transformer config”

This struct encodes one specific architecture family: pre-norm residual blocks, RMSNorm, rotary position embeddings, grouped-query attention, and a SwiGLU MLP — the LLaMA-derived shape that Qwen, LLaMA itself, Mistral, and most current open decoder-only models share. It is not an attempt at a universal config covering encoder-decoder models, ALiBi, or MoE routing; those are different forward passes, not different values of the same fields, and would be a new config type (and a new crate::Model impl) rather than more Options bolted onto this one.

Fields§

§n_layers: usize

Number of transformer blocks.

§n_heads: usize

Number of query attention heads.

§n_kv_heads: usize

Number of key/value attention heads. Equal to n_heads for ordinary multi-head attention; smaller under grouped-query attention (Qwen2’s usual configuration), where each KV head is shared by n_heads / n_kv_heads query heads. See [crate::attention].

§hidden_size: usize

The model’s hidden/embedding width (d_model).

§head_dim: usize

Width of one attention head: hidden_size / n_heads. Not an independent metadata field — GGUF does not record it separately — but derived here once so every consumer agrees on it.

§ffn_hidden_size: usize

Width of the SwiGLU MLP’s gate/up projections.

§vocab_size: usize

Vocabulary size — the row count of the token embedding table.

§max_context: usize

The context window this model’s KV cache should be sized for.

§rope_theta: f32

RoPE base frequency (theta). Defaults to 10000.0, the value every LLaMA/Qwen checkpoint has shipped with to date, when the metadata omits rope.freq_base.

§rope_dimension_count: usize

Number of leading dimensions of each head RoPE actually rotates. Defaults to head_dim (full rotary) when the metadata omits rope.dimension_count — which is what every current Qwen2/LLaMA GGUF export does, since full rotary is their only configuration; the field exists in the format for architectures (e.g. GPT-NeoX-style partial rotary) that rotate only a prefix of each head.

§norm_eps: f32

RMSNorm epsilon. Defaults to 1e-6, the value every current Qwen2 checkpoint uses, when the metadata omits both attention.layer_norm_rms_epsilon and attention.layer_norm_epsilon.

Implementations§

Source§

impl QwenConfig

Source

pub fn from_metadata(metadata: &ModelMetadata) -> Result<Self>

Resolves a QwenConfig from a loaded model’s metadata.

§Errors

Returns Error::MalformedModel if any field with no safe default (layer count, either head count, hidden size, feed-forward size, or vocab size) is absent, or if n_heads does not evenly divide hidden_size (which would make head_dim — and therefore every weight matrix shape this crate assumes — ill-defined), or if n_kv_heads does not evenly divide n_heads (which would make the grouped-query head-repeat in [crate::attention] ill-defined).

Source

pub fn gqa_group_size(&self) -> usize

Query heads sharing each key/value head: n_heads / n_kv_heads. 1 for ordinary multi-head attention, > 1 under GQA.

Trait Implementations§

Source§

impl Clone for QwenConfig

Source§

fn clone(&self) -> QwenConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QwenConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for QwenConfig

Source§

fn eq(&self, other: &QwenConfig) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for QwenConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.