fix(#1789): make AprServeDriver max_tokens cap env-configurable#1814
Merged
Conversation
PMAT-170's hardcoded 1024-token cap is reasonable for small/fast models but excessive for large MoE models without KV cache. At empirically observed ~0.5 tok/s on Qwen3-Coder-30B-A3B-Instruct-Q4_K_M (no KV cache, full-prefill-per-token), a 1024-token cap produces ~34 min wall per turn — exceeding the bench harness's per-turn budgets. Same env-var pattern as APR_AGENT_HTTP_TIMEOUT_S (aprender#1812): allow the operator (or bench harness) to dial the cap down for slow models. Default unchanged at 1024 — covers all existing dense + small-MoE use cases. Override via APR_AGENT_MAX_TOKENS_CAP. Phase 6 30B-MoE bench uses APR_AGENT_MAX_TOKENS_CAP=128 to fit per-turn budget. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
6f89331 to
1b7f1e7
Compare
This was referenced May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third in the aprender#1789 follow-up series. PMAT-170's hardcoded 1024-token cap in
AprServeDriver::build_openai_bodyis reasonable for small/fast models but excessive for large MoE models without KV cache.Empirical context
Phase 6 bench against Qwen3-Coder-30B-A3B-Instruct-Q4_K_M (post-#1812):
The HTTP timeout knob from #1812 isn't enough — the bottleneck is generation length, not HTTP wait.
Fix
Same env-var pattern as
APR_AGENT_HTTP_TIMEOUT_S(#1812). NewAPR_AGENT_MAX_TOKENS_CAPenv var; default unchanged at 1024 (no regression for existing flows). Phase 6 bench usesAPR_AGENT_MAX_TOKENS_CAP=128to fit per-turn budget.Test plan
cargo check -p aprender-orchestrate— clean🤖 Generated with Claude Code