-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert directly from llama3 #4268
Changes from all commits
d88582d
4730762
c8cf0d9
d355d20
2d315ba
547132e
bbbd9f2
34d5ef2
3591bbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
//go:build slow | ||
|
||
package convert | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/ollama/ollama/llm" | ||
) | ||
|
||
func convertFull(t *testing.T, p string) (llm.KV, llm.Tensors) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's room for improvement here. Ideally there's a single function call to convert or at least set up for writing the binary. I missed calling |
||
t.Helper() | ||
|
||
mf, err := GetModelFormat(p) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
params, err := mf.GetParams(p) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
arch, err := mf.GetModelArch("", p, params) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := arch.LoadVocab(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := arch.GetTensors(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
f, err := os.CreateTemp(t.TempDir(), "f16") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
if err := arch.WriteGGUF(f); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
r, err := os.Open(f.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer r.Close() | ||
|
||
m, _, err := llm.DecodeGGML(r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return m.KV(), m.Tensors() | ||
} | ||
|
||
func TestConvertFull(t *testing.T) { | ||
cases := []struct { | ||
path string | ||
arch string | ||
tensors int | ||
layers int | ||
}{ | ||
{"Meta-Llama-3-8B-Instruct", "llama", 291, 35}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does the test data get populated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I symlinked it into the directory since I have in another directory but you can clone or unpack as well |
||
{"Mistral-7B-Instruct-v0.2", "llama", 291, 35}, | ||
{"Mixtral-8x7B-Instruct-v0.1", "llama", 291, 35}, | ||
{"gemma-2b-it", "gemma", 164, 20}, | ||
} | ||
|
||
for _, tt := range cases { | ||
t.Run(tt.path, func(t *testing.T) { | ||
p := filepath.Join("testdata", tt.path) | ||
if _, err := os.Stat(p); err != nil { | ||
t.Skipf("%s not found", p) | ||
} | ||
|
||
kv, tensors := convertFull(t, p) | ||
|
||
if kv.Architecture() != tt.arch { | ||
t.Fatalf("expected llama, got %s", kv.Architecture()) | ||
} | ||
|
||
if kv.FileType().String() != "F16" { | ||
t.Fatalf("expected F16, got %s", kv.FileType()) | ||
} | ||
|
||
if len(tensors) != tt.tensors { | ||
t.Fatalf("expected %d tensors, got %d", tt.tensors, len(tensors)) | ||
} | ||
|
||
layers := tensors.Layers() | ||
if len(layers) != tt.layers { | ||
t.Fatalf("expected %d layers, got %d", tt.layers, len(layers)) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is intended to run locally and runs iff
-tags slow
and the model testdata exists