Repository navigation
fix(serve): refuse --lean on --tree flex before default_mode resolves the model - #30
Merged
rkinas merged 3 commits intoOct 21, 2026
Conversation
… the model On a CUDA GPU without FlashAttention 3, main() chose the default mode first, and default_mode() resolves the model to see whether it is Gemma 4; the --lean on / --tree flex refusal came after it, in Server.__init__. So the refusal needed the model metadata (offline: a download error instead) and tests/test_lean.py::test_flex_with_lean_on_refused_before_loading failed on such GPUs (found on an RTX 4060 Ti; it also fails on main there). Both values are explicit, so the check runs before default_mode now (refuse_lean_flex, shared with Server). The test also simulates a GPU without FA3, so it fails without the fix on any machine.
Reviewer's GuideThe PR prevents Sequence diagram for early lean-flex refusalsequenceDiagram
actor User
participant Main as main()
participant Refuse as refuse_lean_flex()
participant Default as default_mode()
participant Server as Server.__init__()
User->>Main: basal-serve --lean on --tree flex
Main->>Refuse: refuse_lean_flex(a.lean, a.tree)
Refuse-->>Main: SystemExit refusal
Note over Main,Default: default_mode() and model resolution are not reached
User->>Server: direct Server construction
Server->>Refuse: refuse_lean_flex(a.lean, a.tree)
Refuse-->>Server: SystemExit refusal
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="basal/server.py" line_range="1432" />
<code_context>
def main():
a = parser().parse_args()
+ refuse_lean_flex(a.lean, a.tree) # before default_mode, which resolves the model on CUDA GPUs without FA3
a.mode = a.mode or default_mode(a.model, a.revision)
validate_quant(a.mode, a.quant)
</code_context>
<issue_to_address>
**Model errors mask refusal**
When basal-calibrate runs in-process on CUDA without FA3, with no explicit mode and `--lean on --tree flex`, and the model is unavailable offline, `default_mode()` attempts model resolution before `Server.__init__` reaches `refuse_lean_flex`, so calibration performs an avoidable lookup and reports a model-resolution failure instead of the lean/tree refusal.
Call `refuse_lean_flex` before `default_mode()` in basal-calibrate’s in-process path.
</issue_to_address>
### Comment 2
<location path="basal/server.py" line_range="638" />
<code_context>
- if a.lean == "on" and a.tree == "flex":
- raise SystemExit("--tree flex runs with --lean pass2; with --lean on its FlexAttention falls back to an "
- "uncompiled kernel during CUDA graph capture and the engine fails to start")
+ refuse_lean_flex(a.lean, a.tree)
if getattr(a, "batches", "default") not in ("default", "auto") and kind not in ("graph", "exit"):
raise SystemExit("--batches needs the CUDA graph engine (fast, fast-nocompile, fast-exit, fp8, nvfp4)")
</code_context>
<issue_to_address>
**Direct think startup resolves first**
When a caller directly constructs `ThinkServer` with `--lean on --tree flex` and model resolution fails, `ThinkServer.__init__` resolves the model before calling `Server.__init__`, so a direct construction with `--lean on --tree flex` can fail during resolution before this guard rejects the options; the caller sees a resolution error instead of the refusal.
Call `refuse_lean_flex` at the start of `ThinkServer.__init__`, before resolving the model or starting the sidecar.
</issue_to_address>… and ThinkServer too basal-calibrate (engine in process) chose the default mode before building the Server, and a ThinkServer resolves the model and starts its sidecar before Server.__init__: both reached the refusal only after the model lookup. Both call refuse_lean_flex first now. The test runs the three entry points (basal-serve, basal-calibrate, ThinkServer) on a simulated CUDA GPU without FA3; without this change the calibrate and think cases fail.
rkinas
added a commit
that referenced
this pull request
Oct 21, 2026
…ast_kernels, as 2.3.1's default_mode asks (#30) In 2.3.1 default_mode() resolves the model when gemma_fast_kernels() is None (no FA3 and not sm_120), not through attention_available directly; the test now patches that, and still fails without the fix (serve case checked).
rkinas
added a commit
that referenced
this pull request
Oct 21, 2026
Owner
|
Merged and released in basal 2.3.1 (https://github.com/rkinas/basal/releases/tag/v2.3.1). One follow-up commit: 2.3.1 picks the default mode through |
rkinas
added a commit
that referenced
this pull request
Oct 22, 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.
Problem
tests/test_lean.py::test_flex_with_lean_on_refused_before_loadingfails on any CUDA GPU without FlashAttention 3,also on
main(found on an RTX 4060 Ti, see #29):main()chooses the default mode before anything else, and on CUDA without FA3default_mode()resolves the model(to see whether it is Gemma 4). The
--lean on/--tree flexrefusal comes later, inServer.__init__. So therefusal needs the model's metadata first: offline,
basal-serve --lean on --tree flexends in a download errorinstead of the refusal. On Hopper with FA3 (and on CPU)
default_mode()does not resolve, which is why it passesthere.
Change
refuse_lean_flex(lean, tree): the existing check and message, shared bymain()(now beforedefault_mode()),basal-calibratewith the engine in process (before itsdefault_mode()),ThinkServer.__init__(before itresolves the model and starts its sidecar) and
Server.__init__(unchanged position, for callers that build aServerdirectly). Both values are explicit (lean_treenever resolvesautotoon), so checking the rawarguments refuses exactly the same cases.
ThinkServerbuilt directly) with a CUDA GPUwithout FA3 simulated (
torch.cuda.is_availableandattention_availablepatched) andresolvefailing, so itfails without the fix on any machine, CPU included.
Checks
part fixed the calibrate and think cases still fail; with the whole fix all three pass.
basal-serve --model Remek/never-downloaded-repo --lean on --tree flex: exits with the refusal (no resolve).tests/(withouttest_gguf.py): 617 passed, 73 skipped (CPU).Summary by Sourcery
Reject incompatible lean and flex tree settings before selecting a mode or resolving the model.
Bug Fixes:
--lean on --tree flexbefore model resolution across serve, calibrate, and think entry points, avoiding unintended downloads or model-loading failures.Enhancements:
Documentation:
--lean on --tree flexis refused before resolving the model, including on CUDA systems without FlashAttention 3.Tests: