forward(input_ids)returns the final hidden states.compute_logits(hidden_states)projects hidden states to vocabulary logits via the LM head.- A class-level
packed_module_mappingdict maps model parameter names to checkpoint keys, enabling correct loading of fused/sharded weights.
Qwen3ForCausalLM
Qwen3 architecture with Q/K norms and GQA
LlamaForCausalLM
Llama 3 architecture with NTK-scaled RoPE
Qwen3ForCausalLM
myvllm.models.qwen3.Qwen3ForCausalLM
Full Qwen3 causal language model. Stacks num_layers of Qwen3DecoderLayer inside a Qwen3Model backbone, then attaches a ParallelLMHead for next-token prediction. Supports optional weight tying between the token embedding and the LM head.
Key architectural differences from Llama 3:
- Per-head Q and K RMSNorm layers inside each attention block (applied when
qkv_bias=False). - Default RoPE base of
10000(versus500000for Llama 3). - Default max position of
16384.
Constructor
int
required
Vocabulary size. Controls the size of the token embedding table and the LM head.
Model hidden dimension (embedding size and residual stream width).
int
required
Total number of query attention heads across all tensor-parallel ranks.
int
Dimension of each attention head. Defaults to
hidden_size // num_heads.float
default:"1.0"
Attention scale multiplier applied alongside
1 / sqrt(head_dim).int
Total number of key/value heads. Set to a value smaller than
num_heads for grouped-query attention (GQA). Defaults to num_heads.float
default:"1e-5"
Epsilon used in all RMSNorm layers.
bool
default:"False"
Whether to include bias in the QKV projection. When
False, per-head Q and K norms are applied before attention.int
default:"10000"
RoPE base frequency.
int
default:"16384"
Maximum sequence length the positional embedding cache is pre-computed for.
int
default:"4096"
Hidden dimension of the MLP feed-forward layers.
bool
default:"True"
Whether to include bias in the MLP projections.
int
default:"12"
Number of transformer decoder layers.
bool
default:"False"
If
True, the LM head shares the same weight tensor as the token embedding.int
default:"256"
Paged KV cache block size, passed through to each
Attention module.forward
compute_logits separately.
compute_logits
ParallelLMHead. In a tensor-parallel setup, rank 0 gathers logits from all ranks and returns the full (batch_or_tokens, vocab_size) tensor; other ranks return a partial shard.
Sub-components
packed_module_mapping
Qwen3ForCausalLM defines a class attribute that maps internal parameter names to their corresponding keys in a HuggingFace-style checkpoint and the sub-index within a fused weight:
weight_loader overload when loading pre-trained checkpoints.
Quick start
LlamaForCausalLM
myvllm.models.llama.LlamaForCausalLM
Llama 3 causal language model. Structurally identical to Qwen3ForCausalLM but with the following differences:
- No Q/K norms —
LlamaAttndoes not apply per-head RMSNorm to queries and keys. - NTK-scaled RoPE —
RotaryEmbeddingis initialized withis_llama3=True, enabling the NTK-by-parts long-context frequency scaling. - Higher RoPE base — defaults to
500000instead of10000. - Larger context window — defaults to
131072instead of16384. tie_word_embeddings=Trueby default.
Constructor
int
default:"128256"
Vocabulary size.
Model hidden dimension.
int
default:"64"
Dimension of each attention head.
int
default:"32"
Total number of query/output heads across all tensor-parallel ranks.
int
default:"8"
Total number of key/value heads.
bool
default:"False"
Whether to add bias in the QKV projection.
float
default:"1e-5"
Epsilon for all RMSNorm layers.
int
default:"500000"
RoPE base frequency. The higher value extends the effective context length.
int
default:"131072"
Maximum sequence length the positional cache covers.
int
default:"8192"
MLP feed-forward hidden dimension.
bool
default:"False"
Whether to include bias in the MLP projections.
int
default:"16"
Number of transformer decoder layers.
int
default:"256"
Paged KV cache block size.
bool
default:"True"
If
True, the LM head shares the embedding weight.forward
Qwen3ForCausalLM.forward. Returns final hidden states.
compute_logits
Qwen3ForCausalLM.compute_logits. Projects to vocabulary logits.
Sub-components
Quick start
Adding a new model
Follow these steps to add a new architecture to miniVLLM.1
Implement the ForCausalLM class
Create Use the existing layer primitives from
src/myvllm/models/mymodel.py. The class must expose:myvllm.layers (ColumnParallelLinear, RowParallelLinear, LayerNorm, Attention, etc.) to ensure correct tensor-parallel behavior.2
Implement weight_loader for custom sharding
If your model has parameters that do not map 1-to-1 to checkpoint keys — e.g., fused QKV or merged gate+up projections — override Refer to
weight_loader on the relevant nn.Parameter:QKVColumnParallelLinear.weight_loader and MergedColumnParallelLinear.weight_loader in myvllm/layers/linear.py for reference implementations.3
Register in the model runner
Open the model runner’s model registry and add an entry for your new class:The runner uses this registry to instantiate the correct class from the model config.
4
Export from the models package
Add the import to
src/myvllm/models/__init__.py: