Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama Llama Model Qwen2MoE

From Leeroopedia
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);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment