s#x/exp/maps#maps# (#11506)

This commit is contained in:
Michael Yang
2025-07-23 13:23:32 -07:00
committed by GitHub
parent 3bac5cba60
commit 6c733bf0a6
5 changed files with 10 additions and 22 deletions

View File

@@ -11,14 +11,13 @@ import (
"io" "io"
"io/fs" "io/fs"
"log/slog" "log/slog"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"slices" "slices"
"strings" "strings"
"testing" "testing"
"golang.org/x/exp/maps"
"github.com/ollama/ollama/fs/ggml" "github.com/ollama/ollama/fs/ggml"
) )
@@ -137,9 +136,7 @@ func TestConvertModel(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
keys := maps.Keys(expect) for _, k := range slices.Sorted(maps.Keys(expect)) {
slices.Sort(keys)
for _, k := range keys {
if v, ok := actual[k]; !ok { if v, ok := actual[k]; !ok {
t.Errorf("missing %s", k) t.Errorf("missing %s", k)
} else if v != expect[k] { } else if v != expect[k] {
@@ -343,9 +340,7 @@ func TestConvertAdapter(t *testing.T) {
actual := generateResultsJSON(t, r, m.KV(), m.Tensors()) actual := generateResultsJSON(t, r, m.KV(), m.Tensors())
keys := maps.Keys(c.Expected) for _, k := range slices.Sorted(maps.Keys(c.Expected)) {
slices.Sort(keys)
for _, k := range keys {
if v, ok := actual[k]; !ok { if v, ok := actual[k]; !ok {
t.Errorf("missing %s", k) t.Errorf("missing %s", k)
} else if v != c.Expected[k] { } else if v != c.Expected[k] {

View File

@@ -8,12 +8,12 @@ import (
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
"maps"
"slices" "slices"
"strings" "strings"
"github.com/d4l3k/go-bfloat16" "github.com/d4l3k/go-bfloat16"
"github.com/x448/float16" "github.com/x448/float16"
"golang.org/x/exp/maps"
) )
type safetensorMetadata struct { type safetensorMetadata struct {
@@ -46,8 +46,7 @@ func parseSafetensors(fsys fs.FS, replacer *strings.Replacer, ps ...string) ([]T
return nil, err return nil, err
} }
keys := maps.Keys(headers) keys := slices.Sorted(maps.Keys(headers))
slices.Sort(keys)
names := make(map[string]struct{}, len(keys)) names := make(map[string]struct{}, len(keys))

View File

@@ -8,11 +8,10 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"log/slog" "log/slog"
"maps"
"os" "os"
"slices" "slices"
"strings" "strings"
"golang.org/x/exp/maps"
) )
const ( const (
@@ -260,11 +259,8 @@ func parseVocabularyFromTokenizer(fsys fs.FS) (*Vocabulary, error) {
tokens[token.ID] = token tokens[token.ID] = token
} }
keys := maps.Keys(tokens)
slices.Sort(keys)
v := Vocabulary{Model: "gpt2"} v := Vocabulary{Model: "gpt2"}
for _, k := range keys { for _, k := range slices.Sorted(maps.Keys(tokens)) {
token := tokens[k] token := tokens[k]
v.Tokens = append(v.Tokens, token.Content) v.Tokens = append(v.Tokens, token.Content)
v.Scores = append(v.Scores, float32(token.ID)) v.Scores = append(v.Scores, float32(token.ID))

2
go.mod
View File

@@ -71,7 +71,7 @@ require (
github.com/ugorji/go/codec v1.2.12 // indirect github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.36.0 golang.org/x/crypto v0.36.0
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect
golang.org/x/net v0.38.0 // indirect golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.31.0 golang.org/x/sys v0.31.0
golang.org/x/term v0.30.0 golang.org/x/term v0.30.0

View File

@@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
"maps"
"math" "math"
"slices" "slices"
"strings" "strings"
@@ -14,7 +15,6 @@ import (
"text/template/parse" "text/template/parse"
"github.com/agnivade/levenshtein" "github.com/agnivade/levenshtein"
"golang.org/x/exp/maps"
"github.com/ollama/ollama/api" "github.com/ollama/ollama/api"
) )
@@ -157,9 +157,7 @@ func (t *Template) Vars() []string {
set[strings.ToLower(n)] = struct{}{} set[strings.ToLower(n)] = struct{}{}
} }
vars = maps.Keys(set) return slices.Sorted(maps.Keys(set))
slices.Sort(vars)
return vars
} }
type Values struct { type Values struct {