Repository navigation
feat(engine): bandit selector optional - #56
Merged
Merged
Conversation
SpeculativeEngine(config, drafters, target, bandit=None, arms=None): when the selector is omitted and the resolved strategy has one arm, the engine uses a one-arm UCB1Selector; with several arms it raises a ValueError naming UCB1Selector/ThompsonSelector and n_arms. Existing calls are unchanged. The README quickstart and one-arm recipes, the examples page and llms.txt drop the selector; the API table is regenerated; CHANGELOG [Unreleased] updated.
6 tasks done
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.
feat(engine): bandit selector optional
Stacked on #55 (base
docs/simpler-quickstart): this PR shortens the quickstart #55 rewrote, so it builds on it to avoid aconflict in the same README lines. After #55 merges, retarget this PR to
main. Do not merge until reviewed.Change
SpeculativeEngine(config, drafters, target, bandit=None, arms=None).banditkeeps its position and gets the defaultNone.UCB1Selector(
window_size=config.bandit.window_size), which always selects arm 0. The engine already ran with a one-arm selectorin every existing one-drafter call, so this changes nothing at run time. Cases:
drafter_strategy="auto"with one model drafter (composite-g6-f2), including its per-call fallback atbatch > 1;
"bandit"strategy with one drafter;ValueError, for example: "2 arms need a bandit selector to choose between them (drafterstrategy 'bandit'). Pass one, for example flashspec.bandit.UCB1Selector(n_arms=2) or
flashspec.bandit.ThompsonSelector(n_arms=2). It is optional only when there is one arm."
bandit=, with or withoutarms=) is unchanged, and no existing test wasedited;
Tests (
tests/unit/test_optional_selector.py)UCB1Selector(n_arms=1)and HFgenerate(do_sample=False), on 3prompts;
"bandit"with one drafter: equals HF greedy;ValueErrornamingUCB1Selector(n_arms=2)andThompsonSelector(n_arms=2); three explicit arms →ValueError.bandit=;arms=still by keyword after a positionalselector.
Docs
from flashspec.bandit import UCB1Selectorand the argument:SpeculativeEngine(config, [drafter], target).It is now 19 lines;
bandit: DraftSelector | None = None).docs/examples.md:SpeculativeEngine(config, drafters, target).llms.txtsays when the selector is optional.[Unreleased]: Added (optional selector) and Changed (simpler quickstart). The 0.3.1 section is written in theversion-bump PR, stacked on this one.
flashspec.banditimport in the quickstart.Gate
Local, on this branch:
make lint(ruff, format, import-linter: engine → bandit is an allowed layer import),mypy --strict flashspec: cleanpytest tests/unit tests/integration -m "not gpu": 568 passed, 5 skipped;pytest tests/chaos: 5 passedpython scripts/readme_api.py --check: current