Skip to content

ESN: implement the online readout API; refuse unsupported configs - #8

Merged
drzo merged 12 commits into
masterfrom
claude/esn-implementation-docs-GoNIs
Oct 28, 2026
Merged

drzo merged 12 commits into
masterfrom
claude/esn-implementation-docs-GoNIs

Conversation

@drzo

@drzo drzo commented Oct 28, 2026

Copy link
Copy Markdown

Make sure to read the contributing guidelines before submitting a PR

Summary

Removes the remaining stubs and silent fallbacks in the ESN path.

Online readout API (was declared in llama.h with no definitions) — src/llama-esn.{h,cpp}

  • Contexts on models exported with esn.online_learning.enabled record the readout input (result_norm) of each output position, keyed by (seq_id, pos) and bounded by esn.replay_window.
  • llama_esn_submit_feedback turns corrections, tool results, rewards and confidences into weighted samples. Batches are all-or-nothing and bounded by esn.online_learning.buf_size. Latency events are rejected, since they carry no token target.
  • llama_esn_update_readout fits a per-context F32 copy of W_out:
    • ridge: Woodbury solve, refit from the checkpoint over the replay window
    • RLS: recursive, with forgetting
    • SGD: weighted cross-entropy steps
  • The graph uses the adapted readout via a new llm_graph_params::esn_readout, which is part of the graph-reuse check. The model and other contexts keep the checkpoint. llama_esn_reset_adaptation restores it exactly.
  • New esn.output_temperature key: the scale the exported readout was fit to (T·one-hot), so ridge/RLS updates keep it. New llama_esn_model_online_params returns the exported settings.
  • llama.h documents semantics and error codes. It no longer claims the adapted readout is in llama_state_* data.

Fallbacks removed

  • The loader now refuses these instead of warning about them or silently ignoring them:
    • esn.bidirectional
    • hierarchical keys (n_levels > 1, lateral links, top-down modulation)
    • an unfrozen reservoir
  • esn_training.py:
    • requires --train-data unless --init-only; the random-token fallback is gone
    • errors on a byte tokenizer with vocab_size != 256 instead of overriding it
    • writes online metadata with the correct mode (it used to map RLS to ridge) for batch-trained models too
    • writes esn.output_temperature for least-squares readouts
  • Docs (esn.md, esllm-roadmap.md, esn-completion.md, CLAUDE.md) no longer describe the API as stubs.

Testing

  • New CTest test-esn-online writes its own small models and checks:
    • ridge logits become exactly T·one-hot at the corrected position
    • RLS on one sample equals ridge
    • SGD raises or lowers probabilities for corrections and negative rewards
    • reset restores logits bit for bit
    • a second context is unaffected
    • updates apply under graph reuse
    • all error codes
  • It also passes on models trained by esn_training.py (batch ridge and online RLS).
  • ctest -R test-esn: 3/3 passed.
  • test-esn-inference passes on trained and --init-only models.
  • flake8 is clean.

Generated by Claude Code

llm_graph_input_rs never implemented can_reuse, so the default (false)
made llama.cpp rebuild and re-allocate the compute graph for every
decoded token of every recurrent architecture (Mamba, RWKV, ESN).

build_rs and the recurrent builders' state-store views bake n_rs, the
cell head and rs_z into view sizes and offsets; everything else they use
is an input tensor or fixed for the context. Record head and rs_z when
the input is built and allow reuse while all three are unchanged, which
holds for consecutive decode steps.

ESN decode throughput (4 threads, Q4_0 reservoir): +55% at R=256, +27% at
R=1024, +23% at R=2048, +13% at R=8192. Logits are bit-identical with
LLAMA_GRAPH_REUSE_DISABLE=1, including with two sequences decoded in
lockstep and one of them cleared and restarted mid-stream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
Prompt processing stacked the per-token reservoir states in a balanced
ggml_concat tree, copying each state log2(n) times. Write each step's
state into its row of one [reservoir_size, n_seq_tokens, n_seqs] buffer
instead. Each ggml_set_rows returns a view of the whole buffer that
depends on the previous write, so the readout sees every row, and the
graph topology still does not depend on which tokens are outputs.

