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
66fe77f0
"vscode:/vscode.git/clone" did not exist on "213ffdb54899cd82a4ecf911f217542a1b37d2fc"
Commit
66fe77f0
authored
Jul 03, 2024
by
Michael Yang
Browse files
models
parent
d1a5227c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
27 deletions
+19
-27
envconfig/config.go
envconfig/config.go
+16
-18
server/modelpath.go
server/modelpath.go
+3
-9
No files found.
envconfig/config.go
View file @
66fe77f0
...
...
@@ -99,6 +99,21 @@ func Origins() (origins []string) {
return
origins
}
// Models returns the path to the models directory. Models directory can be configured via the OLLAMA_MODELS environment variable.
// Default is $HOME/.ollama/models
func
Models
()
string
{
if
s
,
ok
:=
os
.
LookupEnv
(
"OLLAMA_MODELS"
);
ok
{
return
s
}
home
,
err
:=
os
.
UserHomeDir
()
if
err
!=
nil
{
panic
(
err
)
}
return
filepath
.
Join
(
home
,
".ollama"
,
"models"
)
}
var
(
// Experimental flash attention
FlashAttention
bool
...
...
@@ -154,7 +169,7 @@ func AsMap() map[string]EnvVar {
"OLLAMA_LLM_LIBRARY"
:
{
"OLLAMA_LLM_LIBRARY"
,
LLMLibrary
,
"Set LLM library to bypass autodetection"
},
"OLLAMA_MAX_LOADED_MODELS"
:
{
"OLLAMA_MAX_LOADED_MODELS"
,
MaxRunners
,
"Maximum number of loaded models per GPU"
},
"OLLAMA_MAX_QUEUE"
:
{
"OLLAMA_MAX_QUEUE"
,
MaxQueuedRequests
,
"Maximum number of queued requests"
},
"OLLAMA_MODELS"
:
{
"OLLAMA_MODELS"
,
Models
Dir
,
"The path to the models directory"
},
"OLLAMA_MODELS"
:
{
"OLLAMA_MODELS"
,
Models
()
,
"The path to the models directory"
},
"OLLAMA_NOHISTORY"
:
{
"OLLAMA_NOHISTORY"
,
NoHistory
,
"Do not preserve readline history"
},
"OLLAMA_NOPRUNE"
:
{
"OLLAMA_NOPRUNE"
,
NoPrune
,
"Do not prune model blobs on startup"
},
"OLLAMA_NUM_PARALLEL"
:
{
"OLLAMA_NUM_PARALLEL"
,
NumParallel
,
"Maximum number of parallel requests"
},
...
...
@@ -295,12 +310,6 @@ func LoadConfig() {
loadKeepAlive
(
ka
)
}
var
err
error
ModelsDir
,
err
=
getModelsDir
()
if
err
!=
nil
{
slog
.
Error
(
"invalid setting"
,
"OLLAMA_MODELS"
,
ModelsDir
,
"error"
,
err
)
}
if
set
,
err
:=
strconv
.
ParseBool
(
clean
(
"OLLAMA_INTEL_GPU"
));
err
==
nil
{
IntelGpu
=
set
}
...
...
@@ -312,17 +321,6 @@ func LoadConfig() {
HsaOverrideGfxVersion
=
clean
(
"HSA_OVERRIDE_GFX_VERSION"
)
}
func
getModelsDir
()
(
string
,
error
)
{
if
models
,
exists
:=
os
.
LookupEnv
(
"OLLAMA_MODELS"
);
exists
{
return
models
,
nil
}
home
,
err
:=
os
.
UserHomeDir
()
if
err
!=
nil
{
return
""
,
err
}
return
filepath
.
Join
(
home
,
".ollama"
,
"models"
),
nil
}
func
loadKeepAlive
(
ka
string
)
{
v
,
err
:=
strconv
.
Atoi
(
ka
)
if
err
!=
nil
{
...
...
server/modelpath.go
View file @
66fe77f0
...
...
@@ -105,9 +105,7 @@ func (mp ModelPath) GetShortTagname() string {
// GetManifestPath returns the path to the manifest file for the given model path, it is up to the caller to create the directory if it does not exist.
func
(
mp
ModelPath
)
GetManifestPath
()
(
string
,
error
)
{
dir
:=
envconfig
.
ModelsDir
return
filepath
.
Join
(
dir
,
"manifests"
,
mp
.
Registry
,
mp
.
Namespace
,
mp
.
Repository
,
mp
.
Tag
),
nil
return
filepath
.
Join
(
envconfig
.
Models
(),
"manifests"
,
mp
.
Registry
,
mp
.
Namespace
,
mp
.
Repository
,
mp
.
Tag
),
nil
}
func
(
mp
ModelPath
)
BaseURL
()
*
url
.
URL
{
...
...
@@ -118,9 +116,7 @@ func (mp ModelPath) BaseURL() *url.URL {
}
func
GetManifestPath
()
(
string
,
error
)
{
dir
:=
envconfig
.
ModelsDir
path
:=
filepath
.
Join
(
dir
,
"manifests"
)
path
:=
filepath
.
Join
(
envconfig
.
Models
(),
"manifests"
)
if
err
:=
os
.
MkdirAll
(
path
,
0
o755
);
err
!=
nil
{
return
""
,
err
}
...
...
@@ -129,8 +125,6 @@ func GetManifestPath() (string, error) {
}
func
GetBlobsPath
(
digest
string
)
(
string
,
error
)
{
dir
:=
envconfig
.
ModelsDir
// only accept actual sha256 digests
pattern
:=
"^sha256[:-][0-9a-fA-F]{64}$"
re
:=
regexp
.
MustCompile
(
pattern
)
...
...
@@ -140,7 +134,7 @@ func GetBlobsPath(digest string) (string, error) {
}
digest
=
strings
.
ReplaceAll
(
digest
,
":"
,
"-"
)
path
:=
filepath
.
Join
(
dir
,
"blobs"
,
digest
)
path
:=
filepath
.
Join
(
envconfig
.
Models
()
,
"blobs"
,
digest
)
dirPath
:=
filepath
.
Dir
(
path
)
if
digest
==
""
{
dirPath
=
path
...
...
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