mirror of
https://github.com/ollama/ollama.git
synced 2026-03-28 03:08:44 +07:00
* WIP - MLX backend with gemma3 * MLX: add cmake and go tag build toggles To build the new MLX backend code: cmake --preset MLX cmake --build --preset MLX --parallel cmake --install build --component MLX go build -tags mlx . Note: the main.go entrypoint for the MLX engine will change in a follow up commit. * add experimental image generation runtime * add experimental image generation runtime * MLX: wire up cuda build for linux * MLX: get dependencies correct and dedup This is still too large for a unified github artifact, but is now "correct" for the mlx_cuda_v13 directory. * fix relative link bug in dedup * Add darwin build and readme * add go build tag for mlx dependent code and wire up build_darwin.sh * lint cleanup * macos: build mlx for x86 This will be CPU only. * cuda build instructions and fix drift from mlx bump * stale comment * Delete agent helper doc * Clean up readme.md * Revise README for tokenizer clarity and details Updated README to clarify tokenizer functionality and removed correctness section. --------- Co-authored-by: jmorganca <jmorganca@gmail.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestWordPiece(t *testing.T) {
|
|
wpm := NewWordPiece(
|
|
&Vocabulary{
|
|
Values: []string{"[UNK]", "[CLS]", "[SEP]", "▁hello", "▁world", "s", "▁!", "▁@", "▁#"},
|
|
AddBOS: true,
|
|
AddEOS: true,
|
|
BOS: []int32{1},
|
|
EOS: []int32{2},
|
|
},
|
|
true, // lowercase
|
|
)
|
|
|
|
ids, err := wpm.Encode("Hello world!", true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if diff := cmp.Diff([]int32{1, 3, 4, 6, 2}, ids); diff != "" {
|
|
t.Errorf("unexpected ids (-want +got):\n%s", diff)
|
|
}
|
|
|
|
words, err := wpm.Decode(ids)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if diff := cmp.Diff("[CLS] hello world! [SEP]", words); diff != "" {
|
|
t.Errorf("unexpected words (-want +got):\n%s", diff)
|
|
}
|
|
}
|
|
|
|
func TestWordPieceWords(t *testing.T) {
|
|
var wpm WordPiece
|
|
|
|
basic := slices.Collect(wpm.words("Hey friend! How are you?!?"))
|
|
if diff := cmp.Diff([]string{"Hey", "friend", "!", "How", "are", "you", "?", "!", "?"}, basic); diff != "" {
|
|
t.Errorf("unexpected words (-want +got):\n%s", diff)
|
|
}
|
|
|
|
chinese := slices.Collect(wpm.words("野口里佳 Noguchi Rika"))
|
|
if diff := cmp.Diff([]string{"野", "口", "里", "佳", "Noguchi", "Rika"}, chinese); diff != "" {
|
|
t.Errorf("unexpected words (-want +got):\n%s", diff)
|
|
}
|
|
}
|