Skip to content

feat(runtime): continuous model-load progress in the trace log (llama.cpp-style) - #840

Merged
0xShug0 merged 2 commits into
0xShug0:mainfrom
drzsdrtfg:feature/server-load-progress
Oct 10, 2026
Merged

0xShug0 merged 2 commits into
0xShug0:mainfrom
drzsdrtfg:feature/server-load-progress

Conversation

@drzsdrtfg

@drzsdrtfg drzsdrtfg commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Hosts that stream the framework log (audiocpp_server --log-file, audiocpp_cli --log) have no way to render an honest model-load progress bar. The log says which model started loading and when it finished, but nothing in between:

  • On a two-model eager boot (ASR + TTS), the log is silent for ~20 s per model while weights read and upload — a host UI either freezes or has to interpolate blindly.
  • The only continuous signals a host can find are external heuristics (RSS growth, process I/O counters), which front-load on the mmap burst and cannot see the weights phase at all.

llama.cpp solves this in the loader itself: a per-tensor bytes_done / bytes_total callback that fires throughout the whole weight upload. This PR brings the same reporting to audio.cpp, over the existing trace log.

Design: strictly opt-in (--load-progress 0|1, default 0)

Per review feedback, every new key is gated behind --load-progress 1 on both the server and the CLI. With the flag off, the log is byte-identical to the pre-load-progress behavior:

  • no runtime.load.phase brackets, no <store>.weights.upload_progress curve, no server.load.progress boundaries;
  • the pre-existing runtime.model.* inspection trace keeps its original gating (it still emits with plain --log/--log-file exactly as before), and the explicit per-load inspection still runs — its cost and output are unchanged;
  • zero overhead path: the tracker's per-tensor hooks return after one atomic flag check.

What it emits (with --load-progress 1 plus --log/--log-file)

Key Meaning
runtime.load.phase inspect|load|loaded Brackets around the long loader calls: package inspection, weight load, session built
<store>.weights.upload_progress <0..1> The continuous curve: uploaded weight bytes / expected bytes, advanced per tensor (~0.2% steps, so ≤ ~500 lines per model)
server.load.progress <0..1> Server-level models-completed fraction during eager boot; 1.0 once every configured model is resident, just before the listening banner

Mechanics:

  • New engine::core::load_progress tracker (include/engine/framework/core/load_progress.h). ModelRegistry::load starts a curve per load, seeding the denominator from the inspected weight files' on-disk bytes; BackendWeightStore::upload raises the denominator if its backend tensors expand past the seed (dequantization, derived tensors, weights the inspection could not see) and feeds add_uploaded_weight_bytes once per uploaded tensor — the same place llama.cpp advances its callback.
  • The curve is closed by engine::runtime::finish_model_load_trace(), called by the server (classic and parallel) and the CLI after create_task_session: that is when the weight stores have actually uploaded, not when the registry load returns.
  • Mutex-guarded, so lazy first-use loads racing an eager load stay correct.

Exact denominator, no backward corrections (review fix, revised)

The first revision clamped the curve to its high-water mark; the second let the fraction correct downward when a later component raised the total. Both treated the symptom: the real problem was that no one knew the whole model's byte count before the first tensor copied, because weight stores are built one component at a time. This revision fixes the cause:

  • BackendWeightStore::upload() splits into prepare() (allocate the buffer, register the store's full pending-tensor budget with the tracker — no data movement) and the copy loop; upload() prepares automatically, so families that keep uploading per store behave exactly as before.
  • Multi-component families prepare all stores before uploading any. lfm2_audio does this for every session (ASR: encoder+backbone; TTS: backbone+depthformer+detokenizer; chat: all four); the runtime constructors only queue weights, and inference uploads lazily if a caller skips the explicit phases.
  • The tracker accumulates declared budgets, so once all stores are prepared the denominator covers the whole model from the first copied byte.

Result on LFM2.5-Audio ASR: one monotonic climb across encoder and backbone — zero downward corrections — capped at 0.99, final 1.0 only at runtime.load.phase loaded. For families that still upload per store (and for seeds that undercount, like lfm2_audio's empty discovered_weights), the earlier safety net remains: the fraction is always done/total over known work, a total raise emits the corrected fraction immediately, and the per-tensor path never reports 1.0 early.

Example (windows-cpu-release, granite5asr + supertonic eager boot):

[TRACE ...] runtime.load.phase inspect
[TRACE ...] runtime.load.phase load
[TRACE ...] Granite 5 ASR encoder weights.weights.upload_progress 0.0075676
[TRACE ...] Granite 5 ASR encoder weights.weights.upload_progress 0.0145946
... (per-tensor steps) ...
[TRACE ...] Granite 5 ASR encoder weights.weights.upload_progress 0.99
[TRACE ...] runtime.load.phase loaded
[TRACE ...] Granite 5 ASR encoder weights.weights.upload_progress 1
[TRACE ...] server.load.progress 0.5
... second model ...
[TRACE ...] server.load.progress 1

Verification

  • Built windows-cpu-release and windows-vulkan-release (audiocpp_server, audiocpp_cli, audiocpp_gguf), on current main.
  • Flag off (server, log-file): zero new lines of any kind, pre-existing trace intact, /health 200 — byte-identical logging. Same for the CLI (--log only).
  • Flag on (server): full phase ladder per model, 148 curve steps, curve maximum 0.99 before runtime.load.phase loaded, final 1.0 after it, server.load.progress boundaries, /health 200 after bind.
  • Flag on (CLI, stdout): 122 curve steps on a multi-store TTS model, no premature 1.0, no spurious decreases, audio produced, exit 0.
  • --load-progress with any value other than 0|1 fails fast.

Risk assessment

When the flag is off (default for every existing pipeline): the only hot-path change is one pass over pending tensors computing ggml_nbytes sums plus tracker calls that return after an atomic flag check — no locks, allocations, formatting, or syscalls; nanoseconds per tensor against weight copies measured in milliseconds. Log output is unchanged byte-for-byte, and the inspection phase runs exactly as before.

When the flag is on: ~200–500 extra log lines per model load (~30 KB per two-model boot) through the existing trace logger. The progress mutex is uncontended in practice and never held during I/O.

Behavior: all keys are additive; hosts that don't parse them ignore them. No changes to inference, model formats, HTTP endpoints, session semantics, or memory layout.

Notes for reviewers: the store-name doubling in keys (supertonic.weights.weights.upload_progress) comes from stores already named <family>.weights; hosts match the *.weights.upload_progress suffix uniformly. A local install built from this branch self-reports AUDIOCPP_VERSION=dev; tooling tracking installs by registry tag is unaffected.

Hosts that stream the framework log (audiocpp_server --log-file,
audiocpp_cli --log) had no way to show model-load progress: the log only
said which model was loading and when it was done, so load bars stalled
between milestones. llama.cpp reports a continuous done/total curve over
the per-tensor weight upload; audio.cpp now does the same.

- New core/load_progress tracker: begin_model_load seeds the denominator
  from the inspected weight files; register_weight_bytes raises it when
  a store's uploads expand past the seed; add_uploaded_weight_bytes /
  emit_weight_upload_progress trace <store>.weights.upload_progress
  once per ~0.2% step (mutex-guarded, lazy loads included).
- BackendWeightStore::upload feeds the tracker per tensor and emits the
  curve before and after every tensor copy.
- ModelRegistry::load brackets the load with runtime.load.phase
  inspect|load and starts the curve; finish_model_load_trace() closes it
  (runtime.load.phase loaded + final curve point) once the host has
  built the task session - that is when the weight stores actually
  upload.
- ServerState::load_models traces server.load.progress (models-completed
  fraction, 1.0 when every eager model is resident, before the listening
  banner).
@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

Assisted with Glm5.3 and 5.3 flash over zcode

@drzsdrtfg
drzsdrtfg force-pushed the feature/server-load-progress branch from c94cb0c to aaae931 Compare October 8, 2026 16:37
@drzsdrtfg
drzsdrtfg marked this pull request as ready for review October 8, 2026 17:04
@0xShug0

0xShug0 commented Oct 8, 2026

Copy link
Copy Markdown
Owner

@drzsdrtfg Thanks for the PR. This helps address the lack of model-loading progress reported by UI users. However, I suggest making it opt-in with --load-progress 0|1, defaulting to 0, so the logging behavior remains unchanged for existing downstream pipelines.

One minor issue is progress reaches 100% too early. In my LFM2 ASR test, it reached 100% after loading the 63 MiB encoder, before uploading the 917 MiB backbone. When the next component increases the total, the monotonic clamp keeps the displayed progress at 100%, so it no longer reflects the remaining work.

@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

ok, will come bakc when its done

…otals rise

Review feedback on 0xShug0#840:

- All load-progress keys (runtime.load.phase, <store>.weights.upload_progress,
  server.load.progress) are now gated behind --load-progress 1 on both the
  server and the CLI, default 0. With the flag off the log is byte-identical
  to the pre-load-progress behavior: no phase brackets, no curve, no
  models-completed boundaries, and the runtime.model.* inspection trace keeps
  its original trace-log gating. The explicit per-load inspection runs exactly
  as before the feature.

- The curve no longer strands at 100% when a later component raises the
  denominator (LFM2 ASR: 100% after the 63 MiB encoder, before the 917 MiB
  backbone). emit_weight_upload_progress now reports done/total over all work
  known so far: a total raise emits the corrected lower fraction immediately
  (no high-water clamp), and the per-tensor path caps at 0.99 - the final 1.0
  belongs to end_model_load after the last store uploaded, so an undercounted
  seed can never display 100% early.

- ParallelServerState closes the load-progress bracket after its first
  resident session and reports models-completed boundaries, matching the
  classic server state.

Verified windows-cpu-release + windows-vulkan-release: flag-off boots emit
zero new lines with /health 200; flag-on boots show the full ladder with the
curve capped at 0.99 before runtime.load.phase loaded and 1.0 after; CLI
synthesis emits the same on stdout; supertonic's multi-store upload stays
monotonic to the cap.
@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Both points are addressed in 9159716:

Opt-in reporting. All three key families (runtime.load.phase, <store>.weights.upload_progress, server.load.progress) are now gated behind --load-progress 1 on the server and the CLI, defaulting to 0. With the flag off the log is byte-identical to before this PR — the pre-existing runtime.model.* inspection trace keeps its original gating, and the per-load inspection runs exactly as it did. The per-tensor hooks cost one atomic flag check when disabled.

Early 100%. Reproduced the shape of your LFM2 case from the code path: the seed (discovered weight bytes) undercounts when some weights aren't visible to the inspection, the first small store completes against that small denominator, and the old high-water clamp pinned the curve at 1.0 after the backbone raised the total. Two changes fix it:

  • the reported fraction is now always done/total over all work known so far — when a store raises the total, the corrected (lower) fraction emits immediately, so the curve tracks the actual remaining work;
  • the per-tensor path caps at 0.99; the final 1.0 is emitted by end_model_load only after the last store uploaded (finish_model_load_trace after session construction). Under any seed error the curve can now at most show 99% before the load truly ends, then corrects and climbs again.

Verified on windows-cpu-release and windows-vulkan-release: flag-off boots emit zero new lines with /health 200; flag-on boots show the ladder with the curve capped at 0.99 before runtime.load.phase loaded and 1.0 after; the CLI emits the same on stdout, and a multi-store TTS model stays monotonic to the cap with no premature 1.0. I don't have an LFM2 package locally to exercise the exact 63 MiB / 917 MiB numbers — if you can run your LFM2 ASR test against this revision, that would confirm the correction path on the real package.

@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

Follow-up: I ran the LFM2 test you asked for, against 9159716.

Package: LiquidAI/LFM2.5-Audio-1.5B-GGUF (Q8_0), four components — backbone 1.19 GB, mmproj 293 MB, vocoder 206 MB, tokenizer 77 MB (sizes differ from your 917 MiB/63 MiB figures, presumably a repo revision apart, but the mechanism is identical). Run via audiocpp_cli --task asr --family lfm2_audio --model-spec-override model_specs/lfm2_audio.json --log --load-progress 1 on windows-cpu-release; a 1 s wav transcribed correctly ("Aye!"), exit 0.

This family undercounts even harder than your case: runtime.model.discovered_weight_count 0 — the lfm2_audio inspection discovers no weight files at all (the contract resolves components by role at load time), so the curve seed is zero and the first store's bytes ARE the initial denominator.

With the fix, the emitted curve does the right thing:

  • lfm2_audio.encoder uploads first: 193 emissions climbing to the cap — it stops at 0.99, never 1.0;
  • the backbone store registers: the next emission corrects 0.99 → 0.090 (encoder share of the real total) and climbs again for 82 more emissions;
  • runtime.load.phase loaded, then the single final 1.0.

So: no early 100% even with a zero seed, and after the denominator grows the curve tracks the actual remaining backbone work instead of sitting pinned. Flag off on the same model: zero new lines, pre-existing trace intact, same transcription.

@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

sorry for these slop comments(zcode somehow comments automatically without asking). Still not fixed.

@0xShug0
0xShug0 merged commit a03f27c into 0xShug0:main Oct 10, 2026
11 checks passed
@0xShug0

0xShug0 commented Oct 10, 2026

Copy link
Copy Markdown
Owner

@drzsdrtfg Thanks! Merged. The current approach looks fine. We just need to document that progress is approximate and may move backward when loading multiple GGUF components. It works correctly for the tested single-GGUF cases.

@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

Yeah, but I am still searching for proper fix, since the prgress going back may not be to the liking of most users.

@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

Follow-up in 4caead7: after the LFM2 test I reworked the fix to remove the downward correction entirely rather than keep it.

The correction drop treated the symptom. The real problem is that weight stores are built one component at a time, so nothing knew the whole model's byte count before the first tensor copied. This revision gives BackendWeightStore a prepare/upload split:

  • prepare() allocates the weight buffer and registers the store's full pending-tensor budget with the tracker — no data movement. upload() prepares automatically, so families that upload per store are untouched.
  • Multi-component families prepare all stores before uploading any. lfm2_audio does this in all three session constructors (ASR: encoder+backbone; TTS: backbone+depthformer+detokenizer; chat: all four); the runtime constructors only queue weights now, and inference uploads lazily if a caller skips the explicit phases.
  • The tracker accumulates declared budgets instead of deriving the total from done+last-budget (which under-counted when budgets registered before anything had copied).

Measured on LFM2.5-Audio ASR with --load-progress 1: 118 emissions, zero downward corrections, one monotonic climb across encoder and backbone with the true denominator from the first byte, capped at 0.99, final 1.0 only at runtime.load.phase loaded, transcription unchanged. Regression runs (supertonic TTS multi-store, granite+supertonic two-model server boot, flag-off on all of them) are unchanged and clean. The per-store cap+correction path stays as the honest fallback for families that have not adopted the split.

@0xShug0

0xShug0 commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Sounds good!

@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

Tested supertonic3 and granite 5 asr on my own ui, working properly.

Note: my follow-up commit (4caead7) landed after your merge, so it's not in main. Want it as a new PR?

@0xShug0

0xShug0 commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Tested supertonic3 and granite 5 asr on my own ui, working properly.

Note: my follow-up commit (4caead7) landed after your merge, so it's not in main. Want it as a new PR?

Yes!

@drzsdrtfg

Copy link
Copy Markdown
Contributor Author

Sorry for being such a hassle and thanks for being so consistent on your work on audio.cpp. I decided to not open the other PR, since we need to add a couple of lines to every multi-component asr. Its just not worth it. My future work will probably be less on the backend side, since I suck. Have a happy day.

@0xShug0

0xShug0 commented Oct 10, 2026

Copy link
Copy Markdown
Owner

@drzsdrtfg No worries at all. I really appreciate all the work you've put into audio.cpp. And don't be so hard on yourself...Looking forward to more contributions from you. Have a great day too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants