feat: integrate Bet-Optimal Drafting (BOD) for dynamic block-size optimization#27
Open
0xClandestine wants to merge 1 commit into
Open
feat: integrate Bet-Optimal Drafting (BOD) for dynamic block-size optimization#270xClandestine wants to merge 1 commit into
0xClandestine wants to merge 1 commit into
Conversation
Add BOD as an opt-in dynamic block-size optimizer for speculative decoding. The draft model is the gambler; the target model is the house. BOD finds the optimal bet size (γ for chain / B for tree) to maximize throughput using a unified mathematical framework. Integration points: - EffectiveRuntimeConfig / RuntimeProfile: 6 new bod_* fields (disabled by default, zero behavioral change). - CLI (serve + generate): --bod-enabled, --bod-mode, --bod-min-bet, --bod-max-bet, --bod-default-scale-cost, --bod-default-fixed-cost. - spec_epoch.py: accepts optional bod_controller; queries it per-cycle for dynamic block sizing and records observations (bet, accepted, cycle_time, draft_time, verify_time). - runtime.py: auto-creates BODController when bod_enabled=True. - __init__.py: exports BODConfig, BODController, BODObservation. - doctor.py: registers BOD fields in config/CLI registries. 343 tests pass, 3 skipped (pre-existing).
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
Integrates Bet-Optimal Drafting (BOD) — a unified bet-size optimizer for chain (vanilla DFlash) and tree (DDTree) speculative decoding — throughout the codebase. The draft model is the gambler; the target model is the house. BOD finds the optimal bet size (γ for chain / B for tree) to maximize throughput using a unified mathematical framework.
Core Algorithm
Both modes reduce to the same optimization problem:
Where
xis the bet size,E[tokens]is a concave increasing function, and the denominator is linear. The optimalxmaximizes this ratio.Chain mode (γ optimization) has three tiers:
Tree mode (B optimization) has three tiers:
Integration Points
dflash_mlx/bet_optimal_drafting.pyBODConfig,BODController,BODObservation,bod_optimal_bet()convenience API, Metal kernels, analytical solversruntime_profiles.pybod_*fields onRuntimeProfile/EffectiveRuntimeConfigruntime_context.pyruntime_config_from_profile()andbuild_offline_runtime_context()thread BOD paramsruntime.pystream_dflash_generate()auto-createsBODControllerwhen enabledengine/spec_epoch.pybod_controller; queries per-cycle for block size; records observations after each cycleserver/config.py--bod-enabled,--bod-mode,--bod-min-bet,--bod-max-bet,--bod-default-scale-cost,--bod-default-fixed-costgenerate.pyrun_generate()__init__.pyBODConfig,BODController,BODObservationdoctor.pyUsage
Testing
test_generate_cli.pyexpected dict