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
35b89b2e
Commit
35b89b2e
authored
Jul 03, 2024
by
Michael Yang
Browse files
rfc: dynamic environ lookup
parent
5784c053
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
26 deletions
+29
-26
app/lifecycle/logging.go
app/lifecycle/logging.go
+1
-1
envconfig/config.go
envconfig/config.go
+16
-12
envconfig/config_test.go
envconfig/config_test.go
+6
-7
gpu/gpu.go
gpu/gpu.go
+1
-1
llm/memory_test.go
llm/memory_test.go
+2
-2
llm/server.go
llm/server.go
+2
-2
server/routes.go
server/routes.go
+1
-1
No files found.
app/lifecycle/logging.go
View file @
35b89b2e
...
...
@@ -14,7 +14,7 @@ import (
func
InitLogging
()
{
level
:=
slog
.
LevelInfo
if
envconfig
.
Debug
{
if
envconfig
.
Debug
()
{
level
=
slog
.
LevelDebug
}
...
...
envconfig/config.go
View file @
35b89b2e
...
...
@@ -26,11 +26,24 @@ func (o OllamaHost) String() string {
var
ErrInvalidHostPort
=
errors
.
New
(
"invalid port specified in OLLAMA_HOST"
)
// Debug returns true if the OLLAMA_DEBUG environment variable is set to a truthy value.
func
Debug
()
bool
{
if
s
:=
clean
(
"OLLAMA_DEBUG"
);
s
!=
""
{
b
,
err
:=
strconv
.
ParseBool
(
s
)
if
err
!=
nil
{
// non-empty value is truthy
return
true
}
return
b
}
return
false
}
var
(
// Set via OLLAMA_ORIGINS in the environment
AllowOrigins
[]
string
// Set via OLLAMA_DEBUG in the environment
Debug
bool
// Experimental flash attention
FlashAttention
bool
// Set via OLLAMA_HOST in the environment
...
...
@@ -80,7 +93,7 @@ type EnvVar struct {
func
AsMap
()
map
[
string
]
EnvVar
{
ret
:=
map
[
string
]
EnvVar
{
"OLLAMA_DEBUG"
:
{
"OLLAMA_DEBUG"
,
Debug
,
"Show additional debug information (e.g. OLLAMA_DEBUG=1)"
},
"OLLAMA_DEBUG"
:
{
"OLLAMA_DEBUG"
,
Debug
()
,
"Show additional debug information (e.g. OLLAMA_DEBUG=1)"
},
"OLLAMA_FLASH_ATTENTION"
:
{
"OLLAMA_FLASH_ATTENTION"
,
FlashAttention
,
"Enabled flash attention"
},
"OLLAMA_HOST"
:
{
"OLLAMA_HOST"
,
Host
,
"IP Address for the ollama server (default 127.0.0.1:11434)"
},
"OLLAMA_KEEP_ALIVE"
:
{
"OLLAMA_KEEP_ALIVE"
,
KeepAlive
,
"The duration that models stay loaded in memory (default
\"
5m
\"
)"
},
...
...
@@ -137,15 +150,6 @@ func init() {
}
func
LoadConfig
()
{
if
debug
:=
clean
(
"OLLAMA_DEBUG"
);
debug
!=
""
{
d
,
err
:=
strconv
.
ParseBool
(
debug
)
if
err
==
nil
{
Debug
=
d
}
else
{
Debug
=
true
}
}
if
fa
:=
clean
(
"OLLAMA_FLASH_ATTENTION"
);
fa
!=
""
{
d
,
err
:=
strconv
.
ParseBool
(
fa
)
if
err
==
nil
{
...
...
envconfig/config_test.go
View file @
35b89b2e
...
...
@@ -12,16 +12,15 @@ import (
)
func
TestConfig
(
t
*
testing
.
T
)
{
Debug
=
false
// Reset whatever was loaded in init()
t
.
Setenv
(
"OLLAMA_DEBUG"
,
""
)
LoadConfi
g
()
require
.
False
(
t
,
Debug
)
require
.
False
(
t
,
Debu
g
()
)
t
.
Setenv
(
"OLLAMA_DEBUG"
,
"false"
)
LoadConfi
g
()
require
.
False
(
t
,
Debug
)
require
.
False
(
t
,
Debu
g
()
)
t
.
Setenv
(
"OLLAMA_DEBUG"
,
"1"
)
LoadConfi
g
()
require
.
True
(
t
,
Debug
)
require
.
True
(
t
,
Debu
g
()
)
t
.
Setenv
(
"OLLAMA_FLASH_ATTENTION"
,
"1"
)
LoadConfig
()
require
.
True
(
t
,
FlashAttention
)
...
...
gpu/gpu.go
View file @
35b89b2e
...
...
@@ -611,7 +611,7 @@ func LoadOneapiMgmt(oneapiLibPaths []string) (int, *C.oneapi_handle_t, string) {
}
func
getVerboseState
()
C
.
uint16_t
{
if
envconfig
.
Debug
{
if
envconfig
.
Debug
()
{
return
C
.
uint16_t
(
1
)
}
return
C
.
uint16_t
(
0
)
...
...
llm/memory_test.go
View file @
35b89b2e
...
...
@@ -8,14 +8,14 @@ import (
"testing"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/gpu"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestEstimateGPULayers
(
t
*
testing
.
T
)
{
envconfig
.
Debug
=
true
t
.
Setenv
(
"OLLAMA_DEBUG"
,
"1"
)
modelName
:=
"dummy"
f
,
err
:=
os
.
CreateTemp
(
t
.
TempDir
(),
modelName
)
require
.
NoError
(
t
,
err
)
...
...
llm/server.go
View file @
35b89b2e
...
...
@@ -195,7 +195,7 @@ func NewLlamaServer(gpus gpu.GpuInfoList, model string, ggml *GGML, adapters, pr
params
=
append
(
params
,
"--n-gpu-layers"
,
fmt
.
Sprintf
(
"%d"
,
opts
.
NumGPU
))
}
if
envconfig
.
Debug
{
if
envconfig
.
Debug
()
{
params
=
append
(
params
,
"--verbose"
)
}
...
...
@@ -381,7 +381,7 @@ func NewLlamaServer(gpus gpu.GpuInfoList, model string, ggml *GGML, adapters, pr
}
slog
.
Info
(
"starting llama server"
,
"cmd"
,
s
.
cmd
.
String
())
if
envconfig
.
Debug
{
if
envconfig
.
Debug
()
{
filteredEnv
:=
[]
string
{}
for
_
,
ev
:=
range
s
.
cmd
.
Env
{
if
strings
.
HasPrefix
(
ev
,
"CUDA_"
)
||
...
...
server/routes.go
View file @
35b89b2e
...
...
@@ -1093,7 +1093,7 @@ func (s *Server) GenerateRoutes() http.Handler {
func
Serve
(
ln
net
.
Listener
)
error
{
level
:=
slog
.
LevelInfo
if
envconfig
.
Debug
{
if
envconfig
.
Debug
()
{
level
=
slog
.
LevelDebug
}
...
...
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