[PR #562] [CLOSED] serve: /slots reports n_prompt_tokens, so a llama.cpp-style context m… #2692

Closed
opened 2026-11-04 02:02:25 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/562
Author: @Zerschranzer
Created: 10/2/2026
Status: ❌ Closed

Base: main ← Head: slots-n-prompt-tokens


📝 Commits (10+)

  • 872af82 Low-RAM mode, resident variant: the experts the GPU does not hold stay in RAM (--resident-experts), chosen by setup
  • 483953f Merge f-84 into rel-0.1.30
  • 7e4ee54 setup: the resident low-RAM variant keeps its RAM copy pageable on ROCm (STRATA_RESIDENT_PIN=0 in the config's env)
  • 1afdd47 Merge f-coupled into rel-0.1.30
  • 0704e7d HIP: enable RDNA4 gfx1201 (RX 9070 / AI PRO R9700)
  • 8616c60 generate: the option parser's else-if chain in two statements (MSVC C1061: more than 128 nested blocks after the new options); the same order and effects
  • 538a0df Merge f-resram into rel-0.1.30
  • 703ef30 Merge f-189 (PR #189, the conversation snapshot core and RAM cache) into rel-0.1.30
  • e46ccca Conversation snapshots and checkpoints follow the session carve (#216): a session saves and restores only the layers it owns
  • 9907379 HIP: RDNA4 gfx1201 beside gfx1100; the startup check compares the card with the compiled archs; setup picks ROCm and the hipBLASLt table per arch

📊 Changes

3 files changed (+24 additions, -4 deletions)

View changed files

📝 docs/DETAILS.md (+2 -2)
📝 serve/server.py (+7 -1)
📝 serve/test_server.py (+15 -1)

📄 Description

Why

Clients written against llama.cpp's endpoints read a context meter from /slots: they divide n_prompt_tokens by
n_ctx. Strata's slot carried only id, n_ctx and is_processing, so such a meter sits at 0 % against
Strata however full the context is - and the reaction a user reaches for ("raise the context") changes nothing.

The number is already there, only not under that name. Same second, IQ3_S, 2x RX 9060 XT (gfx1200, HIP), engine
0.1.37:

GET /slots   -> [{"id": 0, "n_ctx": 262144, "is_processing": false}]
GET /status  -> {"busy": false, ..., "prompt_tokens": 120711, "generated": 331}

I hit it with a chat front-end of my own that draws a context ring: it stayed at 0 % through a 120K-token
conversation, while /status and /metrics had the right number the whole time.

What it changes

  • GET /slots also returns n_prompt_tokens: the running request's prompt size, kept after it ends (the
    conversation cache carries it on). Read under status_lock, so it is the same snapshot /status serves.
    Nothing else in the response changes, and the Monitor's own /metrics is untouched.
  • serve/test_server.py: test_slot_reports_the_context_in_use - a set prompt_tokens shows up in the slot, and
    after clearing it the slot reports 0. The existing exact-slot assertion in
    test_build_model_path_and_slot_status carries the new key.
  • docs/DETAILS.md: the endpoint table and the paragraph say what /slots reports.

Semantics, on purpose

  • Generated tokens are not counted, exactly as llama.cpp's n_prompt_tokens does not count them; the next
    request's prompt carries them through the conversation cache, so a meter catches up on the next round.
  • The value is set when the request starts, so it jumps to the full prompt size at prefill instead of growing
    token by token.
  • A dead engine still answers [], so a client hides the meter rather than showing 0 %.
  • n_prompt_tokens_processed and n_prompt_tokens_cache (also llama.cpp names) are deliberately left out until
    someone needs them; the engine's reused would map onto the latter.

Tests

python -m unittest serve.test_server serve.test_monitor
Ran 122 tests in 53.453s - OK

against the mock engine, no GPU and no pack. Live on the same build:

GET /slots -> [{"id": 0, "n_ctx": 262144, "is_processing": false, "n_prompt_tokens": 120711}]

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/562 **Author:** [@Zerschranzer](https://github.com/Zerschranzer) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `slots-n-prompt-tokens` --- ### 📝 Commits (10+) - [`872af82`](https://github.com/Niko1221/Strata/commit/872af82983d53de7c754ead79f4599606d3a40e8) Low-RAM mode, resident variant: the experts the GPU does not hold stay in RAM (--resident-experts), chosen by setup - [`483953f`](https://github.com/Niko1221/Strata/commit/483953fdc15ed86808d714573b87634f43c3f1ea) Merge f-84 into rel-0.1.30 - [`7e4ee54`](https://github.com/Niko1221/Strata/commit/7e4ee54288051d3a71e403df4e8db455f64d38dc) setup: the resident low-RAM variant keeps its RAM copy pageable on ROCm (STRATA_RESIDENT_PIN=0 in the config's env) - [`1afdd47`](https://github.com/Niko1221/Strata/commit/1afdd47161726eb013c4533fc0a83c1cd9e58297) Merge f-coupled into rel-0.1.30 - [`0704e7d`](https://github.com/Niko1221/Strata/commit/0704e7dc85084761c5ca20008d226a99279a9805) HIP: enable RDNA4 gfx1201 (RX 9070 / AI PRO R9700) - [`8616c60`](https://github.com/Niko1221/Strata/commit/8616c60974d6cae71c8af582255cde15506ed19c) generate: the option parser's else-if chain in two statements (MSVC C1061: more than 128 nested blocks after the new options); the same order and effects - [`538a0df`](https://github.com/Niko1221/Strata/commit/538a0dfa4bd974e9687df6a5514250675369942c) Merge f-resram into rel-0.1.30 - [`703ef30`](https://github.com/Niko1221/Strata/commit/703ef3044e67a0adbd26f3a264f90ae83c801524) Merge f-189 (PR #189, the conversation snapshot core and RAM cache) into rel-0.1.30 - [`e46ccca`](https://github.com/Niko1221/Strata/commit/e46ccca49c89fb725f521ff6671a6b12e8d7d7b9) Conversation snapshots and checkpoints follow the session carve (#216): a session saves and restores only the layers it owns - [`9907379`](https://github.com/Niko1221/Strata/commit/99073795e377c6eb52ad5cce8fd6d70d7937f52d) HIP: RDNA4 gfx1201 beside gfx1100; the startup check compares the card with the compiled archs; setup picks ROCm and the hipBLASLt table per arch ### 📊 Changes **3 files changed** (+24 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+2 -2) 📝 `serve/server.py` (+7 -1) 📝 `serve/test_server.py` (+15 -1) </details> ### 📄 Description ## Why Clients written against llama.cpp's endpoints read a context meter from `/slots`: they divide `n_prompt_tokens` by `n_ctx`. Strata's slot carried only `id`, `n_ctx` and `is_processing`, so such a meter sits at **0 %** against Strata however full the context is - and the reaction a user reaches for ("raise the context") changes nothing. The number is already there, only not under that name. Same second, IQ3_S, 2x RX 9060 XT (gfx1200, HIP), engine 0.1.37: GET /slots -> [{"id": 0, "n_ctx": 262144, "is_processing": false}] GET /status -> {"busy": false, ..., "prompt_tokens": 120711, "generated": 331} I hit it with a chat front-end of my own that draws a context ring: it stayed at 0 % through a 120K-token conversation, while `/status` and `/metrics` had the right number the whole time. ## What it changes - `GET /slots` also returns `n_prompt_tokens`: the running request's prompt size, kept after it ends (the conversation cache carries it on). Read under `status_lock`, so it is the same snapshot `/status` serves. Nothing else in the response changes, and the Monitor's own `/metrics` is untouched. - `serve/test_server.py`: `test_slot_reports_the_context_in_use` - a set `prompt_tokens` shows up in the slot, and after clearing it the slot reports 0. The existing exact-slot assertion in `test_build_model_path_and_slot_status` carries the new key. - `docs/DETAILS.md`: the endpoint table and the paragraph say what `/slots` reports. ## Semantics, on purpose - Generated tokens are not counted, exactly as llama.cpp's `n_prompt_tokens` does not count them; the next request's prompt carries them through the conversation cache, so a meter catches up on the next round. - The value is set when the request starts, so it jumps to the full prompt size at prefill instead of growing token by token. - A dead engine still answers `[]`, so a client hides the meter rather than showing 0 %. - `n_prompt_tokens_processed` and `n_prompt_tokens_cache` (also llama.cpp names) are deliberately left out until someone needs them; the engine's `reused` would map onto the latter. ## Tests python -m unittest serve.test_server serve.test_monitor Ran 122 tests in 53.453s - OK against the mock engine, no GPU and no pack. Live on the same build: GET /slots -> [{"id": 0, "n_ctx": 262144, "is_processing": false, "n_prompt_tokens": 120711}] --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:25 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2692
No description provided.