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: usizeNumber of transformer blocks.
n_heads: usizeNumber of query attention heads.
n_kv_heads: usizeNumber 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].
The model’s hidden/embedding width (d_model).
head_dim: usizeWidth 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.
Width of the SwiGLU MLP’s gate/up projections.
vocab_size: usizeVocabulary size — the row count of the token embedding table.
max_context: usizeThe context window this model’s KV cache should be sized for.
rope_theta: f32RoPE 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: usizeNumber 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: f32RMSNorm 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
impl QwenConfig
Sourcepub fn from_metadata(metadata: &ModelMetadata) -> Result<Self>
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).
Sourcepub fn gqa_group_size(&self) -> usize
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
impl Clone for QwenConfig
Source§fn clone(&self) -> QwenConfig
fn clone(&self) -> QwenConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more