Pass temperature to draft sampler in dflash_generate#77
Open
shaun0927 wants to merge 1 commit intoz-lab:mainfrom
Open
Pass temperature to draft sampler in dflash_generate#77shaun0927 wants to merge 1 commit intoz-lab:mainfrom
shaun0927 wants to merge 1 commit intoz-lab:mainfrom
Conversation
The draft sampler at dflash/model.py:121 was called without the
user-supplied temperature, so it always used the default
`temperature=0.0` (greedy argmax). The target sampler at line 134
does receive `temperature`. For any `temperature > 0` the two paths
therefore sample from different distributions: the draft is
deterministic while the target is stochastic.
Acceptance is decided by token equality
(block_output_ids[:, 1:] == posterior[:, :-1])
so the mismatch artificially depresses acceptance and the accepted
tokens do not follow the target distribution.
Minimal repro without a model:
torch.manual_seed(0)
logits = torch.tensor([[[2.0, 1.5, 1.0, 0.5]]])
draft = sum(int(sample(logits).item() == 0) for _ in range(4000))
target = sum(int(sample(logits, 1.0).item() == 0) for _ in range(4000))
# draft = 4000/4000 (100%), target ~1900/4000 (~47%)
Pass `temperature` through so both paths use the same scheme.
Refs: z-lab#74
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.
Closes #74.
Problem
In
dflash_generate, the draft sampler is invoked without theuser-supplied
temperature:dflash/model.py:121(draft):dflash/model.py:134(target):For any
temperature > 0the draft is therefore deterministic (greedyargmax) while the target samples stochastically. Acceptance is decided
by a token-equality check
(
block_output_ids[:, 1:] == posterior[:, :-1]), so the mismatchartificially depresses acceptance and the accepted-token distribution
does not match the target distribution.
Reproduction without a model (verbatim copy of
sample()):Fix
Pass
temperaturethrough to the draftsample():This is the minimal change that puts draft and target on the same
sampling scheme. Acceptance is still token-equality (not
Leviathan-style rejection sampling), so
dflash_generatestill does notprovide an exact-distribution guarantee for
temperature > 0; happy tofollow up with a docstring note or a proper rejection-sampling
implementation in a separate PR if useful.
Notes
temperature == 0, the default in the READMEexamples) are unaffected: both branches go through
torch.argmax.sample()— that one would have broken downstream broadcasting; thisPR touches only the call site.
branch so they can be merged independently.