Implementation:Ollama Ollama Llama Model Qwen2MoE
| Knowledge Sources | |
|---|---|
| Domains | LLM Inference, Model Architecture |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
Implements the ggml computation graph builder for the Qwen2-MoE (Mixture-of-Experts) model architecture.
Description
The llm_build_qwen2moe constructor builds a transformer with RoPE-based positional encoding, RMS-normalized self-attention with Q/K/V projections and optional biases, and MoE feed-forward layers with expert routing across all transformer blocks. Uses build_moe_ffn for sparse expert selection and gating.
Usage
Enables Ollama to run Qwen2-MoE models through the llama.cpp inference engine by defining the model's sparse MoE computation graph.
Code Reference
Source Location
- Repository: Ollama
- File:
llama/llama.cpp/src/models/qwen2moe.cpp - Lines: 1-151
Signature
llm_build_qwen2moe::llm_build_qwen2moe(
const llama_model & model,
const llm_graph_params & params) : llm_graph_context(params);
Import
#include "models.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | const llama_model & | Yes | Loaded model with Qwen2-MoE weights |
| params | const llm_graph_params & | Yes | Graph construction parameters |
Outputs
| Name | Type | Description |
|---|---|---|
| ggml graph | ggml_cgraph | Complete Qwen2-MoE computation graph |
Usage Examples
auto builder = llm_build_qwen2moe(model, params);