Files
LocalAI/core/services/galleryop/artifact_progress.go
mudler's LocalAI [bot] a89d780707 fix(gallery): keep multi-file HF install progress proportional during verify (#10908)
The artifact progress bridge mapped every PhaseVerifying event to a flat
95%. The materializer emits PhaseVerifying once per file (from each file's
AfterDownload hook) and downloads run sequentially, so the first small file
to finish pinned the bar at 95% - and, because progress is monotonic, it
stayed at 95% for the entire remaining download (e.g. a 70GB checkpoint
reporting 95% at 410MB / 69.7GB).

Track per-file verify proportionally to the running aggregate bytes, the
same way downloading does. CurrentBytes already reflects "completed files +
this file", so the percentage advances honestly. The flat 95%/99% is now
reserved for the genuinely once-per-install Committing/Persisting phases.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
2026-07-18 00:01:24 +02:00

74 lines
2.2 KiB
Go

package galleryop
import (
"fmt"
"sync"
"github.com/mudler/LocalAI/pkg/modelartifacts"
)
type artifactProgressBridge struct {
mu sync.Mutex
last float64
currentBytes int64
totalBytes int64
update func(*OpStatus)
}
func newArtifactProgressBridge(update func(*OpStatus)) *artifactProgressBridge {
return &artifactProgressBridge{update: update}
}
func (b *artifactProgressBridge) Sink(event modelartifacts.ProgressEvent) {
b.mu.Lock()
progress := b.last
message := "Preparing model files"
switch event.Phase {
case modelartifacts.PhaseResolving:
progress = max(progress, 0)
message = "Resolving model files"
case modelartifacts.PhaseDownloading:
if event.TotalBytes > 0 {
progress = max(progress, min(90, float64(event.CurrentBytes)*90/float64(event.TotalBytes)))
}
message = fmt.Sprintf("Downloading model file: %s", event.File)
case modelartifacts.PhaseVerifying:
// Verification runs per file — the materializer emits this from each
// file's AfterDownload hook, not once at the end. CurrentBytes is the
// running aggregate (completed files + this file), so track it
// proportionally like downloading. A flat 95% here pinned the bar the
// moment the first file finished, leaving a multi-file (e.g. 70GB)
// install stuck at 95% for the entire remaining download.
if event.TotalBytes > 0 {
progress = max(progress, min(90, float64(event.CurrentBytes)*90/float64(event.TotalBytes)))
}
message = "Verifying model files"
case modelartifacts.PhaseCommitting:
progress = max(progress, 99)
message = "Finalizing model installation"
case modelartifacts.PhasePersisting:
progress = max(progress, 99)
message = "Saving model configuration"
}
b.last = progress
b.currentBytes = max(b.currentBytes, event.CurrentBytes)
b.totalBytes = max(b.totalBytes, event.TotalBytes)
status := &OpStatus{
Phase: string(event.Phase), Message: message, FileName: event.File,
Progress: progress, CurrentBytes: b.currentBytes, TotalBytes: b.totalBytes,
Cancellable: true,
}
update := b.update
b.mu.Unlock()
if update != nil {
update(status)
}
}
func (b *artifactProgressBridge) ClampLegacy(progress float64) float64 {
b.mu.Lock()
defer b.mu.Unlock()
b.last = max(b.last, progress)
return b.last
}