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
fb92b617
Unverified
Commit
fb92b617
authored
Sep 02, 2025
by
Michael Yang
Committed by
GitHub
Sep 02, 2025
Browse files
logutil: add Trace and TraceContext helpers (#12110)
parent
8149a3c8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
22 additions
and
18 deletions
+22
-18
harmony/harmonyparser.go
harmony/harmonyparser.go
+2
-3
llm/server.go
llm/server.go
+1
-1
logutil/logutil.go
logutil/logutil.go
+9
-0
ml/backend/ggml/ggml.go
ml/backend/ggml/ggml.go
+3
-3
model/bytepairencoding.go
model/bytepairencoding.go
+2
-3
model/model.go
model/model.go
+1
-3
model/sentencepiece.go
model/sentencepiece.go
+4
-5
No files found.
harmony/harmonyparser.go
View file @
fb92b617
package
harmony
import
(
"context"
"fmt"
"log/slog"
"strings"
...
...
@@ -292,7 +291,7 @@ func (h *HarmonyMessageHandler) AddContent(content string, toolParser *HarmonyTo
for
_
,
event
:=
range
events
{
switch
event
:=
event
.
(
type
)
{
case
HarmonyEventHeaderComplete
:
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"harmony event header complete"
,
"header"
,
event
.
Header
)
logutil
.
Trace
(
"harmony event header complete"
,
"header"
,
event
.
Header
)
switch
event
.
Header
.
Channel
{
case
"analysis"
:
if
event
.
Header
.
Recipient
!=
""
{
...
...
@@ -315,7 +314,7 @@ func (h *HarmonyMessageHandler) AddContent(content string, toolParser *HarmonyTo
h
.
state
=
harmonyMessageState_Normal
}
case
HarmonyEventContentEmitted
:
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"harmony event content"
,
"content"
,
event
.
Content
,
"state"
,
h
.
state
)
logutil
.
Trace
(
"harmony event content"
,
"content"
,
event
.
Content
,
"state"
,
h
.
state
)
if
h
.
state
==
harmonyMessageState_Normal
{
contentSb
.
WriteString
(
event
.
Content
)
}
else
if
h
.
state
==
harmonyMessageState_Thinking
{
...
...
llm/server.go
View file @
fb92b617
...
...
@@ -865,7 +865,7 @@ func (s *ollamaServer) createLayout(systemInfo discover.SystemInfo, systemGPUs d
}
layers
[
i
]
+=
memory
.
CPU
.
Weights
[
i
]
.
Size
layers
[
i
]
+=
memory
.
CPU
.
Cache
[
i
]
.
Size
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"layer to assign"
,
"layer"
,
i
,
"size"
,
format
.
HumanBytes2
(
layers
[
i
]))
logutil
.
Trace
(
"layer to assign"
,
"layer"
,
i
,
"size"
,
format
.
HumanBytes2
(
layers
[
i
]))
}
gpuLayers
:=
ml
.
GPULayersList
{}
...
...
logutil/logutil.go
View file @
fb92b617
package
logutil
import
(
"context"
"io"
"log/slog"
"path/filepath"
...
...
@@ -27,3 +28,11 @@ func NewLogger(w io.Writer, level slog.Level) *slog.Logger {
},
}))
}
func
Trace
(
msg
string
,
args
...
any
)
{
slog
.
Log
(
context
.
TODO
(),
LevelTrace
,
msg
,
args
...
)
}
func
TraceContext
(
ctx
context
.
Context
,
msg
string
,
args
...
any
)
{
slog
.
Log
(
ctx
,
LevelTrace
,
msg
,
args
...
)
}
ml/backend/ggml/ggml.go
View file @
fb92b617
...
...
@@ -271,7 +271,7 @@ func New(modelPath string, params ml.BackendParams) (ml.Backend, error) {
tt
:=
C
.
ggml_new_tensor
(
ctxs
[
bt
],
kind
,
C
.
int
(
len
(
t
.
source
.
Shape
)),
(
*
C
.
int64_t
)(
unsafe
.
Pointer
(
&
t
.
source
.
Shape
[
0
])))
C
.
ggml_set_name
(
tt
,
cname
)
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"created tensor"
,
"name"
,
name
,
"shape"
,
t
.
source
.
Shape
,
"dtype"
,
t
.
source
.
Kind
,
"buffer_type"
,
C
.
GoString
(
C
.
ggml_backend_buft_name
(
bt
)))
logutil
.
Trace
(
"created tensor"
,
"name"
,
name
,
"shape"
,
t
.
source
.
Shape
,
"dtype"
,
t
.
source
.
Kind
,
"buffer_type"
,
C
.
GoString
(
C
.
ggml_backend_buft_name
(
bt
)))
size
:=
pad
(
C
.
ggml_backend_buft_get_alloc_size
(
bt
,
tt
),
C
.
ggml_backend_buft_get_alignment
(
bt
))
if
layer
==
-
1
{
...
...
@@ -378,7 +378,7 @@ func New(modelPath string, params ml.BackendParams) (ml.Backend, error) {
}
for
bs
:=
range
maps
.
Values
(
bbs
)
{
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"model weights"
,
"buffer"
,
C
.
GoString
(
C
.
ggml_backend_buffer_name
(
bs
)),
logutil
.
Trace
(
"model weights"
,
"buffer"
,
C
.
GoString
(
C
.
ggml_backend_buffer_name
(
bs
)),
"size"
,
format
.
HumanBytes2
(
uint64
(
C
.
ggml_backend_buffer_get_size
(
bs
))))
}
...
...
@@ -811,7 +811,7 @@ func (c *Context) Reserve() {
}
}
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"compute graph"
,
"backend"
,
C
.
GoString
(
C
.
ggml_backend_name
(
c
.
b
.
schedBackends
[
i
])),
logutil
.
Trace
(
"compute graph"
,
"backend"
,
C
.
GoString
(
C
.
ggml_backend_name
(
c
.
b
.
schedBackends
[
i
])),
"buffer_type"
,
C
.
GoString
(
C
.
ggml_backend_buft_name
(
c
.
b
.
schedBufts
[
i
])),
"size"
,
format
.
HumanBytes2
(
uint64
(
bufferStatus
.
size
)))
}
...
...
model/bytepairencoding.go
View file @
fb92b617
...
...
@@ -2,7 +2,6 @@ package model
import
(
"cmp"
"context"
"fmt"
"iter"
"log/slog"
...
...
@@ -202,7 +201,7 @@ func (bpe BytePairEncoding) Encode(s string, addSpecial bool) ([]int32, error) {
}
}
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"encoded"
,
"string"
,
s
,
"ids"
,
ids
)
logutil
.
Trace
(
"encoded"
,
"string"
,
s
,
"ids"
,
ids
)
if
addSpecial
&&
len
(
ids
)
>
0
{
ids
=
bpe
.
vocab
.
addSpecials
(
ids
)
...
...
@@ -243,6 +242,6 @@ func (bpe BytePairEncoding) Decode(ids []int32) (string, error) {
}
}
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"decoded"
,
"string"
,
sb
.
String
(),
"from"
,
lazyIdsString
{
ids
:
ids
})
logutil
.
Trace
(
"decoded"
,
"string"
,
sb
.
String
(),
"from"
,
lazyIdsString
{
ids
:
ids
})
return
sb
.
String
(),
nil
}
model/model.go
View file @
fb92b617
package
model
import
(
"context"
"errors"
"fmt"
_
"image/jpeg"
_
"image/png"
"log/slog"
"os"
"reflect"
"strconv"
...
...
@@ -198,7 +196,7 @@ func populateFields(base Base, v reflect.Value, tags ...Tag) reflect.Value {
names
:=
fn
(
tagsCopy
)
for
_
,
name
:=
range
names
{
if
tensor
:=
base
.
Backend
()
.
Get
(
strings
.
Join
(
name
,
"."
));
tensor
!=
nil
{
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"found tensor"
,
""
,
tensor
)
logutil
.
Trace
(
"found tensor"
,
""
,
tensor
)
vv
.
Set
(
reflect
.
ValueOf
(
tensor
))
break
}
...
...
model/sentencepiece.go
View file @
fb92b617
...
...
@@ -2,7 +2,6 @@ package model
import
(
"container/heap"
"context"
"fmt"
"log/slog"
"strconv"
...
...
@@ -25,7 +24,7 @@ func (spm SentencePieceModel) Vocabulary() *Vocabulary {
}
func
NewSentencePieceModel
(
vocab
*
Vocabulary
)
SentencePieceModel
{
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"Tokens"
,
"num tokens"
,
len
(
vocab
.
Values
),
"vals"
,
vocab
.
Values
[
:
5
],
"scores"
,
vocab
.
Scores
[
:
5
],
"types"
,
vocab
.
Types
[
:
5
])
logutil
.
Trace
(
"Tokens"
,
"num tokens"
,
len
(
vocab
.
Values
),
"vals"
,
vocab
.
Values
[
:
5
],
"scores"
,
vocab
.
Scores
[
:
5
],
"types"
,
vocab
.
Types
[
:
5
])
counter
:=
map
[
int
]
int
{}
var
maxTokenLen
int
...
...
@@ -39,7 +38,7 @@ func NewSentencePieceModel(vocab *Vocabulary) SentencePieceModel {
}
}
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"Token counts"
,
"normal"
,
counter
[
TOKEN_TYPE_NORMAL
],
"unknown"
,
counter
[
TOKEN_TYPE_UNKNOWN
],
"control"
,
counter
[
TOKEN_TYPE_CONTROL
],
logutil
.
Trace
(
"Token counts"
,
"normal"
,
counter
[
TOKEN_TYPE_NORMAL
],
"unknown"
,
counter
[
TOKEN_TYPE_UNKNOWN
],
"control"
,
counter
[
TOKEN_TYPE_CONTROL
],
"user defined"
,
counter
[
TOKEN_TYPE_USER_DEFINED
],
"unused"
,
counter
[
TOKEN_TYPE_UNUSED
],
"byte"
,
counter
[
TOKEN_TYPE_BYTE
],
"max token len"
,
maxTokenLen
)
...
...
@@ -182,7 +181,7 @@ func (spm SentencePieceModel) Encode(s string, addSpecial bool) ([]int32, error)
}
}
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"encoded"
,
"string"
,
s
,
"ids"
,
ids
)
logutil
.
Trace
(
"encoded"
,
"string"
,
s
,
"ids"
,
ids
)
if
addSpecial
&&
len
(
ids
)
>
0
{
ids
=
spm
.
vocab
.
addSpecials
(
ids
)
...
...
@@ -246,6 +245,6 @@ func (spm SentencePieceModel) Decode(ids []int32) (string, error) {
}
}
slog
.
Log
(
context
.
TODO
(),
logutil
.
Level
Trace
,
"decoded"
,
"ids"
,
ids
,
"string"
,
sb
.
String
())
logutil
.
Trace
(
"decoded"
,
"ids"
,
ids
,
"string"
,
sb
.
String
())
return
sb
.
String
(),
nil
}
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