-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathllama_test.go
120 lines (107 loc) · 3.21 KB
/
llama_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package llama_test
import (
"os"
"github.com/go-skynet/go-llama.cpp"
. "github.com/go-skynet/go-llama.cpp"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("LLama binding", func() {
testModelPath := os.Getenv("TEST_MODEL")
Context("Declaration", func() {
It("fails with no model", func() {
model, err := New("not-existing")
Expect(err).To(HaveOccurred())
Expect(model).To(BeNil())
})
})
Context("Inferencing tests (using "+testModelPath+") ", func() {
getModel := func() (*LLama, error) {
model, err := New(
testModelPath,
EnableF16Memory,
SetContext(128),
SetMMap(true),
SetNBatch(512),
)
Expect(err).ToNot(HaveOccurred())
Expect(model).ToNot(BeNil())
return model, err
}
It("predicts successfully", func() {
if testModelPath == "" {
Skip("test skipped - only makes sense if the TEST_MODEL environment variable is set.")
}
model, err := getModel()
text, err := model.Predict(`[INST] Answer to the following question:
how much is 2+2?
[/INST]`)
Expect(err).ToNot(HaveOccurred(), text)
Expect(text).To(ContainSubstring("4"), text)
})
It("speculative sampling predicts", func() {
if testModelPath == "" {
Skip("test skipped - only makes sense if the TEST_MODEL environment variable is set.")
}
model, err := New(
testModelPath,
EnableF16Memory,
SetContext(128),
SetMMap(true),
SetNBatch(512),
SetPerplexity(true),
)
Expect(err).ToNot(HaveOccurred())
Expect(model).ToNot(BeNil())
model2, err := New(
testModelPath,
EnableF16Memory,
SetContext(128),
SetMMap(true),
SetNBatch(512),
SetPerplexity(true),
)
Expect(err).ToNot(HaveOccurred())
Expect(model).ToNot(BeNil())
text, err := model.SpeculativeSampling(model2, `[INST] Answer to the following question:
how much is 2+2?
[/INST]`, llama.SetNDraft(16),
)
Expect(err).ToNot(HaveOccurred(), text)
Expect(text).To(ContainSubstring("4"), text)
})
It("tokenizes strings successfully", func() {
if testModelPath == "" {
Skip("test skipped - only makes sense if the TEST_MODEL environment variable is set.")
}
model, err := getModel()
l, tokens, err := model.TokenizeString("A STRANGE GAME.\nTHE ONLY WINNING MOVE IS NOT TO PLAY.\n\nHOW ABOUT A NICE GAME OF CHESS?",
SetRopeFreqBase(10000.0), SetRopeFreqScale(1))
Expect(err).ToNot(HaveOccurred())
Expect(l).To(BeNumerically(">", 0))
Expect(int(l)).To(Equal(len(tokens)))
})
})
Context("Inferencing tests with GPU (using "+testModelPath+") ", Label("gpu"), func() {
getModel := func() (*LLama, error) {
model, err := New(
testModelPath,
llama.EnableF16Memory, llama.SetContext(128), llama.EnableEmbeddings, llama.SetGPULayers(10),
)
Expect(err).ToNot(HaveOccurred())
Expect(model).ToNot(BeNil())
return model, err
}
It("predicts successfully", func() {
if testModelPath == "" {
Skip("test skipped - only makes sense if the TEST_MODEL environment variable is set.")
}
model, err := getModel()
text, err := model.Predict(`[INST] Answer to the following question:
how much is 2+2?
[/INST]`)
Expect(err).ToNot(HaveOccurred(), text)
Expect(text).To(ContainSubstring("4"), text)
})
})
})