Repository navigation
fix: simulator returns zeros on transformers >= 5 and BOS-less tokenizers - #180
Open
flyingdoubleG wants to merge 1 commit into
Open
flyingdoubleG wants to merge 1 commit into
flyingdoubleG wants to merge 1 commit into
Conversation
…zers
The logprob simulator indexed the result of apply_chat_template as a list
of token ids and took encode('\t')[1] as the tab token, assuming a BOS
token. On transformers >= 5, apply_chat_template returns a BatchEncoding
by default, and tokenizers such as Qwen2.5 add no BOS, so both raised
IndexError. simulate() catches the exception and returns all-zero
predictions, so every simulation correlation became NaN without an error.
Request a list with return_dict=False and encode the tab without special
tokens. The offline client also passed apply_chat_template's result to
TokensPrompt as token ids; request a list there too.
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
The logprob simulator (
NeuronSimulator._simulate_with_logprobs, used by thesimulationscorer) returns all-zero predictions in two common setups, without raising an error:apply_chat_templatenow returns aBatchEncodingby default (return_dict=True), sotokenized_prompt[-3]inparse_simulation_responseraisesIndexError.pyproject.tomlleavestransformersunpinned, and current vLLM requirestransformers>=5.16.1,<5.20, so fresh installs hit this.encode("\t")is[197], so[1]raisesIndexErroron any transformers version.simulate()catches the exception and returns zeros ("Simulation failed: list index out of range, returning zeros"). Every per-sequence and per-quantile correlation then becomes NaN.Repro with a fake client that returns P("7") = P("0") = 0.5 after every tab, so each token's expected activation should be 3.5:
Changes
simulator.py: callapply_chat_template(..., return_dict=False), and get the tab token withencode("\t", add_special_tokens=False)[-1].clients/offline.py: theOfflineclient also passesapply_chat_template(..., tokenize=True)toTokensPrompt(prompt_token_ids=...)and takeslen()of it for statistics. On transformers >= 5 that is aBatchEncoding, not a list of ids, soreturn_dict=Falseis added there as well. I could not run vLLM locally (Windows), so this part is covered by the reasoning above rather than a test.return_dictexists in transformers 4.x (defaultFalse), so behaviour there is unchanged apart from the BOS fix.Similar in spirit to #176 / #177 (
batch_decodeon transformers 5).Tests
tests/test_scorers/test_simulator_tokenization.pyrunsNeuronSimulator.simulatewith the fake client for the Llama-3.1 (BOS) and Qwen2.5 (no BOS) tokenizers, and checks that the expected activations are 3.5.ruff check(with the repo's excludes) andblack --checkpass on the changed files. pyright reports only unresolved imports from my local environment, the same as on main.Locally I ran the test against stubbed
vllm/faissmodules and withouttests/conftest.py, since vLLM does not install on Windows. In CI it imports normally.