DSH | dsh-context-budget | Keep a local model's context at a size your GPU handles well #5078
Replies: 2 comments 1 reply
建议把三个预算边界分开显示这个插件的 measured/predicted slowness 对本地模型很有帮助。需要特别避免把几个不同数字混成一个“context size”:provider usage 是一次请求的计量,surface estimate 是模型可见内容的估算,compaction cost 则是额外的 summary/rewrite 请求成本;提前 compact 可能降低后续压力,但不是免费操作,也不会抹掉已经发生的调用成本。 建议在集成和 UI 中固定这些证据: 手册中有一页独立的 token accounting 说明,专门区分 surface、provider usage、compaction 和 retry 计量,并给出长 Session 的核对方法:Interpret token estimates, provider usage, and compaction pressure。它不是官方 DeepSeek 文档,也不代表对该插件的兼容性认证;请在目标 DSH revision、模型和硬件上重新验证。 |
|
Thanks, that's a useful way to think about it, and most of it is already how the plugin works. The three checks are evaluated on their own and the log line names whichever one tripped, one line per step, so none of them hides another. When the plugin does trigger a compaction it logs the result either way, and a failed compaction is never treated as done. A slow reply is only remembered for the context it was measured on; once a compaction rewrites that context it's forgotten, so one compaction can't set off the next, and the summary requests themselves aren't measured. dsh's own engine also refuses to run two compactions at once. State is kept per provider and per session, and the logs only ever contain counts and timings, never prompt text, tool output, or file paths. The part that isn't there yet is per-sample detail. |
Uh oh!
There was an error while loading. Please reload this page.
Project URL:
https://github.com/d3vmeh/dsh-context-budget
npm: https://www.npmjs.com/package/dsh-context-budget
Introduction:
DSH compacts a conversation when it reaches a fixed fraction of the model's declared context window. On local hardware the declared window is not very practical: my Qwen3.8-27B advertises 256K, but on a Strix Halo it reads prompts at ~300 tokens/s when the context is small and ~70 tokens/s past 100K. A turn that started in seconds early in the session starts in half an hour later on, and the GPU hung near 170K before the default 80% threshold was reached.
dsh-context-budget measures how expensive the context has become and warns, or compacts early, before that point. Before every agent step it runs up to three checks per provider route:
Any configured check can trip; unset ones are skipped. Default action is
warn(one line in the DSH terminal);compactasks DSH's own compaction engine to summarize everything except the most recentretainTokens. A/context-budgetcommand shows the live numbers, including an estimate of what compacting now would cost, because on local hardware a compaction is not free (the summary prompt and the rewritten context both prefill cold; on my machine about 25 to 35 minutes each at 120K).How it integrates with DSH:
A small cordis plugin. It measures on the
llm/streamwaterfall (time to first chunk plus the uncached prompt tokens from DSH's usage report, so it works with any provider and never talks to the model server), decides onagent/pre-stepusingctx.tokenMeter, and compacts through the agent's own compaction engine (compactRegion) with the same range selection compaction-basic uses. It ships adsh.bundlepatch, so installation is:then in
~/.dsh/profiles/web/cordis.patch.yml:What it looks like in use:
If you only want the static ceiling, you do not need this plugin: compaction-basic's
modelPolicieswith a per-modelthresholdRatiodoes that today. This plugin adds the measured checks and the cost estimate.Companion: dsh-llm-gate (#4995) keeps the number of requests within your server's slots; this one keeps each request's size within what the GPU handles well.
MIT License. Feedback welcome!
> Unofficial project, independently developed and maintained by community members.
All reactions