Repository navigation
Conversation
This branch has not been deployed
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
Fixes #920.
SpeculativeInferencer.autoregressive_samplingpreviously calledself.predict_next_token, which invokedmodel.inference(..., output_scores=True, do_sample=True)(HuggingFacegenerate()). Intransformers,generate()'sscoresare already warped by the model'sgeneration_config(such as defaulttemperature,top_p,top_k), andautoregressive_samplingthen passed those processed scores intoscore_to_proba second time, distorting the draft probability distribution relative to the target model's raw logits.Changes
SpeculativeInferencer.autoregressive_sampling(src/lmflow/pipeline/inferencer.py): Compute next-token raw logits directly frommodel.get_backend_model()(input_ids=sequence, return_dict=True).logits[:, -1, :]undertorch.no_grad(), matching STEP 2's target-model forward pass and avoiding HFgenerate()logits warping.SpeculativeInferencer.score_to_prob: Use out-of-placescores = scores / temperatureinstead of in-placescores /= temperature, preventing double temperature scaling whenscore_to_probis called twice on the sameoutput.logitsslice during rejection/adjustment.SpeculativeInferencer.inference: Forwardtemperature=temperaturetoautoregressive_samplingand wrap STEP 2's forward pass intorch.no_grad().tests/pipeline/test_speculative_inferencer.py.Verification
model.inference()returned generation-config-modified scores before the fix.PYTHONPATH=src pytest -v --strict-markers tests/pipeline/test_speculative_inferencer.py-> 3 passed.ruff check src/lmflow/pipeline/inferencer.py tests/pipeline/test_speculative_inferencer.py --select E4,E7,E9,F --ignore E731-> All checks passed.