pp512 (4 threads, Q4_0): +26% at R=1024, +29% at R=2048, unchanged at
R=256 (all in cache) and R=8192 (bound by reading W_res). Logits are
bit-identical to the concat tree for one and several sequences and for
ubatch sizes 512, 64 and 7.

test-esn-inference J failed on Q4_0 models, on master as well: batched
and stepwise decoding use different W_in kernels, and a rounding
difference that flips one Q8_0-quantized state value leaves the later
positions of that sequence off by up to 0.1. Check for the signature of
a misplaced row instead, a jump from a close match straight to O(1);
an injected one-row shift in the stacking still fails it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
The CPU backend computed tanh with scalar libm tanhf (~20 ns/element),
14% of single-thread work at R=1024, and a one-row reservoir state left
the other threads waiting on it. tanh and sigmoid in unary-ops.cpp are
now branch-free (minimax polynomial below |x|=0.625, inline exp above),
so they auto-vectorize: 0.8 ns/element with AVX2, within 1.2 and 2 ulp.
tests/test-esn-activations.cpp checks them against double references.

With token inputs the ESN input drive (s_in*W_in*E + biases +
s_fb*W_fb) depends on the token alone. esn_training.py now stores it as
esn_input_table (--no-input-table to omit), and llm_build_esn reads it
with one get_rows instead of up to seven nodes. Scales by 1 are skipped.

4-thread medians, before -> after: pp512 R=1024 20361 -> 37590 tok/s,
tg256 R=1024 11956 -> 18560, R=2048 3470 -> 4440. Logits change by
rounding only; held-out perplexity and C++/Python parity are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
The llama_esn_* functions declared in llama.h had no definitions. They now
retrain a per-context copy of W_out from feedback:

- Contexts on models exported with esn.online_learning.enabled record the
  readout input (result_norm) of every output position, keyed by
  (seq_id, pos), bounded by esn.replay_window.
- llama_esn_submit_feedback turns corrections, tool results, rewards and
  confidences into weighted samples (all-or-nothing, bounded by
  esn.online_learning.buf_size); latency events are rejected.
- llama_esn_update_readout fits the context's F32 readout by ridge
  (Woodbury, refit from the checkpoint over the replay window), RLS or
  SGD. The graph uses it instead of the model tensor; other contexts and
  the model are unchanged. llama_esn_reset_adaptation returns to the
  checkpoint.
- New esn.output_temperature records the scale the exported readout was
  fit to, so least-squares updates keep it; new
  llama_esn_model_online_params returns the exported settings.

Silent degradations removed: the loader refuses esn.bidirectional,
hierarchical keys and an unfrozen reservoir instead of warning or ignoring
them; esn_training.py requires --train-data (no random-token fallback),
errors on a byte tokenizer with vocab != 256 instead of overriding it, and
writes online metadata with the correct mode for any trained model.

tests/test-esn-online.cpp checks each mode against its closed form, reset,
per-context isolation, graph reuse and the error codes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
@github-actions github-actions Bot added documentation Improvements or additions to documentation testing labels Oct 28, 2026

drzo commented Oct 28, 2026

Copy link
Copy Markdown
Author

editorconfig is failing, but not because of this PR. It flags trailing whitespace and missing final newlines in docs/gpt-oss.md, examples/gpt-oss-README.md and examples/gpt-oss-example.sh. This PR doesn't touch any of those files, and the same check also fails on master. No fix exists yet. The proposed fix is to strip the trailing whitespace and add a final newline to those three files, as a separate change; I've left it out of this PR to keep the scope narrow. A re-run would fail the same way, so I haven't re-run it.


Generated by Claude Code

drzo commented Oct 28, 2026 •

Copy link
Copy Markdown
Author

Five more failures that are not caused by this PR. All five jobs stopped during setup, before anything was built:

  • android-build: Android sdkmanager exited with code 1 while installing the SDK. This job also fails on master.
  • windows-latest-cmake (cpu-x64 (static)): the libcurl dependency download wasn't a valid archive (tar.exe: Error opening archive: Unrecognized archive format).
  • server-windows, windows-latest-cmake-hip and windows-2022-cmake-cuda (12.4): the same libcurl download failure.

