kev-0.5b declared architecture "ggmlc", which llama.cpp does not know. It was fetched, catalogued and placed, and failed on every node — while the answer was in the first kilobytes of the file. internal/gguf reads a GGUF header (v1-v3) up to general.architecture, over HTTP with a Range request, and judges it against the architectures llama.cpp b10991 lists in LLM_ARCH_NAMES (152, copied from the source at that tag); a vision projector is not a model on its own. An unknown build is not refused, only not vouched for, and a header that cannot be fetched does not refuse anything. Checked in three places: the registry listing (from the architecture Hugging Face reports with expand[]=gguf, so one request per repository) shows it and withholds the fetch button; a fetch reads the header and refuses unless "fetch anyway"; and the model service refuses to add such a model, which covers the serve form and ctl model add. Tried on real files: the mirror's qwen2.5-1.5b (qwen2) and bge-m3 (bert), and Qwen2.5-0.5B on Hugging Face through its redirect. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
package gguf
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/binary"
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// header builds a GGUF v3 header: an array before the architecture, the way
|
|
// real files put tokenizer data, so skipping values is exercised.
|
|
func header(arch string) []byte {
|
|
var b bytes.Buffer
|
|
w := func(v any) { _ = binary.Write(&b, binary.LittleEndian, v) }
|
|
str := func(s string) { w(uint64(len(s))); b.WriteString(s) }
|
|
b.WriteString("GGUF")
|
|
w(uint32(3))
|
|
w(uint64(0)) // tensors
|
|
w(uint64(4)) // kvs
|
|
str("general.alignment")
|
|
w(uint32(tUint32))
|
|
w(uint32(32))
|
|
str("some.list")
|
|
w(uint32(tArray))
|
|
w(uint32(tString))
|
|
w(uint64(2))
|
|
str("a")
|
|
str("bc")
|
|
str("general.architecture")
|
|
w(uint32(tString))
|
|
str(arch)
|
|
str("general.name")
|
|
w(uint32(tString))
|
|
str("A Model")
|
|
return b.Bytes()
|
|
}
|
|
|
|
func TestTheArchitectureIsReadFromTheHeader(t *testing.T) {
|
|
h, err := Read(bytes.NewReader(header("ggmlc")))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if h.Architecture != "ggmlc" || h.Name != "A Model" || h.Version != 3 {
|
|
t.Errorf("header = %+v", h)
|
|
}
|
|
}
|
|
|
|
func TestSomethingElseIsNotAGGUF(t *testing.T) {
|
|
if _, err := Read(strings.NewReader("<html>not found</html>")); !errors.Is(err, ErrNotGGUF) {
|
|
t.Errorf("an HTML page read as %v", err)
|
|
}
|
|
}
|
|
|
|
func TestOnlyTheStartOfARemoteFileIsFetched(t *testing.T) {
|
|
body := append(header("qwen2"), make([]byte, 1<<20)...)
|
|
var rng string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
rng = r.Header.Get("Range")
|
|
http.ServeContent(w, r, "m.gguf", timeZero, bytes.NewReader(body))
|
|
}))
|
|
defer srv.Close()
|
|
h, err := FromURL(context.Background(), nil, srv.URL+"/m.gguf")
|
|
if err != nil || h.Architecture != "qwen2" {
|
|
t.Fatalf("%+v, %v", h, err)
|
|
}
|
|
if !strings.HasPrefix(rng, "bytes=0-") {
|
|
t.Errorf("asked for %q rather than the start of the file", rng)
|
|
}
|
|
}
|
|
|
|
func TestLlamaCppKnowsWhatItCanLoad(t *testing.T) {
|
|
if v := LlamaCpp("b10991", "qwen2"); !v.Servable || !v.Checked {
|
|
t.Errorf("qwen2: %+v", v)
|
|
}
|
|
// The file that started this: downloaded, catalogued, placed, and then
|
|
// refused by every node with "unknown model architecture: 'ggmlc'".
|
|
if v := LlamaCpp("b10991", "ggmlc"); v.Servable || !strings.Contains(v.Reason, "cannot load") {
|
|
t.Errorf("ggmlc: %+v", v)
|
|
}
|
|
if v := LlamaCpp("b10991", "clip"); v.Servable {
|
|
t.Errorf("a vision projector alone: %+v", v)
|
|
}
|
|
// A build llmgw has no list for is not refused, only not vouched for.
|
|
if v := LlamaCpp("b99999", "ggmlc"); !v.Servable || v.Checked {
|
|
t.Errorf("an unknown build: %+v", v)
|
|
}
|
|
}
|
|
|
|
var timeZero = time.Time{}
|