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
eaed6f8c
Commit
eaed6f8c
authored
Jan 12, 2024
by
Michael Yang
Browse files
add max context length check
parent
565f8a3c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
0 deletions
+15
-0
llm/ggml.go
llm/ggml.go
+1
-0
llm/gguf.go
llm/gguf.go
+9
-0
llm/llm.go
llm/llm.go
+5
-0
No files found.
llm/ggml.go
View file @
eaed6f8c
...
@@ -83,6 +83,7 @@ type model interface {
...
@@ -83,6 +83,7 @@ type model interface {
NumEmbed
()
uint32
NumEmbed
()
uint32
NumHead
()
uint32
NumHead
()
uint32
NumHeadKv
()
uint32
NumHeadKv
()
uint32
NumCtx
()
uint32
}
}
type
container
interface
{
type
container
interface
{
...
...
llm/gguf.go
View file @
eaed6f8c
...
@@ -308,6 +308,15 @@ func (llm *ggufModel) NumHeadKv() uint32 {
...
@@ -308,6 +308,15 @@ func (llm *ggufModel) NumHeadKv() uint32 {
return
value
.
(
uint32
)
return
value
.
(
uint32
)
}
}
func
(
llm
*
ggufModel
)
NumCtx
()
uint32
{
value
,
exists
:=
llm
.
kv
[
fmt
.
Sprintf
(
"%s.context_length"
,
llm
.
ModelFamily
())]
if
!
exists
{
return
0
}
return
value
.
(
uint32
)
}
func
(
llm
*
ggufModel
)
NumGQA
()
uint32
{
func
(
llm
*
ggufModel
)
NumGQA
()
uint32
{
numHeadKv
:=
llm
.
NumHeadKv
()
numHeadKv
:=
llm
.
NumHeadKv
()
if
numHeadKv
==
0
{
if
numHeadKv
==
0
{
...
...
llm/llm.go
View file @
eaed6f8c
...
@@ -35,6 +35,11 @@ func New(workDir, model string, adapters, projectors []string, opts api.Options)
...
@@ -35,6 +35,11 @@ func New(workDir, model string, adapters, projectors []string, opts api.Options)
return
nil
,
err
return
nil
,
err
}
}
if
opts
.
NumCtx
>
int
(
ggml
.
NumCtx
())
{
log
.
Printf
(
"WARNING: requested context length is greater than model's max context length (%d > %d), using %d instead"
,
opts
.
NumCtx
,
ggml
.
NumCtx
(),
ggml
.
NumCtx
())
opts
.
NumCtx
=
int
(
ggml
.
NumCtx
())
}
if
opts
.
NumCtx
<
4
{
if
opts
.
NumCtx
<
4
{
opts
.
NumCtx
=
4
opts
.
NumCtx
=
4
}
}
...
...
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