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
b9495ea1
Commit
b9495ea1
authored
Nov 30, 2023
by
Michael Yang
Browse files
load projectors
parent
409bb967
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
15 deletions
+23
-15
llm/llama.go
llm/llama.go
+6
-1
llm/llm.go
llm/llm.go
+3
-3
server/images.go
server/images.go
+13
-10
server/routes.go
server/routes.go
+1
-1
No files found.
llm/llama.go
View file @
b9495ea1
...
@@ -325,7 +325,7 @@ func (w *StatusWriter) Write(b []byte) (int, error) {
...
@@ -325,7 +325,7 @@ func (w *StatusWriter) Write(b []byte) (int, error) {
return
os
.
Stderr
.
Write
(
b
)
return
os
.
Stderr
.
Write
(
b
)
}
}
func
newLlama
(
model
string
,
adapters
[]
string
,
runners
[]
ModelRunner
,
numLayers
int64
,
opts
api
.
Options
)
(
*
llama
,
error
)
{
func
newLlama
(
model
string
,
adapters
,
projectors
[]
string
,
runners
[]
ModelRunner
,
numLayers
int64
,
opts
api
.
Options
)
(
*
llama
,
error
)
{
fileInfo
,
err
:=
os
.
Stat
(
model
)
fileInfo
,
err
:=
os
.
Stat
(
model
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -365,6 +365,11 @@ func newLlama(model string, adapters []string, runners []ModelRunner, numLayers
...
@@ -365,6 +365,11 @@ func newLlama(model string, adapters []string, runners []ModelRunner, numLayers
params
=
append
(
params
,
"--lora"
,
adapters
[
0
])
params
=
append
(
params
,
"--lora"
,
adapters
[
0
])
}
}
if
len
(
projectors
)
>
0
{
// TODO: applying multiple projectors is not supported by the llama.cpp server yet
params
=
append
(
params
,
"--mmproj"
,
projectors
[
0
])
}
if
opts
.
NumThread
>
0
{
if
opts
.
NumThread
>
0
{
params
=
append
(
params
,
"--threads"
,
fmt
.
Sprintf
(
"%d"
,
opts
.
NumThread
))
params
=
append
(
params
,
"--threads"
,
fmt
.
Sprintf
(
"%d"
,
opts
.
NumThread
))
}
}
...
...
llm/llm.go
View file @
b9495ea1
...
@@ -23,7 +23,7 @@ type LLM interface {
...
@@ -23,7 +23,7 @@ type LLM interface {
Ping
(
context
.
Context
)
error
Ping
(
context
.
Context
)
error
}
}
func
New
(
workDir
,
model
string
,
adapters
[]
string
,
opts
api
.
Options
)
(
LLM
,
error
)
{
func
New
(
workDir
,
model
string
,
adapters
,
projectors
[]
string
,
opts
api
.
Options
)
(
LLM
,
error
)
{
if
_
,
err
:=
os
.
Stat
(
model
);
err
!=
nil
{
if
_
,
err
:=
os
.
Stat
(
model
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -82,9 +82,9 @@ func New(workDir, model string, adapters []string, opts api.Options) (LLM, error
...
@@ -82,9 +82,9 @@ func New(workDir, model string, adapters []string, opts api.Options) (LLM, error
opts
.
NumGQA
=
0
opts
.
NumGQA
=
0
opts
.
RopeFrequencyBase
=
0.0
opts
.
RopeFrequencyBase
=
0.0
opts
.
RopeFrequencyScale
=
0.0
opts
.
RopeFrequencyScale
=
0.0
return
newLlama
(
model
,
adapters
,
chooseRunners
(
workDir
,
"gguf"
),
ggml
.
NumLayers
(),
opts
)
return
newLlama
(
model
,
adapters
,
projectors
,
chooseRunners
(
workDir
,
"gguf"
),
ggml
.
NumLayers
(),
opts
)
case
"ggml"
,
"ggmf"
,
"ggjt"
,
"ggla"
:
case
"ggml"
,
"ggmf"
,
"ggjt"
,
"ggla"
:
return
newLlama
(
model
,
adapters
,
chooseRunners
(
workDir
,
"ggml"
),
ggml
.
NumLayers
(),
opts
)
return
newLlama
(
model
,
adapters
,
projectors
,
chooseRunners
(
workDir
,
"ggml"
),
ggml
.
NumLayers
(),
opts
)
default
:
default
:
return
nil
,
fmt
.
Errorf
(
"unknown ggml type: %s"
,
ggml
.
ModelFamily
())
return
nil
,
fmt
.
Errorf
(
"unknown ggml type: %s"
,
ggml
.
ModelFamily
())
}
}
...
...
server/images.go
View file @
b9495ea1
...
@@ -35,16 +35,17 @@ type RegistryOptions struct {
...
@@ -35,16 +35,17 @@ type RegistryOptions struct {
}
}
type
Model
struct
{
type
Model
struct
{
Name
string
`json:"name"`
Name
string
`json:"name"`
ShortName
string
ShortName
string
ModelPath
string
ModelPath
string
OriginalModel
string
OriginalModel
string
AdapterPaths
[]
string
AdapterPaths
[]
string
Template
string
ProjectorPaths
[]
string
System
string
Template
string
License
[]
string
System
string
Digest
string
License
[]
string
Options
map
[
string
]
interface
{}
Digest
string
Options
map
[
string
]
interface
{}
}
}
type
PromptVars
struct
{
type
PromptVars
struct
{
...
@@ -250,6 +251,8 @@ func GetModel(name string) (*Model, error) {
...
@@ -250,6 +251,8 @@ func GetModel(name string) (*Model, error) {
log
.
Print
(
"WARNING: model contains embeddings, but embeddings in modelfiles have been deprecated and will be ignored."
)
log
.
Print
(
"WARNING: model contains embeddings, but embeddings in modelfiles have been deprecated and will be ignored."
)
case
"application/vnd.ollama.image.adapter"
:
case
"application/vnd.ollama.image.adapter"
:
model
.
AdapterPaths
=
append
(
model
.
AdapterPaths
,
filename
)
model
.
AdapterPaths
=
append
(
model
.
AdapterPaths
,
filename
)
case
"application/vnd.ollama.image.projector"
:
model
.
ProjectorPaths
=
append
(
model
.
ProjectorPaths
,
filename
)
case
"application/vnd.ollama.image.template"
:
case
"application/vnd.ollama.image.template"
:
bts
,
err
:=
os
.
ReadFile
(
filename
)
bts
,
err
:=
os
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
server/routes.go
View file @
b9495ea1
...
@@ -105,7 +105,7 @@ func load(c *gin.Context, modelName string, reqOpts map[string]interface{}, sess
...
@@ -105,7 +105,7 @@ func load(c *gin.Context, modelName string, reqOpts map[string]interface{}, sess
loaded
.
Options
=
nil
loaded
.
Options
=
nil
}
}
llmRunner
,
err
:=
llm
.
New
(
workDir
,
model
.
ModelPath
,
model
.
AdapterPaths
,
opts
)
llmRunner
,
err
:=
llm
.
New
(
workDir
,
model
.
ModelPath
,
model
.
AdapterPaths
,
model
.
ProjectorPaths
,
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
// some older models are not compatible with newer versions of llama.cpp
// some older models are not compatible with newer versions of llama.cpp
// show a generalized compatibility error until there is a better way to
// show a generalized compatibility error until there is a better way to
...
...
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