This commit is contained in:
Michael Yang 2025-11-18 14:07:58 -08:00
parent f01c83ed6d
commit 4d24d8a77d
22 changed files with 58 additions and 91 deletions

View File

@ -36,6 +36,12 @@ linters:
errcheck:
exclude-functions:
- fmt.Fprintf
gocritic:
disabled-checks:
# Detects suspicious duplicated sub-expressions.
# Prone to false positives when used on cgo code
# https://github.com/go-critic/go-critic/issues/897#issuecomment-568892104
- dupSubExpr
perfsprint:
strconcat: false
concat-loop: false

View File

@ -22,6 +22,7 @@ import (
var ErrCancelled = errors.New("Cancelled")
// Cancelled refers to ErrCancelled.
//
// Deprecated: Use ErrCancelled instead.
var Cancelled = ErrCancelled

View File

@ -345,11 +345,9 @@ func GetInferenceComputer(ctx context.Context) ([]InferenceCompute, error) {
slog.Info("Matched", "inference compute", ic)
inference = append(inference, ic)
} else {
} else if len(inference) > 0 {
// Break out on first non matching line after we start matching
if len(inference) > 0 {
return inference, nil
}
return inference, nil
}
}
time.Sleep(100 * time.Millisecond)

View File

@ -384,15 +384,9 @@ func wrapLines(text string, width int) []string {
wrapped = append(wrapped, "")
} else if len(line) <= width {
wrapped = append(wrapped, line)
} else if words := strings.Fields(line); len(words) == 0 {
wrapped = append(wrapped, line)
} else {
// Word wrapping while preserving whitespace structure
words := strings.Fields(line)
if len(words) == 0 {
// Line with only whitespace
wrapped = append(wrapped, line)
continue
}
currentLine := ""
for _, word := range words {
// Check if adding this word would exceed width
@ -537,15 +531,13 @@ func (b *BrowserOpen) Execute(ctx context.Context, args map[string]any) (any, st
if err != nil {
return nil, "", fmt.Errorf("page not found for cursor %d: %w", cursor, err)
}
} else {
} else if len(b.state.Data.PageStack) != 0 {
// get last page
if len(b.state.Data.PageStack) != 0 {
pageURL := b.state.Data.PageStack[len(b.state.Data.PageStack)-1]
var err error
page, err = b.getPageFromStack(pageURL)
if err != nil {
return nil, "", fmt.Errorf("page not found for cursor %d: %w", cursor, err)
}
pageURL := b.state.Data.PageStack[len(b.state.Data.PageStack)-1]
var err error
page, err = b.getPageFromStack(pageURL)
if err != nil {
return nil, "", fmt.Errorf("page not found for cursor %d: %w", cursor, err)
}
}

View File

@ -924,10 +924,8 @@ func TestPushHandler(t *testing.T) {
t.Errorf("expected output %q, got %q", tt.expectedOutput, got)
}
}
} else {
if err == nil || !strings.Contains(err.Error(), tt.expectedError) {
t.Errorf("expected error containing %q, got %v", tt.expectedError, err)
}
} else if err == nil || !strings.Contains(err.Error(), tt.expectedError) {
t.Errorf("expected error containing %q, got %v", tt.expectedError, err)
}
})
}
@ -1014,10 +1012,8 @@ func TestListHandler(t *testing.T) {
if got := string(output); got != tt.expectedOutput {
t.Errorf("expected output:\n%s\ngot:\n%s", tt.expectedOutput, got)
}
} else {
if err == nil || !strings.Contains(err.Error(), tt.expectedError) {
t.Errorf("expected error containing %q, got %v", tt.expectedError, err)
}
} else if err == nil || !strings.Contains(err.Error(), tt.expectedError) {
t.Errorf("expected error containing %q, got %v", tt.expectedError, err)
}
})
}

View File

