To calculate the parameter count for the Qwen3 model based on the provided configuration, I'll break it down step by step. This model is a transformer-based LLM, and the total parameter count includes:
- The input embedding layer.
- The output linear layer (for language modeling).
- Parameters in each transformer layer (attention mechanisms, feed-forward networks, and layer norms).
Key values from the configuration:
hidden_size: 4096
intermediate_size: 12288
vocab_size: 151936
num_hidden_layers: 36
num_attention_heads: 32 (not directly used in parameter count but confirms the attention structure)
- Other details like RMSNorm imply no biases in the layers for efficiency.
Step 1: Parameters in the Embedding Layer
- The embedding layer is a matrix of size
vocab_size x hidden_size.
- Calculation: ( 151936 \times 4096 = 622,329,856 )
Step 2: Parameters in the Output Layer
- This is a linear layer from
hidden_size to vocab_size (for generating output logits).
- Since
tie_word_embeddings is false, this is a separate layer.
- Calculation: ( 4096 \times 151936 = 622,329,856 )
Step 3: Parameters per Transformer Layer
Each of the 36 layers consists of:
- Attention block: Includes projections for Query (Q), Key (K), Value (V), and an output projection.
- Q projection: ( hidden_size \times hidden_size )
- K projection: ( hidden_size \times hidden_size )
- V projection: ( hidden_size \times hidden_size )
- Output projection: ( hidden_size \times hidden_size )
- Total for attention: ( 4 \times (4096 \times 4096) = 4 \times 16,777,216 = 67,108,864 )
- Feed-forward network (MLP): Qwen3 uses a gated MLP with SiLU activation, consisting of three linear layers:
- Gate projection: ( hidden_size \times intermediate_size )
- Up projection: ( hidden_size \times intermediate_size )
- Down projection: ( intermediate_size \times hidden_size )
- Total for MLP: ( 2 \times (4096 \times 12288) + (12288 \times 4096) )
- First two: ( 2 \times (4096 \times 12288) = 2 \times 50,331,648 = 100,663,296 )
- Last: ( 12288 \times 4096 = 50,331,648 )
- Total: ( 100,663,296 + 50,331,648 = 150,994,944 )
- Layer norms: Two RMSNorm layers (one before attention, one after), each with a scale vector of size
hidden_size.
- Total: ( 2 \times 4096 = 8,192 )
Per-layer total: ( 67,108,864 + 150,994,944 + 8,192 = 218,112,000 )
For 36 layers: ( 36 \times 218,112,000 = 7,852,032,000 )
Step 4: Total Parameters
Add up all components:
- Embedding: 622,329,856
- Output layer: 622,329,856
- All layers: 7,852,032,000
- Total: ( 622,329,856 + 622,329,856 + 7,852,032,000 = 9,096,691,712 )
Final Parameter Count
The total number of parameters in this Qwen3 model is approximately 9.1 billion. This is a rough estimate based on the standard transformer architecture assumptions (e.g., no biases in layers, as is common in efficient models like Qwen3). If you're using a specific implementation (e.g., from Hugging Face), the exact count might vary slightly due to optimizations.