The libcurl failure is persistent, so a re-run won't help. .github/actions/windows-setup-curl downloads a pinned build, https://curl.se/windows/dl-8.6.0_6/curl-8.6.0_6-win64-mingw.zip. That URL now returns an HTTP 404 HTML page, which tar.exe then refuses. curl.se only hosts the latest Windows build, and https://curl.se/windows/archive/ is also 404. This PR doesn't touch that action, so I've left it out of the PR. Proposed patch, which fetches whatever build is current:

-        curl.exe -o $env:RUNNER_TEMP/curl.zip -L "https://curl.se/windows/dl-${env:CURL_VERSION}/curl-${env:CURL_VERSION}-${env:ARCHITECTURE}-mingw.zip"
+        curl.exe --fail -o $env:RUNNER_TEMP/curl.zip -L "https://curl.se/windows/latest.cgi?p=${env:ARCHITECTURE}-mingw.zip"

(latest.cgi?p=win64-mingw.zip currently redirects to dl-8.23.0_5.) If a pinned build is preferred, bump the default curl_version to 8.23.0_5 instead, and that pin will break again on curl's next release. android-build failed the same way again on the new head (4917497), so it is persistent too. The runner's preinstalled cmdline-tools is "Wrong version", so the setup action installs its own, and then cmdline-tools/16.0/bin/sdkmanager tools exits 1. The legacy tools package isn't served for that sdkmanager version any more. The fix belongs in the workflow's Android SDK setup (pin a matching cmdline-tools version, or drop the tools package). That is outside this PR and has no fix yet.

pyright type-check (in both workflows that run it) is also failing, but not because of this PR. Every error is in a Python file this PR doesn't change (examples/json_schema_pydantic_example.py, gguf-py/gguf/vocab.py), none is in scripts/esn_training.py, and the same check fails on master. No fix exists yet.

Two build failures, also present on master, are in code this PR doesn't touch:

  • macOS-latest-cmake-arm64: -Werror errors in common/common.cpp (deprecated wstring_convert in the Xcode 26 SDK) and in vendor/minja/minja.hpp (-Wmissing-noreturn). There are no errors in src/ or tests/.
  • ubuntu-22-cmake-sycl and ubuntu-22-cmake-sycl-fp16: syclcompat/math.hpp is missing from the installed SYCL toolchain, so the error comes from ggml/src/ggml-sycl.

ggml-ci-arm64-cpu-high-perf-sve is also failing, but not because of this PR. All of its ctest suites pass, the ESN tests included. The only failure is the reranker model check: rerank score 2 @ 0.040 (FAIL: score not in range [0.10, 0.30]). That check uses a BERT reranker, which this PR doesn't touch, and the job also fails on master.


Generated by Claude Code

…ulkan ccache

With a GPU backend, the ggml_set_rows stacking indexed each step by a view
of a CPU input tensor, and the scheduler copies each view as a separate
split input; a 128-token ubatch exceeded GGML_SCHED_MAX_SPLIT_INPUTS and
aborted at context creation (test-esn-online on ubuntu-24-cmake-vulkan).
set_rows is kept when the CPU is the only backend (it is ~13% faster at
R=1024 there); otherwise the steps are concatenated in a balanced tree,
as before #6.

ubuntu-24-cmake-vulkan builds with GGML_NATIVE and shared ccache objects
across runner CPUs (SIGILL in test-backend-ops and test-esn-activations);
key its cache on the CPU fingerprint as the ggml-ci jobs already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav

drzo commented Oct 28, 2026 •

Copy link
Copy Markdown
Author

Unlike the earlier failures, ubuntu-24-cmake-vulkan failed because of this PR, and 6b77faf fixes it:

  • test-esn-online aborted with GGML_ASSERT(n_inputs < GGML_SCHED_MAX_SPLIT_INPUTS) while creating the context. The ESN graph's set_rows stacking indexes each step with a view of a CPU input. On a GPU backend, the scheduler copies every one of those views as a separate split input, so a 128-token ubatch went over the limit of 30. This bug came in with Recurrent graph reuse and O(n) ESN output stacking #6; the new test is the first thing to run the ESN graph on a GPU backend in CI. set_rows is now used only when the CPU is the only backend, where it is about 13% faster at R=1024. Otherwise the steps are combined with a balanced ggml_concat tree, which is how it worked before Recurrent graph reuse and O(n) ESN output stacking #6. Both paths pass test-esn-online and test-esn-inference locally.
  • test-esn-activations and test-backend-ops crashed with SIGILL. This job builds with GGML_NATIVE on and shares its ccache across runners with different CPUs. Its cache key now includes the CPU fingerprint, as the ggml-ci jobs' keys already do.

Generated by Claude Code

@drzo
drzo marked this pull request as ready for review October 28, 2026 17:54
Copilot AI balanced review requested due to automatic review settings October 28, 2026 17:54
@cursor

cursor Bot commented Oct 28, 2026

Copy link
Copy Markdown

Bugbot needs on-demand usage enabled

Bugbot uses usage-based billing for this team and requires on-demand usage to be enabled.

A team admin can enable on-demand usage in the Cursor dashboard.

ubuntu-22-cmake-webgpu builds with GGML_NATIVE (-march=native) and runs
ctest, but its ccache key ignored the CPU. Objects built on a runner
with a newer instruction set were restored on an older one, and
test-esn-activations and test-esn-online died with SIGILL. Use the same
CPU-fingerprint key as the Vulkan and ggml-ci jobs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
@cursor

cursor Bot commented Oct 28, 2026

Copy link
Copy Markdown

Bugbot needs on-demand usage enabled

Bugbot uses usage-based billing for this team and requires on-demand usage to be enabled.

A team admin can enable on-demand usage in the Cursor dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Online adaptation has critical crash paths and correctness defects, including unsafe allocation retries, training on stale reservoir states, and silently dropping LoRA contributions.

8 open issues
What changed in this PR

Implements per-context ESN online readout adaptation in the llama runtime, replacing undefined APIs and rejecting unsupported model configurations.

Changes:

  • Adds feedback capture, ridge/RLS/SGD updates, reset support, and graph integration.
  • Tightens model and training validation, exports adaptation metadata, and updates documentation.
  • Adds online-adaptation tests and CPU-specific cache keys for Vulkan/WebGPU CI.
File Description
tests/​test-esn-online.cpp Adds synthetic-model tests for adaptation and API behavior.
tests/​CMakeLists.txt Registers the online-adaptation CTest.
src/​llama-model.cpp Integrates adapted readouts and multi-backend state stacking.
src/​llama-hparams.h Adds output-temperature metadata storage.
src/​llama-hparams.cpp Validates adaptation settings and rejects unsupported configurations.
src/​llama-graph.h Adds readout and capture parameters to graph reuse checks.
src/​llama-graph.cpp Initializes ESN graph parameters.
src/​llama-esn.h Defines per-context adaptation state and operations.
src/​llama-esn.cpp Implements feedback, optimizers, reset, and public APIs.
src/​llama-context.h Adds context-owned adaptation state.
src/​llama-context.cpp Captures readout inputs and supplies adapted graph weights.
src/​llama-arch.h Declares the output-temperature metadata key.
src/​llama-arch.cpp Maps the output-temperature GGUF key.
src/​CMakeLists.txt Includes the adaptation implementation in libllama.
scripts/​esn_training.py Requires explicit training data and exports adaptation metadata.
include/​llama.h Documents API semantics, settings, and error codes.
docs/​esn.md Explains adaptation modes, costs, and limitations.
docs/​esn-completion.md Updates implementation and test evidence.
docs/​esllm-roadmap.md Distinguishes implemented adaptation from future tool integration.
CLAUDE.md Updates ESN development guidance and examples.
.github/​workflows/​build.yml Adds CPU fingerprints to Vulkan/WebGPU cache keys.

Review effort: Balanced

Comment thread src/llama-esn.cpp Resolved
Comment thread src/llama-esn.cpp Resolved
Comment thread src/llama-esn.cpp Resolved
Comment thread src/llama-esn.cpp Resolved
Comment thread src/llama-model.cpp Resolved
Comment thread scripts/esn_training.py Resolved
Comment thread src/llama-esn.cpp Resolved
Comment thread tests/test-esn-online.cpp Resolved
Review fixes for the llama_esn_* online readout API:

- Captures follow the sequence: every decoded token, output or not,
  discards recordings at and after its position, and feedback is refused
  for positions past the memory's newest one. Before, re-decoding a
  cleared sequence with logits only at the end left the old prompt's
  states trainable at the earlier positions.
- The readout check refuses every CPU extra buffer type (REPACK, AMX)
  found through ggml_backend_dev_get_extra_bufts, instead of matching
  "REPACK" by name; AMX has no get_tensor and crashed.
- The adapted readout is built in locals and committed only once
  allocated, so a failed allocation can be retried or reset safely.
- A singular ridge pivot (below 1e-12 of its diagonal) or a non-positive
  RLS denominator returns -9 instead of aborting; RLS restores W and P,
  so the readout and the pending samples are unchanged.
- submit checks the buffer bound before each copy rather than after
  copying the whole batch.
- A LoRA on the readout and an adapted readout exclude each other (-10
  from the update; llama_set_adapter_lora returns -1 while adapted),
  since the adapted tensor would silently drop the LoRA delta.
- Setting, removing or clearing LoRA adapters now resets the previous
  graph: graph reuse compared the adapter map by address only, so an
  adapter added after a decode was not applied.
- esn_training.py refuses --save-online-metadata with --init-only unless
  the runtime mode is SGD: ridge/RLS need esn.output_temperature.
- The ESN tests call ggml_backend_load_all() (GGML_BACKEND_DL builds).

test-esn-online adds I (rewind/clear), J (singular solve) and K (LoRA).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
Copilot AI balanced review requested due to automatic review settings October 28, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The RLS decay update erodes the documented fixed checkpoint penalty, while unresolved state-restoration and vocabulary-size bugs can train on stale vectors and cause out-of-bounds reads.

3 open issues
4 previously missed issues

In code that hasn't changed since last review

Medium severity Reject decay values that round to 1.0 in float32

scripts/​esn_training.py:1250

A forgetting factor such as 1e-9 passes this check, but its exported decay rounds to 1.0 in float32. With --save-online-metadata, this produces a model that the loader rejects because decay must be below 1, including the permitted SGD --init-only export. Validate the float32 decay here so the argument error is reported before training or export.

Medium severity Invalidate recordings when restoring state or replacing sequences

src/​llama-esn.cpp:170

A position bound cannot detect history replacement through state restoration or sequence copying. For example, decode prompt A, then load a snapshot of prompt B ending at the same position with llama_state_set_data(): the state-loading paths replace memory but leave recorded untouched, so feedback on B's restored outputs passes this check and trains on A's reservoir vectors. Invalidate the affected recordings when state is restored or a destination sequence is replaced, rather than relying solely on seq_pos_max() and subsequent decoding.

Medium severity Derive invalid-token sentinel from the loaded vocabulary

tests/​test-esn-online.cpp:262

In the external-model mode, token 256 is not necessarily out of range. A trained model exported with --tokenizer none --vocab-size 512 accepts this target, so the assertion expecting -3 fails even though the API behaved correctly. Derive the invalid-token sentinel from the loaded model's vocabulary size instead of the synthetic model's constant.

Medium severity Size logits copy and comparison to the loaded vocabulary

tests/​test-esn-online.cpp:382

The optional model argument can name a model with fewer than 256 tokens, such as a trained --tokenizer none --vocab-size 128 model. Its logits row contains only 128 floats, so copying N_VOCAB floats here reads past the row; the later comparison also indexes beyond the shorter baseline vector. Size this copy using the loaded model's vocabulary, as decode_all() already does.

7 resolved since last review

Review effort: Balanced

Comment thread src/llama-esn.cpp Resolved
Comment thread src/llama-context.cpp Resolved
…view

Second round of review fixes for the llama_esn_* online readout API:

- llama_memory_i gains seq_epoch(), which the recurrent memory advances
  whenever a sequence's content is replaced instead of extended or
  truncated: clear, seq_cp onto it, seq_add/seq_div, state restore. The
  ESN adapter tags recordings with it and refuses ones from an older
  epoch, so feedback after llama_state_set_data no longer trains on the
  vectors of the history that was replaced (test L).
- Clearing an empty LoRA set, or re-setting an adapter at the same
  scale, no longer discards the reusable graph; the server clears
  adapters before every batch.
- The documented RLS objective now states that forgetting decays the
  pull toward the checkpoint as well (exact for decay 0); a fixed anchor
  is what ridge provides.
- esn_training.py rejects a --forgetting-factor whose decay rounds to 1
  in float32, which the loader would refuse.
- test-esn-online sizes its out-of-range token and logits copies by the
  loaded model's vocabulary, so it works on external models of any size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
Copilot AI balanced review requested due to automatic review settings October 28, 2026 18:41
@cursor

cursor Bot commented Oct 28, 2026

Copy link
Copy Markdown

Bugbot needs on-demand usage enabled

Bugbot uses usage-based billing for this team and requires on-demand usage to be enabled.

A team admin can enable on-demand usage in the Cursor dashboard.

drzo commented Oct 28, 2026

Copy link
Copy Markdown
Author

Fixed the four previously missed issues from the second review in 80a067e:

  • State restore and sequence replacement (src/llama-esn.cpp): llama_memory_i now has seq_epoch(). The recurrent memory increments it whenever a sequence's content is replaced rather than extended or truncated: on clear, seq_cp onto the sequence, seq_add/seq_div, and state restore (both full and per-sequence). The adapter tags its recordings with the epoch, drops them when the epoch changes, and refuses feedback for recordings from an older epoch. New test L decodes prompt A, saves the state, decodes a reversed prompt ending at the same position, restores A, and checks that feedback is refused.
  • Float32 decay rounding (scripts/esn_training.py): with --save-online-metadata, a --forgetting-factor whose 1 − f rounds to 1 in float32 is now an argument error, so the script no longer exports a model the loader rejects.
  • Invalid-token sentinel and logits copy (tests/test-esn-online.cpp): both are now sized by the loaded model's vocabulary instead of the synthetic model's 256, so the test runs on external models of any vocabulary size.

The LoRA thread is still listed as open. As replied there, I made LoRA on the readout and an adapted readout mutually exclusive rather than folding the LoRA delta into the fit.


Generated by Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Casting solved coefficients to float before accumulation can silently erase readout corrections for repeated or correlated samples while still reporting success.

1 open issue
4 previously missed issues

In code that hasn't changed since last review

High severity Float accumulation loses cancellation in repeated weight corrections

src/​llama-esn.cpp:446

Casting each solved coefficient to float before accumulation loses the cancellation required for repeated or correlated samples. For example, with a 64-element all-ones input, zero checkpoint readout, T=2, default regularization 1e-6, and two corrections to that same input targeting different tokens, Cholesky succeeds but the coefficients round to +1000000 and -1000000. Both target logits become 0 instead of approximately 1, and the update reports success. Accumulate each weight's correction in double precision and cast only the final weight to float.

Medium severity Unchanged LoRA adapters unnecessarily invalidate reusable graphs

src/​llama-context.cpp:767

With an active LoRA, server generation now discards the reusable graph every batch, even when adapters and scales are unchanged. tools/server/server.cpp:3752 calls common_set_adapter_lora(), whose clear-and-readd cycle (common/common.cpp:1110–1113) bypasses both the empty-map and unchanged-scale guards. Reconcile the desired adapter set without clearing unchanged entries, or compare it against a graph-owned snapshot before invalidating reuse.

Medium severity Mark readout host buffer as weights to prevent per-token transfers

src/​llama-esn.cpp:278

Please mark this host buffer as containing weights, as model buffers are in llama-model.cpp:6163. Without that flag, the scheduler can propagate the GPU assignment from result_norm to the readout matmul instead of placing it with W_out. On a discrete CUDA GPU this makes the entire adapted F32 readout a split input copied from host on every decode, including reused single-token graphs, adding 4·R·V bytes of transfer per generated token. Setting the weight usage lets single-token decoding run the projection on the CPU without repeatedly transferring W_out.

Medium severity Zero-weight samples fail to advance the forgetting clock

src/​llama-esn.cpp:486

A zero-confidence or zero-reward sample skips forgetting as well as the weight update. With nonzero decay, this makes later gains disagree with the documented sample-age objective: for scalar x=1, W0=0, T=1, lambda=1 and decay=0.5, weights [0, 1] produce W=2/3 instead of 0.8. Apply P /= (1 - decay) in this branch while leaving W unchanged, so zero-weight samples still advance the forgetting clock.

2 resolved since last review

Review effort: Balanced

With weights on the CPU and op_offload moving large-batch ops to a GPU,
the unrolled recurrence ended up split across backends and every
per-step view became a separate split input, tripping
GGML_ASSERT(n_inputs < GGML_SCHED_MAX_SPLIT_INPUTS).

- Classify the recurrence tensors (W_in, W_res, feedback, biases, input
  table) as REPEATING on block 0 so they live with the recurrent state;
  GGUF names are unchanged.
- Pin the input drive, the per-step ops and the output stacking to the
  backend that holds W_res, and only use set_rows stacking when that
  backend is the CPU.
- ggml_backend_sched_reserve no longer resets the scheduler before
  splitting (as upstream), so assignments made while building the
  graph are honored when compute buffers are reserved.
- test-esn-inference: ESN_TEST_LOG keeps logging on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
Copilot AI balanced review requested due to automatic review settings October 28, 2026 19:01
@github-actions github-actions Bot added the ggml label Oct 28, 2026

drzo commented Oct 28, 2026

Copy link
Copy Markdown
Author

ubuntu-24-cmake-vulkan: fixed in 09ecb0e.

The cause was GGML_ASSERT(n_inputs < GGML_SCHED_MAX_SPLIT_INPUTS) at context creation. With the weights on the CPU, op_offload moved the batched input projection onto Vulkan. The unrolled recurrence then pulled each per-step view across backends, and every view counted as its own split input.

Changes:

  • Tensor placement: the recurrence tensors are classified REPEATING on block 0, so they live with the recurrent state. GGUF names are unchanged.
  • Pinning: the input drive, the steps and the stacking are pinned to W_res's backend.
  • ggml backend fix: ggml_backend_sched_reserve no longer resets the scheduler before splitting. Upstream already dropped that reset. Without this, pins made while building the graph were discarded during buffer reservation.

Verified locally with Vulkan (llvmpipe):

  • test-esn-online: PASSED (A..L)
  • test-esn-inference: PASSED (A..J) on six trained models, including input-table and feedback models
  • The CPU build passes too.

The remaining red checks on 80a067e are the unrelated ones covered in my earlier comment (Windows libcurl 404, editorconfig, pyright, android, macOS, sycl, SVE).


Generated by Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to weigh process-terminating thread failures alongside learning-correctness, shared-state invalidation, and backend and adapter performance risks.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Test G checked that after reset_adaptation, decoding the prompt one
token at a time reproduces base[at], which came from decoding the whole
prompt in one batch. On a GPU backend the two graph shapes can use
different matmul kernels, so the logits differ by rounding: the
ubuntu-24-cmake-vulkan job failed on that 1e-5 bound. Take the
unadapted baseline with the same one-token stepping, compare the reset
result against it at 1e-5, and keep a 1e-3 sanity bound between the
batched and stepped logits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETGJBpWVh57qbY3fnTFwav
Copilot AI balanced review requested due to automatic review settings October 28, 2026 19:53

drzo commented Oct 28, 2026

Copy link
Copy Markdown
Author

ubuntu-24-cmake-vulkan on 09ecb0e: the split-input abort is gone. The run now reached test-esn-online step G and failed at test-esn-online.cpp:398, max_abs_diff(step_all(), base[at]) < 1e-5f.

Step G compared stepped logits against the batched baseline. One side decoded the prompt one token at a time; base[at] came from decoding it in one batch. On the CI Vulkan driver those two graph shapes use different matmul kernels, so the logits differ by rounding.

Fixed in dd50849: the reset result is now compared against a baseline taken with the same one-token stepping (1e-5). A 1e-3 sanity bound between batched and stepped logits remains. Verified locally on the CPU and Vulkan (llvmpipe) builds.


Generated by Claude Code

@cursor

cursor Bot commented Oct 28, 2026

Copy link
Copy Markdown

Bugbot needs on-demand usage enabled

Bugbot uses usage-based billing for this team and requires on-demand usage to be enabled.

A team admin can enable on-demand usage in the Cursor dashboard.

@drzo
drzo merged commit e80dd5c into master Oct 28, 2026
43 of 68 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Cross-cutting risks in numerical updates, GPU transfers, graph reuse, and sequence-history tracking require human assessment of correctness and performance.

No open issues 🎉

Review effort: Balanced

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

Labels

devops documentation Improvements or additions to documentation ggml testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants