diff --git a/cmd/cmd_benchmark.go b/cmd/cmd_benchmark.go index 8baab2f..9970fa9 100644 --- a/cmd/cmd_benchmark.go +++ b/cmd/cmd_benchmark.go @@ -3,6 +3,7 @@ package cmd import ( + "cmp" "context" "encoding/json" "errors" @@ -11,7 +12,7 @@ import ( "math" "os" "runtime" - "sort" + "slices" "time" "forge.lthn.ai/core/cli/pkg/cli" @@ -465,6 +466,6 @@ func loadBenchmarkPrompts() ([]benchPrompt, error) { prompts = append(prompts, benchPrompt{id: id, prompt: r.Prompt}) } - sort.Slice(prompts, func(i, j int) bool { return prompts[i].id < prompts[j].id }) + slices.SortFunc(prompts, func(a, b benchPrompt) int { return cmp.Compare(a.id, b.id) }) return prompts, nil } diff --git a/gguf.go b/gguf.go index a212971..d857fc6 100644 --- a/gguf.go +++ b/gguf.go @@ -1,6 +1,7 @@ package ml import ( + "cmp" "encoding/binary" "encoding/json" "fmt" @@ -8,7 +9,7 @@ import ( "math" "os" "regexp" - "sort" + "slices" "strconv" "strings" ) @@ -174,8 +175,8 @@ func ConvertMLXtoGGUFLoRA(safetensorsPath, configPath, outputPath, architecture } } - sort.Slice(ggufTensors, func(i, j int) bool { - return ggufTensors[i].name < ggufTensors[j].name + slices.SortFunc(ggufTensors, func(a, b ggufTensor) int { + return cmp.Compare(a.name, b.name) }) metadata := []ggufMetadata{ diff --git a/status.go b/status.go index 2c3c013..e4b4f66 100644 --- a/status.go +++ b/status.go @@ -1,9 +1,10 @@ package ml import ( + "cmp" "fmt" "io" - "sort" + "slices" ) // trainingRow holds deduplicated training status + loss for a single model. @@ -146,8 +147,8 @@ func dedupeTraining(statusRows, lossRows []map[string]any) []trainingRow { rows = append(rows, tr) } - sort.Slice(rows, func(i, j int) bool { - return rows[i].model < rows[j].model + slices.SortFunc(rows, func(a, b trainingRow) int { + return cmp.Compare(a.model, b.model) }) return rows @@ -172,8 +173,8 @@ func dedupeGeneration(rows []map[string]any) []genRow { }) } - sort.Slice(result, func(i, j int) bool { - return result[i].worker < result[j].worker + slices.SortFunc(result, func(a, b genRow) int { + return cmp.Compare(a.worker, b.worker) }) return result