You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(modelartifacts): support bounded parallel Hugging Face file downloads (#11162)
* feat(modelartifacts): support bounded parallel Hugging Face file downloads
Closes#11114.
Snapshot materialization fetched every file through the sequential
executor in DownloadFilesWithContext, so a repository split into many
shards spent most of its wall clock in per-file request latency rather
than moving bytes.
Add DownloadFilesWithConcurrency, an errgroup with SetLimit, and keep
DownloadFilesWithContext as a wrapper that passes a limit of 1. That
leaves the two non-artifact callers (core/gallery and the model config
loader) on exactly the path they had: tasks still run in slice order,
and the first failure still returns before any later task starts.
Only whole files run in parallel. A single file is never split, so the
.partial resume machinery and the per-file SHA check in
downloadTaskWithRetry are untouched.
Two details the parallel path forced:
- completedBytes becomes an atomic.Int64. Several AfterDownload hooks
add to it while other files' progress callbacks read it; without this
the race detector reports three races on the new specs.
- The caller's status callback is serialized. The sequential path gave
it an implicit guarantee of never being entered twice at once, and it
belongs to the caller, so the executor keeps that promise rather than
pushing locking onto every caller. AfterDownload is deliberately not
serialized -- it does the verify-and-promote work that parallelism
exists to overlap.
Manifest order needed no work: each hook already writes its own
manifest.Files slot by snapshot index, so entries stay in snapshot
order whatever the completion order. A spec now pins that.
The default is 1, unchanged behaviour. A shared models volume is often
the bottleneck rather than the link, so raising it is a deployment
decision; --artifact-download-concurrency and
LOCALAI_ARTIFACT_DOWNLOAD_CONCURRENCY expose it on both `run` and
`models install`.
Not done here, per the issue: no chunk-level parallelism within a single
file, and no throughput measurements across concurrency 1/2/4/8 -- that
needs a representative sharded repo and a real link.
Assisted-by: Claude:claude-opus-5 go-test gofmt
Signed-off-by: Adira Denis Muhando <dennisadira@gmail.com>
* feat(modelartifacts): expose download concurrency in settings
Follow-up to review feedback on #11162:
- The CLI flag and docs no longer describe the limit as Hugging Face
specific. It applies to any artifact source, as @mudler pointed out.
- artifact_download_concurrency is now a persisted runtime setting and
is editable from the WebUI, so it can be changed without a restart.
The manager's limit becomes an atomic.Int64 behind
SetDownloadConcurrency, because a live runtime setting can be updated
while a materialization is already in flight. Injected materializers
stay compatible through an optional setter interface, so a manager that
does not implement it is simply left alone.
Verified before taking this on: go build, go vet and go test -race all
pass for pkg/modelartifacts, pkg/downloader and core/config. The React
UI builds with vite, artifact_download_concurrency is present in the
built Settings chunk, and eslint reports the same 8 pre-existing
warnings on Settings.jsx as it does without the change.
Implementation contributed by localai-org-maint-bot on the review
thread; reviewed, verified and signed off by me.
Assisted-by: Codex:gpt-5
Assisted-by: Claude:claude-opus-5 go-test vite eslint
Signed-off-by: Adira Denis Muhando <dennisadira@gmail.com>
---------
Signed-off-by: Adira Denis Muhando <dennisadira@gmail.com>
Co-authored-by: localai-org-maint-bot <bot-opensource@localaisrl.com>
Copy file name to clipboardExpand all lines: core/cli/models.go
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ type ModelsCMDFlags struct {
28
28
Colorstring`env:"COLOR" hidden:""`
29
29
NoColorstring`env:"NO_COLOR" hidden:""`
30
30
HFTokenstring`env:"HF_TOKEN" hidden:""`
31
+
32
+
ArtifactDownloadConcurrencyint`env:"LOCALAI_ARTIFACT_DOWNLOAD_CONCURRENCY" help:"How many files of a model artifact to download at once. 1 (the default) downloads sequentially. Raising it helps artifacts split into many files on a fast link, at the cost of more concurrent load on the models volume" group:"storage" default:"1"`
Copy file name to clipboardExpand all lines: core/cli/run.go
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,7 @@ type RunCMD struct {
41
41
BackendsPathstring`env:"LOCALAI_BACKENDS_PATH,BACKENDS_PATH" type:"path" default:"${basepath}/backends" help:"Path containing backends used for inferencing" group:"backends"`
42
42
BackendsSystemPathstring`env:"LOCALAI_BACKENDS_SYSTEM_PATH,BACKEND_SYSTEM_PATH" type:"path" default:"/var/lib/local-ai/backends" help:"Path containing system backends used for inferencing" group:"backends"`
43
43
ModelsPathstring`env:"LOCALAI_MODELS_PATH,MODELS_PATH" type:"path" default:"${basepath}/models" help:"Path containing models used for inferencing" group:"storage"`
44
+
ArtifactDownloadConcurrencyint`env:"LOCALAI_ARTIFACT_DOWNLOAD_CONCURRENCY" help:"How many files of a model artifact to download at once. 1 (the default) downloads sequentially. Raising it helps artifacts split into many files on a fast link, at the cost of more concurrent load on the models volume" group:"storage" default:"1"`
UploadPathstring`env:"LOCALAI_UPLOAD_PATH,UPLOAD_PATH" type:"path" default:"${uploadpath}" help:"Path to store uploads from files api" group:"storage"`
46
47
DataPathstring`env:"LOCALAI_DATA_PATH" type:"path" default:"${basepath}/data" help:"Path for persistent data (collectiondb, agent state, tasks, jobs). Separates mutable data from configuration" group:"storage"`
Copy file name to clipboardExpand all lines: core/config/runtime_settings.go
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -33,15 +33,16 @@ type RuntimeSettings struct {
33
33
LRUEvictionRetryInterval*string`json:"lru_eviction_retry_interval,omitempty"`// Interval between retries when waiting for busy models (e.g., 1s, 2s) (default: 1s)
34
34
35
35
// Performance settings
36
-
Threads*int`json:"threads,omitempty"`
37
-
ContextSize*int`json:"context_size,omitempty"`
38
-
VRAMBudget*string`json:"vram_budget,omitempty"`// Cap VRAM for allocation ("80%" or "12GB"; "" = no cap)
<SettingRowlabel="VRAM Budget"description="Cap VRAM used for model allocation on this node. Percentage (e.g. 80%) or absolute (e.g. 12GB). Empty uses all detected VRAM.">
398
401
<inputclassName="input col-w-120"type="text"value={settings.vram_budget??''}onChange={(e)=>update('vram_budget',e.target.value)}placeholder="e.g. 80% or 12GB"/>
0 commit comments