[PR #4756] [MERGED] refactor convert #11584

Closed
opened 2026-04-12 23:32:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/4756
Author: @mxyng
Created: 5/31/2024
Status: Merged
Merged: 8/1/2024
Merged by: @mxyng

Base: mainHead: mxyng/convert2


📝 Commits (6)

  • 6b25291 update convert test to check result data
  • 5e9db9f refactor convert
  • df993fa comments
  • 781fc2d Update convert/reader_safetensors.go
  • eafc607 convert: only extract large files
  • d8e2664 convert: fix parse functions

📊 Changes

29 files changed (+2494 additions, -1659 deletions)

View changed files

📝 convert/convert.go (+80 -158)
convert/convert_gemma.go (+103 -0)
convert/convert_llama.go (+182 -0)
convert/convert_mixtral.go (+89 -0)
📝 convert/convert_test.go (+76 -53)
convert/fs.go (+58 -0)
convert/gemma.go (+0 -102)
convert/llama.go (+0 -159)
convert/mistral.go (+0 -84)
convert/mixtral.go (+0 -87)
convert/reader.go (+82 -0)
convert/reader_safetensors.go (+149 -0)
convert/reader_torch.go (+47 -0)
convert/safetensors.go (+0 -309)
convert/testdata/Meta-Llama-3-8B-Instruct.json (+313 -0)
convert/testdata/Mistral-7B-Instruct-v0.2.json (+313 -0)
convert/testdata/Mixtral-8x7B-Instruct-v0.1.json (+348 -0)
convert/testdata/gemma-2b-it.json (+188 -0)
📝 convert/tokenizer.go (+214 -55)
convert/tokenizer_spm.go (+83 -0)

...and 9 more files

📄 Description

the goal is to build a single, well defined interface to convert a model as well as interfaces for input formats (e.g. safetensors, pytorch), model architectures (e.g. llama, gemma), and model tokenizers

this change makes some significant changes to the conversion process:

  1. implement a single function call for conversion convert.Convert(string, io.WriteSeeker) which abstracts the many operation required for successful conversion
  2. implement a new convert.Converter interface which each model conversion shall implement
  3. decouple vocabulary parsing from model
  4. add special vocabulary detection for both tokenizer.model and tokenizer.json based vocabularies
  5. update the tensor writing interface for better compatibility with non-trivial conversions

as a test of this new interface, implement mixtral conversion as an extension to llama conversion

TODO:

  • write short tests for tokenizer, model KVs, minimal tensor

Resolves: https://github.com/ollama/ollama/issues/5255


🔄 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/4756 **Author:** [@mxyng](https://github.com/mxyng) **Created:** 5/31/2024 **Status:** ✅ Merged **Merged:** 8/1/2024 **Merged by:** [@mxyng](https://github.com/mxyng) **Base:** `main` ← **Head:** `mxyng/convert2` --- ### 📝 Commits (6) - [`6b25291`](https://github.com/ollama/ollama/commit/6b252918fb5e17f9be5975efe1681a92153b8379) update convert test to check result data - [`5e9db9f`](https://github.com/ollama/ollama/commit/5e9db9fb0bcefbe599734b02dd030f4a347ce576) refactor convert - [`df993fa`](https://github.com/ollama/ollama/commit/df993fa37bde19039231001be9f852386a12a860) comments - [`781fc2d`](https://github.com/ollama/ollama/commit/781fc2d5769bd1df7895dc2a18ab44830f6684fc) Update convert/reader_safetensors.go - [`eafc607`](https://github.com/ollama/ollama/commit/eafc607abb3422a7d8e488aeb7a129a67a1f75c6) convert: only extract large files - [`d8e2664`](https://github.com/ollama/ollama/commit/d8e2664c33e81af0549aa9e75c57e08317d0322d) convert: fix parse functions ### 📊 Changes **29 files changed** (+2494 additions, -1659 deletions) <details> <summary>View changed files</summary> 📝 `convert/convert.go` (+80 -158) ➕ `convert/convert_gemma.go` (+103 -0) ➕ `convert/convert_llama.go` (+182 -0) ➕ `convert/convert_mixtral.go` (+89 -0) 📝 `convert/convert_test.go` (+76 -53) ➕ `convert/fs.go` (+58 -0) ➖ `convert/gemma.go` (+0 -102) ➖ `convert/llama.go` (+0 -159) ➖ `convert/mistral.go` (+0 -84) ➖ `convert/mixtral.go` (+0 -87) ➕ `convert/reader.go` (+82 -0) ➕ `convert/reader_safetensors.go` (+149 -0) ➕ `convert/reader_torch.go` (+47 -0) ➖ `convert/safetensors.go` (+0 -309) ➕ `convert/testdata/Meta-Llama-3-8B-Instruct.json` (+313 -0) ➕ `convert/testdata/Mistral-7B-Instruct-v0.2.json` (+313 -0) ➕ `convert/testdata/Mixtral-8x7B-Instruct-v0.1.json` (+348 -0) ➕ `convert/testdata/gemma-2b-it.json` (+188 -0) 📝 `convert/tokenizer.go` (+214 -55) ➕ `convert/tokenizer_spm.go` (+83 -0) _...and 9 more files_ </details> ### 📄 Description the goal is to build a single, well defined interface to convert a model as well as interfaces for input formats (e.g. safetensors, pytorch), model architectures (e.g. llama, gemma), and model tokenizers this change makes some significant changes to the conversion process: 1. implement a single function call for conversion `convert.Convert(string, io.WriteSeeker)` which abstracts the many operation required for successful conversion 2. implement a new `convert.Converter` interface which each model conversion shall implement 3. decouple vocabulary parsing from model 4. add special vocabulary detection for both tokenizer.model and tokenizer.json based vocabularies 5. update the tensor writing interface for better compatibility with non-trivial conversions as a test of this new interface, implement mixtral conversion as an extension to llama conversion TODO: - [ ] write short tests for tokenizer, model KVs, minimal tensor Resolves: https://github.com/ollama/ollama/issues/5255 --- <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-12 23:32:51 -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#11584