@ -111,7 +111,7 @@ func (m *gptossModel) Tensors(ts []Tensor) []*ggml.Tensor {
for name, mxfp4 := range mxfp4s {
dims := mxfp4.blocks.Shape()
if !strings.HasSuffix(name, ".weight") {
name = name + ".weight"
name += ".weight"
}
if strings.Contains(name, "ffn_down_exps") {
out = append(out, &ggml.Tensor{

View File

@ -226,7 +226,7 @@ func (llm *gguf) Decode(rs io.ReadSeeker) error {
Name: name,
Kind: kind,
Offset: offset,
Shape: shape[:],
Shape: shape,
}
llm.tensors = append(llm.tensors, &tensor)

View File

@ -200,9 +200,7 @@ func (s *HarmonyParser) parseHeader(raw string) HarmonyHeader {
before := raw[:channelIndex]
after := raw[channelIndex+len("<|channel|>"):]
// the channel name is `after` all the way up to the first (if any) whitespace character
idx := strings.IndexFunc(after, func(r rune) bool {
return unicode.IsSpace(r)
})
idx := strings.IndexFunc(after, unicode.IsSpace)
if idx == -1 {
idx = len(after)
}

View File

@ -982,13 +982,11 @@ nextLayer:
slog.Warn("model request too large for system", "requested", format.HumanBytes2(cpuSize), "available", format.HumanBytes2(available), "total", format.HumanBytes2(systemInfo.TotalMemory), "free", format.HumanBytes2(systemInfo.FreeMemory), "swap", format.HumanBytes2(systemInfo.FreeSwap))
return fmt.Errorf("model requires more system memory (%s) than is available (%s)", format.HumanBytes2(cpuSize), format.HumanBytes2(available))
}
} else {
if vramSize > systemInfo.TotalMemory {
// disable partial offloading when model is greater than total system memory as this
// can lead to locking up the system
s.options.NumGPU = 0
gpuLayers = ml.GPULayersList{}
}
} else if vramSize > systemInfo.TotalMemory {
// disable partial offloading when model is greater than total system memory as this
// can lead to locking up the system
s.options.NumGPU = 0
gpuLayers = ml.GPULayersList{}
}
if gpuLayers.Sum() == 0 {

View File

@ -210,10 +210,8 @@ func TestEmbeddingsMiddleware_InvalidEncodingFormat(t *testing.T) {
if !strings.Contains(errResp.Error.Message, "encoding_format") {
t.Errorf("expected error message to mention encoding_format, got %q", errResp.Error.Message)
}
} else {
if resp.Code != http.StatusOK {
t.Errorf("expected status 200, got %d: %s", resp.Code, resp.Body.String())
}
} else if resp.Code != http.StatusOK {
t.Errorf("expected status 200, got %d: %s", resp.Code, resp.Body.String())
}
})
}

View File

@ -543,12 +543,12 @@ func (d DeviceInfo) updateVisibleDevicesEnv(env map[string]string) {
}
v, existing := env[envVar]
if existing {
v = v + ","
v += ","
}
if d.FilterID != "" {
v = v + d.FilterID
v += d.FilterID
} else {
v = v + d.ID
v += d.ID
}
env[envVar] = v
}

View File

@ -143,9 +143,9 @@ func (bpe BytePairEncoding) Encode(s string, addSpecial bool) ([]int32, error) {
case r == 0x00ad:
r = 0x0143
case r <= 0x0020:
r = r + 0x0100
r += 0x0100
case r >= 0x007f && r <= 0x00a0:
r = r + 0x00a2
r += 0x00a2
}
sb.WriteRune(r)
@ -264,9 +264,9 @@ func (bpe BytePairEncoding) Decode(ids []int32) (string, error) {
case r == 0x0143:
r = 0x00ad
case r > 0x0100 && r <= 0x0120:
r = r - 0x0100
r -= 0x0100
case r > 0x0120 && r <= 0x0142:
r = r - 0x00a2
r -= 0x00a2
}
// NOTE: not using WriteRune here because it writes the UTF-8

View File

@ -146,7 +146,7 @@ func NewTextProcessor(s string) (TextProcessor, error) {
func modelForArch(c fs.Config) (Model, error) {
arch := c.Architecture()
if pooling.Type(c.Uint("pooling_type")) != pooling.TypeNone {
arch = arch + "_embed"
arch += "_embed"
}
f, ok := models[arch]

View File

@ -326,17 +326,11 @@ MESSAGE system`,
return
}
switch tt.err.(type) {
case *ParserError:
var pErr *ParserError
if errors.As(err, &pErr) {
// got the correct type of error
return
}
}
if errors.Is(err, tt.err) {
return
} else if pErr := (*ParserError)(nil); errors.As(err, &pErr) {
// got the correct type of error
return
}
t.Fatalf("unexpected error: expected: %v, actual: %v", tt.err, err)

View File

@ -61,7 +61,7 @@ func (c *ImageContext) MultimodalTokenize(llamaContext *llama.Context, data []by
return nil, nil
}
if len(data) <= 0 {
if len(data) == 0 {
return nil, errors.New("received zero length image")
}

View File

@ -995,7 +995,6 @@ func Execute(args []string) error {
log.Println("Server listening on", addr)
if err := httpServer.Serve(listener); err != nil {
log.Fatal("server error:", err)
return err
}

View File

@ -1429,7 +1429,6 @@ func Execute(args []string) error {
log.Println("Server listening on", addr)
if err := httpServer.Serve(listener); err != nil {
log.Fatal("server error:", err)
return err
}

View File

@ -30,7 +30,7 @@ func temperature(ts []token, temp float32) {
// Ensure temperature clipping near 0 to avoid numerical instability
temp = max(temp, 1e-7)
for i := range ts {
ts[i].value = ts[i].value / temp
ts[i].value /= temp
}
}

View File

@ -362,11 +362,9 @@ func (s *Server) GenerateHandler(c *gin.Context) {
if req.Think == nil {
req.Think = &api.ThinkValue{Value: true}
}
} else {
if req.Think != nil && req.Think.Bool() {
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("%q does not support thinking", req.Model)})
return
}
} else if req.Think != nil && req.Think.Bool() {
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("%q does not support thinking", req.Model)})
return
}
r, m, opts, err := s.scheduleRunner(c.Request.Context(), name.String(), caps, req.Options, req.KeepAlive)
@ -1996,11 +1994,9 @@ func (s *Server) ChatHandler(c *gin.Context) {
if req.Think == nil {
req.Think = &api.ThinkValue{Value: true}
}
} else {
if req.Think != nil && req.Think.Bool() {
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("%q does not support thinking", req.Model)})
return
}
} else if req.Think != nil && req.Think.Bool() {
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("%q does not support thinking", req.Model)})
return
}
r, m, opts, err := s.scheduleRunner(c.Request.Context(), name.String(), caps, req.Options, req.KeepAlive)

View File

@ -196,11 +196,9 @@ func TestGenerateDebugRenderOnly(t *testing.T) {
if tt.expectNumImages > 0 && response.DebugInfo.ImageCount != tt.expectNumImages {
t.Errorf("expected image count %d, got %d", tt.expectNumImages, response.DebugInfo.ImageCount)
}
} else {
} else if w.Code != http.StatusOK {
// When debug is disabled, it should attempt normal processing
if w.Code != http.StatusOK {
t.Errorf("expected status %d, got %d", http.StatusOK, w.Code)
}
t.Errorf("expected status %d, got %d", http.StatusOK, w.Code)
}
})
}
@ -401,11 +399,9 @@ func TestChatDebugRenderOnly(t *testing.T) {
if tt.expectNumImages > 0 && response.DebugInfo.ImageCount != tt.expectNumImages {
t.Errorf("expected image count %d, got %d", tt.expectNumImages, response.DebugInfo.ImageCount)
}
} else {
} else if w.Code != http.StatusOK {
// When debug is disabled, it should attempt normal processing
if w.Code != http.StatusOK {
t.Errorf("expected status %d, got %d", http.StatusOK, w.Code)
}
t.Errorf("expected status %d, got %d", http.StatusOK, w.Code)
}
})
}

View File

@ -429,10 +429,8 @@ func (s *Scheduler) load(req *LlmRequest, f *ggml.GGML, systemInfo ml.SystemInfo
}
s.activeLoading = llama
} else {
if s.activeLoading.ModelPath() != req.model.ModelPath {
panic(fmt.Errorf("attempting to load different model after eviction (original %v new %v)", s.activeLoading.ModelPath(), req.model.ModelPath))
}
} else if s.activeLoading.ModelPath() != req.model.ModelPath {
panic(fmt.Errorf("attempting to load different model after eviction (original %v new %v)", s.activeLoading.ModelPath(), req.model.ModelPath))
}
s.loadedMu.Unlock()

View File

@ -68,8 +68,7 @@ func InferTags(t *template.Template) (string, string) {
enterFn := func(n parse.Node) bool {
ancestors = append(ancestors, n)
switch x := n.(type) {
case *parse.FieldNode:
if x, ok := n.(*parse.FieldNode); ok {
if len(x.Ident) > 0 && x.Ident[0] == "Thinking" {
var mostRecentRange *parse.RangeNode
for i := len(ancestors) - 1; i >= 0; i-- {
@ -121,8 +120,7 @@ func InferTags(t *template.Template) (string, string) {
func rangeUsesField(rangeNode *parse.RangeNode, field string) bool {
found := false
enterFn := func(n parse.Node) bool {
switch x := n.(type) {
case *parse.FieldNode:
if x, ok := n.(*parse.FieldNode); ok {
if x.Ident[0] == field {
found = true
}