Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
c4904161
Commit
c4904161
authored
Jul 20, 2023
by
Michael Yang
Browse files
lock on llm.lock(); decrease batch size
parent
f62a8827
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
api/types.go
api/types.go
+1
-1
llama/llama.go
llama/llama.go
+10
-6
No files found.
api/types.go
View file @
c4904161
...
@@ -177,7 +177,7 @@ func DefaultOptions() Options {
...
@@ -177,7 +177,7 @@ func DefaultOptions() Options {
UseNUMA
:
false
,
UseNUMA
:
false
,
NumCtx
:
2048
,
NumCtx
:
2048
,
NumBatch
:
51
2
,
NumBatch
:
3
2
,
NumGPU
:
1
,
NumGPU
:
1
,
LowVRAM
:
false
,
LowVRAM
:
false
,
F16KV
:
true
,
F16KV
:
true
,
...
...
llama/llama.go
View file @
c4904161
...
@@ -172,9 +172,6 @@ func (llm *LLM) Close() {
...
@@ -172,9 +172,6 @@ func (llm *LLM) Close() {
}
}
func
(
llm
*
LLM
)
Predict
(
ctx
[]
int
,
prompt
string
,
fn
func
(
api
.
GenerateResponse
))
error
{
func
(
llm
*
LLM
)
Predict
(
ctx
[]
int
,
prompt
string
,
fn
func
(
api
.
GenerateResponse
))
error
{
llm
.
mu
.
Lock
()
defer
llm
.
mu
.
Unlock
()
C
.
llama_reset_timings
(
llm
.
ctx
)
C
.
llama_reset_timings
(
llm
.
ctx
)
tokens
:=
make
([]
C
.
llama_token
,
len
(
ctx
))
tokens
:=
make
([]
C
.
llama_token
,
len
(
ctx
))
...
@@ -193,12 +190,12 @@ func (llm *LLM) Predict(ctx []int, prompt string, fn func(api.GenerateResponse))
...
@@ -193,12 +190,12 @@ func (llm *LLM) Predict(ctx []int, prompt string, fn func(api.GenerateResponse))
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
for
{
for
{
token
,
err
:=
llm
.
next
()
token
,
err
:=
llm
.
next
()
if
errors
.
Is
(
err
,
io
.
EOF
)
{
if
llm
.
gc
{
return
nil
}
else
if
errors
.
Is
(
err
,
io
.
EOF
)
{
break
break
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
return
err
return
err
}
else
if
llm
.
gc
{
return
io
.
EOF
}
}
b
.
WriteString
(
llm
.
detokenize
(
token
))
b
.
WriteString
(
llm
.
detokenize
(
token
))
...
@@ -293,6 +290,9 @@ func (llm *LLM) detokenize(tokens ...C.llama_token) string {
...
@@ -293,6 +290,9 @@ func (llm *LLM) detokenize(tokens ...C.llama_token) string {
}
}
func
(
llm
*
LLM
)
next
()
(
C
.
llama_token
,
error
)
{
func
(
llm
*
LLM
)
next
()
(
C
.
llama_token
,
error
)
{
llm
.
mu
.
Lock
()
defer
llm
.
mu
.
Unlock
()
if
len
(
llm
.
embd
)
>=
llm
.
NumCtx
{
if
len
(
llm
.
embd
)
>=
llm
.
NumCtx
{
numLeft
:=
(
llm
.
NumCtx
-
llm
.
NumKeep
)
/
2
numLeft
:=
(
llm
.
NumCtx
-
llm
.
NumKeep
)
/
2
truncated
:=
llm
.
embd
[
:
llm
.
NumKeep
]
truncated
:=
llm
.
embd
[
:
llm
.
NumKeep
]
...
@@ -304,6 +304,10 @@ func (llm *LLM) next() (C.llama_token, error) {
...
@@ -304,6 +304,10 @@ func (llm *LLM) next() (C.llama_token, error) {
}
}
for
{
for
{
if
llm
.
gc
{
return
0
,
io
.
EOF
}
if
llm
.
cursor
>=
len
(
llm
.
embd
)
{
if
llm
.
cursor
>=
len
(
llm
.
embd
)
{
break
break
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment