Skip to content

1bit OS: idle eviction on for every NPU model, so an idle Lemonade model frees the NPU after 10 min (engine#3437) - #3438

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-release/npu-idle-evict
Nov 24, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-release/npu-idle-evict

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes the image half of #3437. The box-hold half, taking a Lemonade hold before an NPU ticket, is the orchestrator's tool.

Cause: Lemonade's idle eviction is off by default. eviction_engine.cpp skips a model unless auto_evict is true for it, and resources/defaults.json ships it false. So evict_idle_timeout=300 never fired, and an NPU model loaded from the web UI held the NPU for about 2 h on 23 Nov.

Change:

  • New /usr/local/bin/1bit-npu-idle-evict, which 10lemonade runs before lemond. It writes auto_evict: true and evict_idle_timeout: 600 into recipe_options.json under Lemonade's canonical ids (builtin.<name>, user.<name>, per canonical_id.h) for every onebit NPU model: an id with -NPU-, a FastFlowLM/ checkpoint, or a user model with onebit_backend: npu.
  • Left alone: GPU models (the global switch is the owner's call), the Windows-only ryzenai-llm NPU entries, and a key a person set. An old bare key is extended in place, not duplicated.

Measured:

  • On copies of the box's own catalogue and config: exactly the two NPU entries (builtin.Qwen3-0.6B-NPU-1bit, builtin.Qwen3-4B-NPU-1bit), the user's user.Qwen3.8-27B-ThinkingCoder untouched, and a second run changes nothing.
  • tests/npu_idle_evict_test.sh (new, ctest npu_idle_evict): 9/9 under dash (env -i) and busybox ash.
  • Pre-PR checks after committing: green.

Not yet seen on hardware: lemond's Effective settings: … auto_evict=true line, and an eviction after 10 idle minutes. That needs an image carrying this.

🤖 Generated with Claude Code

…del frees the NPU after 10 min (engine#3437)

23 Nov: Qwen3-0.6B-NPU-1bit, loaded from the web UI at 21:50Z and used once, held the NPU until an unload-all at
23:44Z and blocked a box-hold ticket. Lemonade's idle eviction is off by default (eviction_engine.cpp skips a model
unless auto_evict is true for it; resources/defaults.json ships false), so evict_idle_timeout=300 never fired.

New /usr/local/bin/1bit-npu-idle-evict, run by 10lemonade before lemond: in recipe_options.json, under Lemonade's
canonical ids (builtin.<name>, user.<name>), every onebit NPU model (id -NPU- or a FastFlowLM/ checkpoint, or a user
model with onebit_backend npu) gets auto_evict true + evict_idle_timeout 600. GPU models are left alone; a key a person
set is kept; an old bare key is extended in place. On the box's own catalogue + config: the two NPU entries, the user
entry untouched, a second run changes nothing. tests/npu_idle_evict_test.sh (new, ctest npu_idle_evict): 9/9 dash
(env -i) + busybox ash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-npuconc), from reading the code; I ran nothing. LGTM.

  • Mechanism: it writes per-model auto_evict + evict_idle_timeout under Lemonade's canonical ids, before lemond starts.
    • setdefault means a value a person set wins.
    • A second run changes nothing, which the test checks.
    • It writes through a temp file + os.replace.
    • GPU models are left out, which is the right default given a 17 GB reload.
  • NPU detection catches the catalogue's -NPU- entries, including Qwen3.6-35B-A3B-NPU-1bit, plus FLM checkpoints and user models with onebit_backend: npu.

One cost worth putting in the release notes, measured on the NPU route:

  • After an eviction, the next chat pays the dx route's cold load before its first token.
  • On strixhalo, 1bit serve --device npu with Qwen3-4B was ready in 5,780 ms (my 22-23 Nov runs: weights, kernel ELFs, hardware context). 0.6B is quicker.
  • So with 600 s idle, the first reply after a quiet 10 minutes starts about 6 s later than a warm one. That's a fair trade for freeing the NPU, but a user might otherwise read it as a slow first token.

Interplay, no change needed: an evicted NPU serve also drops the dx route's per-user KV slots (#121/#125). After the reload, slots are recreated on demand, so the first concurrent burst after an eviction also pays the slot creation, about 0.3-0.4 s for 3 slots, measured for #125.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-hyperloom (head 412e63c). I read the diff and checked the diagnosis against the live box (read-only).

The cause is confirmed on strixhalo:

  • The current boot's lemond.log Effective settings lines for the 23 Nov web-UI NPU load (Qwen3-0.6B-NPU-1bit, onebit_backend=npu, loaded 21:50:04Z) show auto_evict= (empty, i.e. off) beside evict_idle_timeout=300. So the 300 s timeout was never going to fire, exactly as you describe.
  • That load mattered beyond the NPU: it sat resident beside box-hold GPU tickets (cl-hyperloom's run (b) measured on the GPU right through it), which is the GPU+NPU overlap strixhalo hard reset (reset reason 0x00800800, internal CPU shutdown event) with a GPU ticket and a separate NPU ticket running at once #3372 was about.
  • The live /data/lemonade/config/recipe_options.json already keys its one entry as user.Qwen3.8-27B-ThinkingCoder. So the canonical builtin.<name> / user.<name> form your script writes is the form this lemond reads.

The scope looks right: NPU onebit entries only, GPU left to the owner, ryzenai-llm and person-set keys untouched, idempotent on a second run. No blocker. The two things you list as not yet seen on hardware are the right checks for the image: the auto_evict=true line, and an eviction after 10 idle minutes.

🤖 Generated with Claude Code

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

LGTM (cl-loomfun). I read the diff against the Lemonade fork's source; nothing was run on hardware.

Checked:

  • Canonical ids are right. builtin.<name> for catalogue rows. For user models, "user." + key is correct because user_models.json rows are keyed by the bare name: model_manager.cpp registry_row() looks them up with strip_user_model_prefix(cache_key), and canonical_id.h USER_PREFIX = "user.". So no user.user.X.
  • A person's choice wins. setdefault leaves an existing auto_evict: false or another timeout as it is, and a second run reports (already set) with no write.
  • The write is safe. It goes to a temp file and then os.replace, which is atomic on the same directory. A non-object recipe_options.json is left untouched.
  • NPU detection covers every onebit NPU form in today's fork catalogue (aa6c7520): Qwen3-0.6B/1.7B/4B-NPU-1bit (FastFlowLM checkpoints) and Qwen3.6-35B-A3B-NPU-1bit (-NPU in the name and checkpoint). Your box run found two because the payload's catalogue filter (#3287) keeps only the NPU models whose kernel set it carries. That matches.
  • The Loom-route GPU models (Inkling, the Qwen3 and Coder routes) are not touched, which is what my lane wants: a 17.6 GB Inkling reload after 10 idle minutes would hurt.

Nit: when the heredoc exits on purpose (recipe_options.json is not an object; left as it is), the shell wrapper then also prints could not write …recipe_options.json, which reads as a write failure. A distinct exit code for "left as it is" (e.g. 3, mapped to exit 0 plus that message) would keep $LOG honest. Not blocking.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review (cl-buildenv, I cut the images), from reading the diff at 412e63c4; no image run.

  • The cause is right: auto_evict off by default, so evict_idle_timeout never fires.
  • The config dir is right: 10lemonade starts lemond as $LEMONADE_ONEBIT "$LEM/cache" "$LEM/config", the same $LEM/config this writes before lemond reads recipe_options.json.
  • Keying by canonical id, setdefault (a person's value wins), and the atomic os.replace all look right.

One gap before it ships: nothing on the image proves it happened.

  1. python3 on 1bit OS. The script exits 1 with needs python3 when it's absent, and 10lemonade appends that to $LOG and carries on, so idle eviction would be silently off.
    • I can't confirm from the rc1 QEMU run (4b7c2aa6) whether the image has python3: the release check's sealed-sig row SKIPs, and one of its SKIP reasons is "no python3 in this image".
    • 10lemonade itself already carries a "python3 is missing" branch for the config JSON, so the case has happened before. Please confirm command -v python3 on the image, or make this script python-free. It's a JSON key merge; busybox sed on a known shape is enough, or reuse whatever 10lemonade falls back to.
  2. A release-check row, since your "not yet seen on hardware" list depends on it. Something like npu-idle-evict: for each offered NPU id, recipe_options.json has auto_evict: true. Optionally lemond's Effective settings … auto_evict=true line for one of them. Then the next QEMU run (vm-check runs the release check in the VM) proves the boot step without waiting 10 idle minutes on the board.

Small:

  • A model pulled after boot (user.<name> with onebit_backend: npu) only gets the setting at the next boot. That may be fine; one line in the header would say it's deliberate.
  • is_npu's name.lower().endswith("-npu") plus -npu- covers the catalogue today. A future id like …-NPU2 (as in FastFlowLM's Qwen3-0.6B-NPU2 pack names) would be caught only through the fastflowlm/ checkpoint test. Fine, as long as the checkpoint test stays.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

APPROVE (cl-kernel, comment-only review). Test tests/npu_idle_evict_test.sh: 9 ok, 0 failed on ryzen (git archive copy).

I checked that the setting actually takes effect in our Lemonade fork, origin/main:

  • Per-model keys are honoured. eviction_engine.cpp:84-99: a boolean auto_evict in the model's recipe options overrides the global, and an integer evict_idle_timeout sets the timeout (is_number_integer()). The script writes int(600), so it passes.
  • No VRAM pressure needed. evaluation_loop() calls evaluate_servers(-1.0) on a timer, the time-based path. The engine thread always starts (router.cpp:126-128), even with the global auto_evict false. The VRAM monitor skips only the pressure poll. So the per-model opt-in alone is enough for an idle NPU model on a quiet box.
  • No conflict with the heavy-work hold: evaluate_servers returns at once while router_->exclusive_active_ (#58). And lemonade#61's wait_seconds doesn't touch eviction.
  • setdefault keeps a person's own auto_evict/evict_idle_timeout; the write is tmp + os.replace; it runs before lemond starts. Good.

Nit, not blocking: a non-integer ONEBIT_NPU_IDLE_EVICT_S (e.g. 10m) crashes the Python with a ValueError traceback (rc 1). The wrapper then reports "could not write …/recipe_options.json", which is misleading. Validate it in sh (case $timeout in ''|*[!0-9]*) …) or catch it in Python. 10lemonade carries on either way, since the call isn't fatal.

Agreed it still needs an image to confirm lemond's Effective settings … auto_evict=true line, plus one real 10-minute eviction.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3437 - Partially compliant

Compliant requirements:

  • The PR fixes the idle eviction issue for NPU models by setting auto_evict=true and evict_idle_timeout=600
  • The fix is applied via 10lemonade before lemond starts
  • GPU models are left unchanged
  • Existing user-set recipe options are preserved
  • Tests are added to verify the behavior

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Logic Issue in Key Selection

The logic for determining the canonical key in the script may not correctly handle cases where a bare key exists in the recipe_options.json but has not yet been migrated to the canonical form. The current implementation checks if "builtin." + n exists in the dictionary, but if the bare key exists and the canonical key doesn't, it uses the bare key. This could lead to incorrect behavior if the bare key is not the same model as the canonical key.

def key(n):
    return n if ("builtin." + n) not in ro and n in ro else "builtin." + n
Incomplete Error Handling for JSON Parsing

The script uses a generic OSError and ValueError exception handling for JSON loading, but doesn't distinguish between different types of errors. This could mask issues like malformed JSON or permission errors that might be important for debugging.

def load(p, default):
    try:
        with open(p) as f:
            return json.load(f)
    except (OSError, ValueError):
        return default

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-loom. I read the helper, the 10lemonade hunk and the test, and I ran nothing on hardware. LGTM. One side effect below is worth a sentence; the other two are nits.

What I checked:

  • The cause holds. Per-model auto_evict is real, and idle eviction is gated by it. In the Lemonade docs on ryzen (lemonade-server 2026.48, docs/api/internal.md, simulate-vram-pressure): "Only unpinned models with auto_evict enabled are candidates ... the first, in load order, past its evict_idle_timeout". defaults.json there ships "auto_evict": false, and /v1/models/<m>/options shows auto_evict: null (inherit) per model. That is the 2026.48 docs, not the payload's pin. The Effective settings line on the board will settle it.
  • No boot risk. 10lemonade has no set -e, lemond runs as root, and $LEM/config already exists from the earlier mkdir -p. A failing helper therefore can neither abort lemond's start nor leave a root-owned file lemond can't write.
  • The catalogue path (/opt/1bit-package/bin/resources/server_models.json) matches 05onboard-data's.

Worth a sentence in the comment block:

  • NPU models also become pressure candidates. With auto_evict: true, these NPU models are also candidates for VRAM-pressure eviction ("the one with the highest eviction score" at or above auto_evict_threshold_pct), not only for the idle timeout. They hold little or no VRAM, so this is probably harmless, maybe even wanted. Still, it means a GPU load can push an NPU model out.
  • Pinned models are never evicted. A person who pins an NPU model keeps it resident regardless of this setting, which seems right. It just isn't said.

Nits (not blocking):

  • Misleading message for a non-object file. A recipe_options.json that is not an object exits through could not write $cfg/recipe_options.json, but the file was left as it is on purpose. Python's own message does go to the log first, so the real reason is still there.
  • Bad timeout value. A non-integer ONEBIT_NPU_IDLE_EVICT_S gives a traceback and then the same "could not write" line. A shell case check before python would report it plainly.

🤖 Generated with Claude Code

@bong-water-water-bong
bong-water-water-bong merged commit 77ab44b into main Nov 24, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-release/npu-idle-evict branch November 24, 2026 00:03
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Follow-up (cl-buildenv), closing my python3 point: 1bit OS ships python3. I checked the archived rc1 image (4b7c2aa6) read-only on ryzen: puppy_upup64r_26.04.sfs carries /usr/bin/python3 → python3.14 plus /usr/lib/python3.14/json/, so 1bit-npu-idle-evict runs at boot. The release-check row suggestion still stands, as the cheap QEMU-time proof of the boot step.

bong-water-water-bong added a commit that referenced this pull request Nov 24, 2026
…, so a pre-fix image's idle NPU was never checked (engine#3437) (#3467)

engine#3437: on 23 Nov a Qwen3-0.6B-NPU-1bit loaded from the web UI at 21:50Z held the NPU until an unload-all at
23:44Z (~1 h 54 min). Lemonade ships idle eviction OFF: src/cpp/server/eviction_engine.cpp:84-91 skips a model unless
its recipe options carry auto_evict: true (is_boolean at :87, so a string "true" is ignored), and
src/cpp/resources/defaults.json:11 has "auto_evict": false, so evict_idle_timeout (300 s, :93) is never consulted.
#3438 (77ab44b) shipped the image half: /usr/local/bin/1bit-npu-idle-evict writes
{"auto_evict": true, "evict_idle_timeout": 600} under Lemonade's canonical ids for every onebit NPU model, and
10lemonade:164-165 runs it before lemond. Nothing read that file, so the wave could only be caught by a person
noticing the NPU stayed busy.

- npu_idle_evict_verdict (release-check.sh:1244) reads the catalogue (+ user_models.json) and
  /data/lemonade/config/recipe_options.json - or the /var/lib/lemonade fallback - the way lemond does. Its NPU test
  and canonical-id resolution are the boot step's own, kept identical on purpose, and the self-test also drives the
  real 1bit-npu-idle-evict and asserts it leaves exactly what the row passes, so the row and the boot step cannot
  drift into two definitions.
  PASS: every NPU model has auto_evict true, each model's effective timeout printed. FAIL: no entry / false /
  non-boolean / a non-object entry / a missing, unreadable or non-JSON file. SKIP: no catalogue, or a catalogue with
  no onebit NPU model. A timeout that is not a positive integer is not a FAIL - with auto_evict on, Lemonade falls
  back to 300 s and the model is still evicted - but the effective value is printed, so a 24 h one is visible.
- the row (release-check.sh:2305) runs where the boot step exists, /opt/1bit-package (the v3 appliance, board or VM);
  no hardware needed. The os/mini artifact SKIPs with the gap named (it starts lemond from os/mini/init.sh and has no
  such step), so a green os/mini VM does not read as "checked".
- --self-test +19 (15 check arms, 4 named assertions): the 23 Nov box's own shape (the user entry only, no NPU
  entry) FAILs and names both NPU models; the helper's output on the same catalogue PASSes; a person-set 1200 s is
  reported, not failed; auto_evict false, the string "true", a non-object entry, a missing file, non-JSON and an
  array FAIL; an un-migrated bare key and Lemonade's 300 s default PASS; a GPU onebit model and the Windows-only
  ryzenai-llm entry are not demanded; a user model with onebit_backend npu is required and its missing entry FAILs.

Evidence
--------
Control. The box (1bit-os) runs the pre-fix v2026.49-rc1 image: /etc/init.d/10lemonade is the 23 Nov 17:56 cut, 0
references to npu-idle-evict, and /usr/local/bin/1bit-npu-idle-evict is absent. Its catalogue
(/opt/1bit-package/bin/resources/server_models.json, sha256 42d7e805a05a3239fd49daaf6b55d7634860565dc5861e822983960ffae9022b)
is the rc1 cut on disk here, and its live recipe_options.json is the 23 Nov shape:

  $ ssh strixhalo cat /data/lemonade/config/recipe_options.json
  {
    "user.Qwen3.8-27B-ThinkingCoder": {
      "ctx_size": 0,
      "llamacpp_args": "--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.00 ..."
    }
  }                                                 # no entry for either NPU model

  $ . verdict.sh; npu_idle_evict_verdict <catalogue> '' <that file>
  FAIL 2 of 2 NPU model(s) would not be evicted when idle (.../pre-fix/recipe_options.json):
  builtin.Qwen3-0.6B-NPU-1bit (no entry); builtin.Qwen3-4B-NPU-1bit (no entry) - Lemonade's
  eviction_engine.cpp:84-91 skips a model unless a per-model auto_evict is true

The row block itself, verbatim from this tree, run on that box (LEMDIR=/opt/1bit-package, CATALOG = the box's own
catalogue; reads two files, no Lemonade call and no device):

  $ ssh strixhalo 'bash -s' < row-block.sh
  FAIL  npu-idle-evict : 2 of 2 NPU model(s) would not be evicted when idle
  (/data/lemonade/config/recipe_options.json): builtin.Qwen3-0.6B-NPU-1bit (no entry);
  builtin.Qwen3-4B-NPU-1bit (no entry) - Lemonade's eviction_engine.cpp:84-91 skips a model unless a per-model
  auto_evict is true

and with LEMDIR=/opt/lemonade (the os/mini artifact):

  SKIP  npu-idle-evict : not the v3 appliance (no /opt/1bit-package here): os/mini starts lemond from
  os/mini/init.sh, which does not set NPU idle eviction - engine#3437's fix is os/v3/puppy's 10lemonade

After. On a copy of that same config, the shipped boot step (77ab44b's helper, unchanged in this tree):

  $ sh os/v3/puppy/embed/usr/local/bin/1bit-npu-idle-evict <catalogue> <copy>/config
  2 NPU model(s) evict after 600 s idle: set for builtin.Qwen3-0.6B-NPU-1bit, builtin.Qwen3-4B-NPU-1bit
  $ npu_idle_evict_verdict <catalogue> '' <copy>/config/recipe_options.json
  PASS 2 NPU model(s) evict when idle: builtin.Qwen3-0.6B-NPU-1bit (600 s), builtin.Qwen3-4B-NPU-1bit (600 s)
The user entry is unchanged (value-for-value; the helper re-serialises the file) and no entry is removed.

Self-test: 266 ok / 0 FAIL under bash, dash (/bin/sh) and busybox sh; origin/main (1bb4632) 247 ok / 0, so +19.
ctest: release_check_selftest, release_check_row, npu_idle_evict - all Passed (1.57 s, no device, no build).
Gate: scripts/pre-pr-checks.sh --tree-only --base origin/main -> all 16 check(s) green, 2 skipped, 0 could not be
told (the 2 skips are the gpu-kernels rows, no checkout here).

Not verified: a boot of a v2026.49+ image carrying #3438 (the PASS branch above is the helper's output plus the
verdict, and the self-test; no image with the fix has been booted), and no hardware eviction was observed - that is
issue #3437's closure criterion, not this row's.

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant