Skip to content

yue2: size the AR prefix-state and NAR graph contexts from their node caps - #657

Closed
engival wants to merge 1 commit into
0xShug0:mainfrom
engival:yue2-graph-context-size
Closed

engival wants to merge 1 commit into
0xShug0:mainfrom
engival:yue2-graph-context-size

Conversation

@engival

@engival engival commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #656

You may want to review this carefully. claude code made a bunch of decisions on how to fix this, including removing an option.

Asking claude to justify this patch:

Why yue2.nar_graph_arena_mb is removed rather than resized

The option was the mem_size of a ggml_init call on a no_alloc context. Such a context holds only tensor headers and the graph object. The activations never live in it: ggml_gallocr places them in a backend buffer sized from the graph itself, which is the number logged as yue2.nar.graph.buffer_bytes.

So the option never controlled memory in the sense its name suggests. Raising it could not make a larger song fit, and lowering it below what the headers need would abort at graph build. The only observable effect of the value was the size of an up-front host malloc that was ~99% never touched. On Linux, overcommit made that invisible. On Windows it is charged against the commit limit, which is the crash in #656, and the reporter's natural response, raising it to 8192, made the malloc bigger.

After this change the context is sized from the node cap the graph is created with, so the two cannot disagree and there is nothing left for a user to tune. Keeping the option would mean either ignoring it silently or documenting a knob that does nothing, and both invite the same misreading that produced this issue. Unknown session options are ignored by the runtime, so existing command lines that still pass it continue to work. yue2.ar_prefill_graph_arena_mb stays because the shared Qwen decode runtime still reads it.

What was wrong

Yue2ArRuntime::PrefixStateGraph and Yue2NarRuntime::Graph create their ggml contexts with ggml_init({arena_bytes, nullptr, /*no_alloc=*/true}). Both contexts are no_alloc: they only ever hold tensor headers and the graph object, the activations are placed by the gallocr into a backend buffer. But ggml_init mallocs the whole mem_size up front regardless, so every run reserved 4 GiB (AR prefix state, from yue2.ar_prefill_graph_arena_mb) and 6 GiB (NAR, from yue2.nar_graph_arena_mb) of host memory that is ~99% never touched, on every backend.

Linux overcommit hides that. Windows charges the reservation against the commit limit, and the CPU run in #656 dies in ggml_init with GGML_ASSERT(ctx->mem_buffer != NULL) right after yue2.nar.synthesize.context is logged, which is where the NAR stage prefills the AR stream and opens the first of those two contexts. Raising yue2.nar_graph_arena_mb asks for a bigger malloc, so it makes it worse.

Change

  • Size both contexts as nodes * ggml_tensor_overhead() + ggml_graph_overhead_custom(nodes, false), with nodes the same cap passed to ggml_new_graph_custom (65536 and 262144). That is ~30 MB and ~110 MB. Same idiom as the Apollo and UniVSR runtimes.
  • yue2.nar_graph_arena_mb has no consumer left and is removed (session option, model spec, docs). Unknown session options are ignored by the runtime, so commands that still pass it keep working.
  • yue2.ar_prefill_graph_arena_mb stays: the shared Qwen decode runtime still reads it.

Model-local only, no framework files touched.

Validation

yue2-3b-q8_0.gguf + yue2-vae-f32.gguf, seed 1234, cot=off, --out compared with cmp against a build of main (4e8be77).

CPU (--backend cpu --threads 8, 6 s request, 4 ODE steps, 192 semantic tokens):

run main this PR
uncapped renders renders, byte-identical
ulimit -v 22 GB GGML_ASSERT(ctx->mem_buffer != NULL) after yue2.nar.synthesize.context 24576, i.e. the log in #656 renders, byte-identical, with --session-option yue2.nar_graph_arena_mb=8192 still on the command line

The capped run is a Linux stand-in for the Windows commit limit: ggml_aligned_malloc: insufficient memory (attempted to allocate 4096.00 MB) from PrefixStateGraph, then the assert. With a tighter cap (14 GB) main fails one stage earlier, in the framework's QwenCausalDecodeRuntime::build_prefill_graph, on the same pattern.

… caps

Both contexts are no_alloc: they hold tensor headers and the graph object,
while the activations live in the gallocr buffer. They were still created
with ggml_init(arena_bytes), which mallocs the whole arena up front: 4 GiB
for the AR prefix-state graph and 6 GiB for the NAR velocity graph, on
every backend. Linux overcommit hides it; Windows charges it against the
commit limit, and a CPU run dies in ggml_init with
GGML_ASSERT(ctx->mem_buffer != NULL) right after the NAR stage starts
(0xShug0#656).

Size the two contexts as nodes * ggml_tensor_overhead() +
ggml_graph_overhead_custom(nodes, false), the idiom the Apollo and UniVSR
runtimes use. That is ~30 MB and ~110 MB. yue2.nar_graph_arena_mb has no
consumer left and is removed; unknown session options are ignored, so
commands that still pass it keep working. yue2.ar_prefill_graph_arena_mb
stays because the shared Qwen decode runtime still reads it.

Validation (yue2-3b-q8_0 + yue2-vae-f32, seed 1234): CPU output is
byte-identical to main, uncapped and under a ulimit -v that made main
fail with the reported assert; Vulkan (Intel Arc Pro B70) output is
byte-identical to main.
@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

@engival I haven’t had a chance to look into the issue yet. Do you mean this is similar to #151?

@engival

engival commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

@0xShug0 Yeah, it looks like the same root cause.

I asked claude to search it, and this bug lives elsewhere too.

The clean framework fix would be for QwenCausalDecodeRuntime to size each context from its 65536 node cap the way this PR does for yue2, and then ignore or drop the *_graph_arena_bytes config fields.

This is touching too much stuff that I rather not play with.

@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

I remembered for 151 another solution was to change backend weight store without touching model code, but I was lazy to do regression tests for this global change and did model local changes. Not sure if that solution still works.

@engival

engival commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

I don't know this code base well enough, so I'm going to just relay claude's analysis:

The fix floated for #151 would cover every model's weight context in one place. It would do nothing for #656, because yue2's NAR and AR contexts and the Qwen runtime's contexts never touch that class. Fixing those globally means editing each runtime that calls ggml_init itself, of which the Qwen one is the most shared, and there are a dozen more in conditioners, decoders and vocoders.

Just brainstorming: If you would rather fix this class globally than merge per-model patches like this one, it doesn't have to be a big-bang change:

  • QwenCausalDecodeRuntime could treat prefill_graph_arena_bytes == 0 (which throws today) as "size from the 65536 node cap". Models passing a real value keep their exact current behaviour; models opt in by passing 0. One shared runtime fixed, zero regression exposure for anyone who does not opt in.
  • Same idea for BackendWeightStore: an alternate constructor sized from tensor count next to the existing context_bytes one, migrated one model at a time as reports come in.
  • A small no_alloc_graph_context_bytes(nodes) helper would name the formula Apollo, UniVSR and this PR already use inline.

If you go that route, this PR is probably unnecessary.

@engival

engival commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

I just did some more testing, and Claude came back with some interesting results. This PR might not be the full picture for memory optimization under windows.

What the PR fixes: The two contexts yue2 owns, 4 GB and 6 GB of phantom reservation. That is where the reporter's assert fires, and the PR removes it.

What it leaves: The shared QwenCausalDecodeRuntime still opens its contexts from yue2.ar_prefill_graph_arena_mb and yue2.ar_decode_graph_arena_mb, defaults 4096 and 1536 MB. On the full-length uncapped run the PR build peaked at 27.5 GB of virtual memory against 10.7 GB actually resident. Most of that gap is those arenas. On Windows that gap is still commit-charged.

@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

I will switch to Windows to do some tests tomorrow to confirm the root cause.

engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
…uffer landed

Every no_alloc ggml context is a host allocation made in full by
ggml_init, whether or not the tensor headers ever fill it. The process
peak in `--metrics` says how much of that there is in total; these
[TIMING] lines say which context, by the name the build_ms line next to
them already uses:

    yue2.nar.graph.ctx_reserved_mb 6144
    yue2.nar.graph.ctx_used_mb 10.603347778320312
    yue2.nar.weights.ctx_reserved_mb 6144
    yue2.nar.weights.ctx_used_mb 0.111602783203125
    yue2.nar.weights.buffer_mb 1533.761962890625
    yue2.nar.weights.buffer_name Vulkan1

New debug::timing_log_context_reservation(name, ctx) reads
ggml_get_mem_size / ggml_used_mem once the graph is built. Called from
the shared Qwen causal decode runtime (prefill, batched prefill, decode,
batched decode, block prefill), the greedy Qwen decoder, the MOSS delay
backbone, the two yue2 graph contexts, and BackendWeightStore::upload(),
which covers every weight store by its own name and adds the backend
buffer's size and name so a host fallback shows up as such.

Gated by the existing timing log; nothing runs without --log.

On this yue2 run (main, defaults, Linux/Vulkan on Intel) the contexts
reserve 29.8 GB for under 30 MB of headers, against a process VmPeak of
32.6 GB. 13.9 GB of that is the weight stores (the 0xShug0#151 class), 5.6 GB
the shared Qwen runtime, 10.2 GB the two yue2 graph contexts that 0xShug0#657
resizes.

Output byte-identical (yue2, 640 tokens, seed 1234).
@engival

engival commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

@0xShug0

I set up some memory instrumentation you could try on the Windows side, two commits on a branch (not a PR, let me know if you want me to open one): https://github.com/engival/audio.cpp/tree/metrics-process-memory

I could only test it on Linux of course.

  1. --metrics gains the process peak, with the number a commit-limit failure is measured against on each OS (Windows: peak commit charge, which Task Manager's default column doesn't show):

metrics.memory.peak_rss_mb=1100
metrics.memory.peak_footprint_mb=32653
metrics.memory.peak_footprint_source=linux_vsize

  1. With --log, every graph context and weight store logs what it reserved vs what its headers actually use, beside the existing build_ms line, plus where each weight buffer landed:

[TIMING ts=20260923-114628] yue2.ar.weights.ctx_reserved_mb 6144
[TIMING ts=20260923-114628] yue2.ar.weights.ctx_used_mb 0.1084442138671875
[TIMING ts=20260923-114628] yue2.ar.weights.buffer_mb 2149.96484375
[TIMING ts=20260923-114628] yue2.ar.weights.buffer_name Vulkan1

On a default yue2 run here the contexts reserve 29.8 GB for under 30 MB of headers. #657 covers the two graph contexts (10.2 GB); the four yue2 weight stores are another 13.9 GB of the same thing (the #151 class), and the shared Qwen runtime 5.6 GB. So depending on the commit limit on your Windows box, #657 alone may pass your test and still not fix the reported issue. The log should make that visible either way. Output is byte-identical with and without the branch.

engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
Opts yue2 into the FromCapacity sizing: the four weight stores
(yue2.ar.weights, yue2.ar.generation.weights, yue2.nar.weights and the
VAE's) take a TensorCapacity from the source's tensor count, the three
QwenCausalDecodeRuntime configs set graph_arena_sizing, and the VAE
runtime gets context_sizing. Their four session options go away:
yue2.model_weight_context_mb, yue2.vae_weight_context_mb,
yue2.ar_decode_graph_arena_mb, yue2.vae_graph_arena_mb (unknown options
are ignored, so old command lines still run).

The two contexts yue2 builds itself, the AR prefix-state graph and the
NAR graph, keep their options for now (the prefill option now only feeds
the prefix-state graph and is described as such); 0xShug0#657 covers those.

Per-context log on the same render, before -> after (MiB reserved):
  yue2.ar.weights                        6144 -> 0.22
  yue2.ar.generation.weights               64 -> 0.22
  yue2.nar.weights                       6144 -> 0.22
  framework.oobleck_audio_vae.weights    1536 -> 0.12
  yue2.ar.prefill.graph (x2, CFG)        4096 -> 48.5
  yue2.ar.decode.graph  (x2, CFG)        1536 -> 48.5
Process peak footprint 32653 -> 20301 MiB; output byte-identical.
engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
The two contexts yue2 builds itself. Each graph's node cap becomes a
named constant next to the runtime and its context is sized from it
with no_alloc_graph_context_bytes; the last two arena options
(yue2.ar_prefill_graph_arena_mb, yue2.nar_graph_arena_mb) go away.

Same ground as 0xShug0#657, done through the shared helper instead of inline
arithmetic; drop this commit if that lands first.

Per-context log, before -> after (MiB reserved / used):
  yue2.ar.prefix_state.graph   4096 -> 48.5   (3.0 used)
  yue2.nar.graph               6144 -> 194.1  (10.6 used)
Process peak footprint on the render: 32653 (main) -> 10061 MiB, all
yue2-owned reservations gone; output byte-identical, and the removed
options are still accepted (ignored) on the command line.
engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
Opts yue2 into the FromCapacity sizing: the four weight stores
(yue2.ar.weights, yue2.ar.generation.weights, yue2.nar.weights and the
VAE's) take a TensorCapacity from the source's tensor count, the three
QwenCausalDecodeRuntime configs set graph_arena_sizing, and the VAE
runtime gets context_sizing. Their four session options go away:
yue2.model_weight_context_mb, yue2.vae_weight_context_mb,
yue2.ar_decode_graph_arena_mb, yue2.vae_graph_arena_mb (unknown options
are ignored, so old command lines still run).

The two contexts yue2 builds itself, the AR prefix-state graph and the
NAR graph, keep their options for now (the prefill option now only feeds
the prefix-state graph and is described as such); 0xShug0#657 covers those.

Per-context log on the same render, before -> after (MiB reserved):
  yue2.ar.weights                        6144 -> 0.22
  yue2.ar.generation.weights               64 -> 0.22
  yue2.nar.weights                       6144 -> 0.22
  framework.oobleck_audio_vae.weights    1536 -> 0.12
  yue2.ar.prefill.graph (x2, CFG)        4096 -> 48.5
  yue2.ar.decode.graph  (x2, CFG)        1536 -> 48.5
Process peak footprint 32653 -> 20301 MiB; output byte-identical.
engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
The two contexts yue2 builds itself. Each graph's node cap becomes a
named constant next to the runtime and its context is sized from it
with no_alloc_graph_context_bytes; the last two arena options
(yue2.ar_prefill_graph_arena_mb, yue2.nar_graph_arena_mb) go away.

Same ground as 0xShug0#657, done through the shared helper instead of inline
arithmetic; drop this commit if that lands first.

Per-context log, before -> after (MiB reserved / used):
  yue2.ar.prefix_state.graph   4096 -> 48.5   (3.0 used)
  yue2.nar.graph               6144 -> 194.1  (10.6 used)
Process peak footprint on the render: 32653 (main) -> 10061 MiB, all
yue2-owned reservations gone; output byte-identical, and the removed
options are still accepted (ignored) on the command line.
engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
Opts yue2 into the FromCapacity sizing: the four weight stores
(yue2.ar.weights, yue2.ar.generation.weights, yue2.nar.weights and the
VAE's) take a TensorCapacity from the source's tensor count, the three
QwenCausalDecodeRuntime configs set graph_arena_sizing, and the VAE
runtime gets context_sizing. Their four session options go away:
yue2.model_weight_context_mb, yue2.vae_weight_context_mb,
yue2.ar_decode_graph_arena_mb, yue2.vae_graph_arena_mb (unknown options
are ignored, so old command lines still run).

The two contexts yue2 builds itself, the AR prefix-state graph and the
NAR graph, keep their options for now (the prefill option now only feeds
the prefix-state graph and is described as such); 0xShug0#657 covers those.

Per-context log on the same render, before -> after (MiB reserved):
  yue2.ar.weights                        6144 -> 0.22
  yue2.ar.generation.weights               64 -> 0.22
  yue2.nar.weights                       6144 -> 0.22
  framework.oobleck_audio_vae.weights    1536 -> 0.12
  yue2.ar.prefill.graph (x2, CFG)        4096 -> 48.5
  yue2.ar.decode.graph  (x2, CFG)        1536 -> 48.5
Process peak footprint 32653 -> 20301 MiB; output byte-identical.
engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
The two contexts yue2 builds itself. Each graph's node cap becomes a
named constant next to the runtime and its context is sized from it
with no_alloc_graph_context_bytes; the last two arena options
(yue2.ar_prefill_graph_arena_mb, yue2.nar_graph_arena_mb) go away.

Same ground as 0xShug0#657, done through the shared helper instead of inline
arithmetic; drop this commit if that lands first.

Per-context log, before -> after (MiB reserved / used):
  yue2.ar.prefix_state.graph   4096 -> 48.5   (3.0 used)
  yue2.nar.graph               6144 -> 194.1  (10.6 used)
Process peak footprint on the render: 32653 (main) -> 10061 MiB, all
yue2-owned reservations gone; output byte-identical, and the removed
options are still accepted (ignored) on the command line.
engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
Opts yue2 into the FromCapacity sizing: the four weight stores
(yue2.ar.weights, yue2.ar.generation.weights, yue2.nar.weights and the
VAE's) take a TensorCapacity from the source's tensor count, the three
QwenCausalDecodeRuntime configs set graph_arena_sizing, and the VAE
runtime gets context_sizing (its two byte fields set to 0, as it requires). Their four session options go away:
yue2.model_weight_context_mb, yue2.vae_weight_context_mb,
yue2.ar_decode_graph_arena_mb, yue2.vae_graph_arena_mb (unknown options
are ignored, so old command lines still run).

The two contexts yue2 builds itself, the AR prefix-state graph and the
NAR graph, keep their options for now (the prefill option now only feeds
the prefix-state graph and is described as such); 0xShug0#657 covers those.

Per-context log on the same render, before -> after (MiB reserved):
  yue2.ar.weights                        6144 -> 0.22
  yue2.ar.generation.weights               64 -> 0.22
  yue2.nar.weights                       6144 -> 0.22
  framework.oobleck_audio_vae.weights    1536 -> 0.12
  yue2.ar.prefill.graph (x2, CFG)        4096 -> 48.5
  yue2.ar.decode.graph  (x2, CFG)        1536 -> 48.5
  framework.oobleck_audio_vae graph      1536 -> 388
Process peak footprint 32653 -> 20301 MiB; output byte-identical.
engival added a commit to engival/audio.cpp that referenced this pull request Sep 23, 2026
The two contexts yue2 builds itself. Each graph's node cap becomes a
named constant next to the runtime and its context is sized from it
with no_alloc_graph_context_bytes; the last two arena options
(yue2.ar_prefill_graph_arena_mb, yue2.nar_graph_arena_mb) go away.

Same ground as 0xShug0#657, done through the shared helper instead of inline
arithmetic; drop this commit if that lands first.

Per-context log, before -> after (MiB reserved / used):
  yue2.ar.prefix_state.graph   4096 -> 48.5   (3.0 used)
  yue2.nar.graph               6144 -> 194.1  (10.6 used)
Process peak footprint on the render: 32653 (main) -> 10061 MiB, all
yue2-owned reservations gone; output byte-identical, and the removed
options are still accepted (ignored) on the command line.
@0xShug0
0xShug0 force-pushed the main branch 2 times, most recently from 9bdd1d9 to 4d88768 Compare September 23, 2026 22:46
@0xShug0

0xShug0 commented Sep 24, 2026

Copy link
Copy Markdown
Owner

@engival The memory metric is a nice addition! Could you open a PR?

This PR will be closed as mentioned in #656

@0xShug0 0xShug0 closed this Sep 24, 2026
engival added a commit to engival/audio.cpp that referenced this pull request Sep 24, 2026
…uffer landed

Every no_alloc ggml context is a host allocation made in full by
ggml_init, whether or not the tensor headers ever fill it. The process
peak in `--metrics` says how much of that there is in total; these
[TIMING] lines say which context, by the name the build_ms line next to
them already uses:

    yue2.nar.graph.ctx_reserved_mb 6144
    yue2.nar.graph.ctx_used_mb 10.603347778320312
    yue2.nar.weights.ctx_reserved_mb 6144
    yue2.nar.weights.ctx_used_mb 0.111602783203125
    yue2.nar.weights.buffer_mb 1533.761962890625
    yue2.nar.weights.buffer_name Vulkan1

New debug::timing_log_context_reservation(name, ctx) reads
ggml_get_mem_size / ggml_used_mem once the graph is built. Called from
the shared Qwen causal decode runtime (prefill, batched prefill, decode,
batched decode, block prefill), the greedy Qwen decoder, the MOSS delay
backbone, the two yue2 graph contexts, and BackendWeightStore::upload(),
which covers every weight store by its own name and adds the backend
buffer's size and name so a host fallback shows up as such.

Gated by the existing timing log; nothing runs without --log.

On this yue2 run (main, defaults, Linux/Vulkan on Intel) the contexts
reserve 29.8 GB for under 30 MB of headers, against a process VmPeak of
32.6 GB. 13.9 GB of that is the weight stores (the 0xShug0#151 class), 5.6 GB
the shared Qwen runtime, 10.2 GB the two yue2 graph contexts that 0xShug0#657
resizes.

Output byte-identical (yue2, 640 tokens, seed 1234).
engival added a commit to engival/audio.cpp that referenced this pull request Sep 24, 2026
…uffer landed

Every no_alloc ggml context is a host allocation made in full by
ggml_init, whether or not the tensor headers ever fill it. The process
peak in `--metrics` says how much of that there is in total; these
[TIMING] lines say which context, by the name the build_ms line next to
them already uses:

    yue2.nar.graph.ctx_reserved_mb 6144
    yue2.nar.graph.ctx_used_mb 10.603347778320312
    yue2.nar.weights.ctx_reserved_mb 6144
    yue2.nar.weights.ctx_used_mb 0.111602783203125
    yue2.nar.weights.buffer_mb 1533.761962890625
    yue2.nar.weights.buffer_name Vulkan1

New debug::timing_log_context_reservation(name, ctx) reads
ggml_get_mem_size / ggml_used_mem once the graph is built. Called from
the shared Qwen causal decode runtime (prefill, batched prefill, decode,
batched decode, block prefill), the greedy Qwen decoder, the MOSS delay
backbone, the two yue2 graph contexts, and BackendWeightStore::upload(),
which covers every weight store by its own name and adds the backend
buffer's size and name so a host fallback shows up as such.

Gated by the existing timing log; nothing runs without --log.

On this yue2 run (main, defaults, Linux/Vulkan on Intel) the contexts
reserve 29.8 GB for under 30 MB of headers, against a process VmPeak of
32.6 GB. 13.9 GB of that is the weight stores (the 0xShug0#151 class), 5.6 GB
the shared Qwen runtime, 10.2 GB the two yue2 graph contexts that 0xShug0#657
resizes.

Output byte-identical (yue2, 640 tokens, seed 1234).
0xShug0 pushed a commit that referenced this pull request Sep 25, 2026
…context in --log (#688)

* metrics: report the process's peak RSS and peak footprint

`--metrics` now prints a memory group next to `wall_ms`, read once at
the end of the run from figures the OS already keeps (one syscall,
nothing sampled during generation):

    metrics.memory.peak_rss_mb=1100
    metrics.memory.peak_footprint_mb=32653
    metrics.memory.peak_footprint_source=linux_vsize

The footprint is the platform's own idea of what the process claimed
beyond resident pages, i.e. what an allocation failure is measured
against there, and the source line says which: Windows peak commit
charge (PeakPagefileUsage, the figure a commit-limit failure compares
to; Task Manager's default column hides it), Linux VmPeak (over-counts
commit), macOS phys_footprint (Activity Monitor's "Memory"). A field
the platform cannot report is omitted, as available_host_memory_bytes()
already does with 0 = unknown.

Motivation: memory reports today arrive as "allocation failed" with an
RSS number, which on Windows says nothing about the commit charge that
actually failed. With this in every shipped binary, "run it with
--metrics and paste the output" answers the question after the fact and
shows how close a working run sits to the limit.

Peaks are process-wide, so a batch item reports the peak reached so far,
not its own.

Validated on Linux/Vulkan (yue2, 640 tokens, seed 1234): output
byte-identical, RSS line matches /usr/bin/time %M.

* log: reserved vs used bytes per ggml context, and where each weight buffer landed

Every no_alloc ggml context is a host allocation made in full by
ggml_init, whether or not the tensor headers ever fill it. The process
peak in `--metrics` says how much of that there is in total; these
[TIMING] lines say which context, by the name the build_ms line next to
them already uses:

    yue2.nar.graph.ctx_reserved_mb 6144
    yue2.nar.graph.ctx_used_mb 10.603347778320312
    yue2.nar.weights.ctx_reserved_mb 6144
    yue2.nar.weights.ctx_used_mb 0.111602783203125
    yue2.nar.weights.buffer_mb 1533.761962890625
    yue2.nar.weights.buffer_name Vulkan1

New debug::timing_log_context_reservation(name, ctx) reads
ggml_get_mem_size / ggml_used_mem once the graph is built. Called from
the shared Qwen causal decode runtime (prefill, batched prefill, decode,
batched decode, block prefill), the greedy Qwen decoder, the MOSS delay
backbone, the two yue2 graph contexts, and BackendWeightStore::upload(),
which covers every weight store by its own name and adds the backend
buffer's size and name so a host fallback shows up as such.

Gated by the existing timing log; nothing runs without --log.

On this yue2 run (main, defaults, Linux/Vulkan on Intel) the contexts
reserve 29.8 GB for under 30 MB of headers, against a process VmPeak of
32.6 GB. 13.9 GB of that is the weight stores (the #151 class), 5.6 GB
the shared Qwen runtime, 10.2 GB the two yue2 graph contexts that #657
resizes.

Output byte-identical (yue2, 640 tokens, seed 1234).
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.

YuE2 CPU: NAR crashes with GGML_ASSERT(ctx->mem_buffer != NULL) on Ryzen (nightly 61e06 too; arena/tiling not applied on CPU)

2 participants