[PR #10078] [CLOSED] ml: structured rope config to allow specifying context length #11877

Closed
opened 2025-11-12 16:23:55 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/10078
Author: @BruceMacD
Created: 4/1/2025
Status: Closed

Base: mainHead: brucemacd/ropeconfig


📝 Commits (3)

  • 96df15e ml: structured rope config to allow specifying context len
  • cbeb2aa Update backend.go
  • 1598215 Update ml/backend.go

📊 Changes

7 files changed (+153 additions, -57 deletions)

View changed files

📝 kvcache/causal_test.go (+1 -1)
📝 ml/backend.go (+48 -1)
📝 ml/backend/ggml/ggml.go (+36 -11)
📝 model/models/gemma2/model.go (+12 -7)
📝 model/models/gemma3/model_text.go (+32 -19)
📝 model/models/llama/model.go (+12 -9)
📝 model/models/mllama/model_text.go (+12 -9)

📄 Description

While implementing Qwen2 architectures I once again came across the need to pass an extra parameter to rope (trained context length), as seen here:
https://github.com/ollama/ollama/tree/brucemacd/qwen25vl

Rather than adding yet another parameter to the rope function I've refactored the Rotary Position Embedding (RoPE) implementation across the codebase to use a structured configuration approach instead of individual parameters. This makes it easier to follow forward passes and allows up to add new configuration in the future without the need to change the rope calls across the entire codebase.

Key changes:

  • Add new RoPEConfig struct with fields for dimension, type, base frequency, and scaling
  • Add RopeType enum to formalize different RoPE implementation variants
  • Add YarnConfig struct and related configuration for YaRN (Yet Another RoPE extensioN) context extension
  • Update RoPE method signature across all tensor interfaces and implementations
  • Refactor all model implementations (llama, gemma2, gemma3, mllama) to use the new configuration structure

This change improves code organization, makes the RoPE configuration more explicit, and provides better support for different RoPE variants and context extension methods.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/10078 **Author:** [@BruceMacD](https://github.com/BruceMacD) **Created:** 4/1/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `brucemacd/ropeconfig` --- ### 📝 Commits (3) - [`96df15e`](https://github.com/ollama/ollama/commit/96df15edfcaab1f192fa60ce49887f4992ca383f) ml: structured rope config to allow specifying context len - [`cbeb2aa`](https://github.com/ollama/ollama/commit/cbeb2aab4f713b712dd90c51a24853d5e5dd79a0) Update backend.go - [`1598215`](https://github.com/ollama/ollama/commit/159821594c345b1e4fd124edb256e8e26dc94060) Update ml/backend.go ### 📊 Changes **7 files changed** (+153 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `kvcache/causal_test.go` (+1 -1) 📝 `ml/backend.go` (+48 -1) 📝 `ml/backend/ggml/ggml.go` (+36 -11) 📝 `model/models/gemma2/model.go` (+12 -7) 📝 `model/models/gemma3/model_text.go` (+32 -19) 📝 `model/models/llama/model.go` (+12 -9) 📝 `model/models/mllama/model_text.go` (+12 -9) </details> ### 📄 Description While implementing Qwen2 architectures I once again came across the need to pass an extra parameter to rope (trained context length), as seen here: https://github.com/ollama/ollama/tree/brucemacd/qwen25vl Rather than adding yet another parameter to the rope function I've refactored the Rotary Position Embedding (RoPE) implementation across the codebase to use a structured configuration approach instead of individual parameters. This makes it easier to follow forward passes and allows up to add new configuration in the future without the need to change the rope calls across the entire codebase. Key changes: - Add new RoPEConfig struct with fields for dimension, type, base frequency, and scaling - Add RopeType enum to formalize different RoPE implementation variants - Add YarnConfig struct and related configuration for YaRN (Yet Another RoPE extensioN) context extension - Update RoPE method signature across all tensor interfaces and implementations - Refactor all model implementations (llama, gemma2, gemma3, mllama) to use the new configuration structure This change improves code organization, makes the RoPE configuration more explicit, and provides better support for different RoPE variants and context extension methods. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-12 16:23:55 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama-ollama#11877