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
a59f6652
Commit
a59f6652
authored
Feb 26, 2025
by
Michael Yang
Browse files
ml/backend/ggml: fix debug logging
parent
688925ac
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
34 deletions
+21
-34
llama/llama.go
llama/llama.go
+15
-22
ml/backend/ggml/ggml/src/ggml.go
ml/backend/ggml/ggml/src/ggml.go
+6
-11
runner/llamarunner/runner.go
runner/llamarunner/runner.go
+0
-1
No files found.
llama/llama.go
View file @
a59f6652
...
@@ -37,23 +37,36 @@ COMPILER inline get_compiler() {
...
@@ -37,23 +37,36 @@ COMPILER inline get_compiler() {
import
"C"
import
"C"
import
(
import
(
"context"
_
"embed"
_
"embed"
"errors"
"errors"
"fmt"
"fmt"
"log/slog"
"os"
"os"
"runtime"
"runtime"
"runtime/cgo"
"runtime/cgo"
"slices"
"slices"
"strings"
"strings"
"sync/atomic"
"unsafe"
"unsafe"
_
"github.com/ollama/ollama/llama/llama.cpp/common"
_
"github.com/ollama/ollama/llama/llama.cpp/common"
_
"github.com/ollama/ollama/llama/llama.cpp/examples/llava"
_
"github.com/ollama/ollama/llama/llama.cpp/examples/llava"
_
"github.com/ollama/ollama/llama/llama.cpp/src"
_
"github.com/ollama/ollama/llama/llama.cpp/src"
"github.com/ollama/ollama/ml/backend/ggml/ggml/src"
ggml
"github.com/ollama/ollama/ml/backend/ggml/ggml/src"
)
)
func
init
()
{
C
.
llama_log_set
(
C
.
ggml_log_callback
(
C
.
llamaLog
),
nil
)
}
//export llamaLog
func
llamaLog
(
level
C
.
int
,
text
*
C
.
char
,
_
unsafe
.
Pointer
)
{
// slog levels zeros INFO and are multiples of 4
if
slog
.
Default
()
.
Enabled
(
context
.
TODO
(),
slog
.
Level
(
int
(
level
-
C
.
GGML_LOG_LEVEL_INFO
)
*
4
))
{
fmt
.
Fprint
(
os
.
Stderr
,
C
.
GoString
(
text
))
}
}
func
BackendInit
()
{
func
BackendInit
()
{
ggml
.
OnceLoad
()
ggml
.
OnceLoad
()
C
.
llama_backend_init
()
C
.
llama_backend_init
()
...
@@ -72,26 +85,6 @@ func PrintSystemInfo() string {
...
@@ -72,26 +85,6 @@ func PrintSystemInfo() string {
return
C
.
GoString
(
C
.
llama_print_system_info
())
+
compiler
return
C
.
GoString
(
C
.
llama_print_system_info
())
+
compiler
}
}
var
logLevel
atomic
.
Int32
func
init
()
{
logLevel
.
Store
(
int32
(
C
.
GGML_LOG_LEVEL_INFO
))
C
.
llama_log_set
((
C
.
ggml_log_callback
)(
C
.
llamaLog
),
nil
)
}
func
EnableDebug
()
{
logLevel
.
Store
(
int32
(
C
.
GGML_LOG_LEVEL_DEBUG
))
}
//export llamaLog
func
llamaLog
(
level
int32
,
text
*
C
.
char
,
_
unsafe
.
Pointer
)
{
if
level
<
logLevel
.
Load
()
{
return
}
fmt
.
Fprint
(
os
.
Stderr
,
C
.
GoString
(
text
))
}
func
GetModelArch
(
modelPath
string
)
(
string
,
error
)
{
func
GetModelArch
(
modelPath
string
)
(
string
,
error
)
{
mp
:=
C
.
CString
(
modelPath
)
mp
:=
C
.
CString
(
modelPath
)
defer
C
.
free
(
unsafe
.
Pointer
(
mp
))
defer
C
.
free
(
unsafe
.
Pointer
(
mp
))
...
...
ml/backend/ggml/ggml/src/ggml.go
View file @
a59f6652
...
@@ -10,6 +10,8 @@ package ggml
...
@@ -10,6 +10,8 @@ package ggml
import
"C"
import
"C"
import
(
import
(
"context"
"fmt"
"log/slog"
"log/slog"
"os"
"os"
"path/filepath"
"path/filepath"
...
@@ -22,21 +24,14 @@ import (
...
@@ -22,21 +24,14 @@ import (
)
)
func
init
()
{
func
init
()
{
C
.
ggml_log_set
(
(
C
.
ggml_log_callback
)
(
C
.
sink
),
nil
)
C
.
ggml_log_set
(
C
.
ggml_log_callback
(
C
.
sink
),
nil
)
}
}
//export sink
//export sink
func
sink
(
level
C
.
int
,
text
*
C
.
char
,
_
unsafe
.
Pointer
)
{
func
sink
(
level
C
.
int
,
text
*
C
.
char
,
_
unsafe
.
Pointer
)
{
msg
:=
strings
.
TrimSpace
(
C
.
GoString
(
text
))
// slog levels zeros INFO and are multiples of 4
switch
level
{
if
slog
.
Default
()
.
Enabled
(
context
.
TODO
(),
slog
.
Level
(
int
(
level
-
C
.
GGML_LOG_LEVEL_INFO
)
*
4
))
{
case
C
.
GGML_LOG_LEVEL_DEBUG
:
fmt
.
Fprint
(
os
.
Stderr
,
C
.
GoString
(
text
))
slog
.
Debug
(
msg
)
case
C
.
GGML_LOG_LEVEL_INFO
:
slog
.
Info
(
msg
)
case
C
.
GGML_LOG_LEVEL_WARN
:
slog
.
Warn
(
msg
)
case
C
.
GGML_LOG_LEVEL_ERROR
:
slog
.
Error
(
msg
)
}
}
}
}
...
...
runner/llamarunner/runner.go
View file @
a59f6652
...
@@ -915,7 +915,6 @@ func Execute(args []string) error {
...
@@ -915,7 +915,6 @@ func Execute(args []string) error {
level
:=
slog
.
LevelInfo
level
:=
slog
.
LevelInfo
if
*
verbose
{
if
*
verbose
{
level
=
slog
.
LevelDebug
level
=
slog
.
LevelDebug
llama
.
EnableDebug
()
}
}
handler
:=
slog
.
NewTextHandler
(
os
.
Stderr
,
&
slog
.
HandlerOptions
{
handler
:=
slog
.
NewTextHandler
(
os
.
Stderr
,
&
slog
.
HandlerOptions
{
Level
:
level
,
Level
:
level
,
...
...
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