[PR #13658] [CLOSED] mlx: implement L2Norm using native mlx_linalg_norm_l2 #61017

Closed
opened 2026-04-29 16:06:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13658
Author: @iamadalek
Created: 1/9/2026
Status: Closed

Base: mainHead: l2norm-feature


📝 Commits (1)

  • 93f3782 mlx: implement L2Norm using native mlx_linalg_norm_l2

📊 Changes

1 file changed (+22 additions, -2 deletions)

View changed files

📝 x/ml/backend/mlx/mlx.go (+22 -2)

📄 Description

Summary

Implements L2 normalization for the MLX backend using the native mlx_linalg_norm_l2 function, enabling BERT, NomicBERT, Qwen3, and Gemma3 embedding models.

Changes from Previous PR (#13649)

Updated based on @dhiltgen's review feedback:

  • Now uses mlx_linalg_norm_l2 instead of manual implementation
  • Cleaner: 3 steps vs 5 steps
  • More efficient: leverages optimized MLX-C linalg function

Implementation

x / (||x||₂ + eps)
  1. Compute L2 norm via mlx_linalg_norm_l2 (axis=-1, keepdims=true)
  2. Add eps for numerical stability
  3. Divide input by norm to get unit vector

Models Unblocked

  • model/models/bert/embed.go
  • model/models/nomicbert/model.go
  • model/models/qwen3/embed.go
  • model/models/gemma3/embed.go
  • x/model/models/gemma3/embed.go

Fixes the NOT YET IMPLEMENTED panic for L2Norm.

Related: #13649, #13648


🔄 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/13658 **Author:** [@iamadalek](https://github.com/iamadalek) **Created:** 1/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `l2norm-feature` --- ### 📝 Commits (1) - [`93f3782`](https://github.com/ollama/ollama/commit/93f3782ce41259a22f9caaeb23d311d7fb8081f7) mlx: implement L2Norm using native mlx_linalg_norm_l2 ### 📊 Changes **1 file changed** (+22 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `x/ml/backend/mlx/mlx.go` (+22 -2) </details> ### 📄 Description ## Summary Implements L2 normalization for the MLX backend using the native `mlx_linalg_norm_l2` function, enabling BERT, NomicBERT, Qwen3, and Gemma3 embedding models. ## Changes from Previous PR (#13649) Updated based on @dhiltgen's review feedback: - Now uses `mlx_linalg_norm_l2` instead of manual implementation - Cleaner: 3 steps vs 5 steps - More efficient: leverages optimized MLX-C linalg function ## Implementation ``` x / (||x||₂ + eps) ``` 1. Compute L2 norm via `mlx_linalg_norm_l2` (axis=-1, keepdims=true) 2. Add eps for numerical stability 3. Divide input by norm to get unit vector ## Models Unblocked - `model/models/bert/embed.go` - `model/models/nomicbert/model.go` - `model/models/qwen3/embed.go` - `model/models/gemma3/embed.go` - `x/model/models/gemma3/embed.go` Fixes the `NOT YET IMPLEMENTED` panic for L2Norm. Related: #13649, #13648 --- <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 2026-04-29 16:06:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#61017