Fix EtaLogitsWarper on fully masked logits#45413
Conversation
|
cc @Cyrilvallez for generation! |
Signed-off-by: HarshRathva <[email protected]>
0d1e9bc to
d8932ab
Compare
|
Could you please provide a reproducer? I don't see how all logits could end up at -inf... |
|
A full import torch
from transformers.generation.logits_process import SuppressTokensLogitsProcessor, EtaLogitsWarper
input_ids = torch.tensor([[0]])
scores = torch.tensor([[5.0, 1.0, -1.0, 0.2]])
# Previous processor masks all vocab entries
masked = SuppressTokensLogitsProcessor([0, 1, 2, 3])(input_ids, scores)
print(masked)
# tensor([[-inf, -inf, -inf, -inf]])
# This PR keeps eta stable on this input
out = EtaLogitsWarper(epsilon=1e-3, device="cpu")(input_ids, masked)
print(out, torch.isnan(out).any())
# tensor([[-inf, -inf, -inf, -inf]]) tensor(False)Before this PR, the entropy path used in So this patch is mainly a robustness guard: preserve the fully masked state and avoid NaNs/crash in eta when upstream processors produce that edge case. |
|
Humm, I think it actually makes more sense to keep the error and crash on such cases, rather than silently fail when something is wrong. A full row should never be all |
|
yup, thanks for the feedback. |
|
Small follow-up pushed on top: moved the fully-masked-row guard in |
|
Hi @Cyrilvallez , just a quick follow-up on this PR. Is there anything still blocking it, or is it simply waiting for review? Happy to make any additional changes if needed. |
|
My main issue with the PR is that we perform runtime value checks that should not be necessary. I.e. we never do it in any other Processor, because there is no reason in general to end up with fully masked rows... |
That makes sense , I’ll close this PR. Thanks for the review and clarification. |
I ran into an edge case in eta sampling where
EtaLogitsWarpercrashes if a row is fully masked (scores == -inffor all tokens).The previous entropy computation used
Categorical(logits=scores).entropy(), which fails on that input. This change computes entropy from NaN-safe probabilities instead, so fully masked rows stay fully masked without raising.I also added a regression assertion to the existing eta warper test for the all-
-infcase.Local test run:
python -m pytest tests/generation/test_logits_process.py -x -q(45 passed).AI-assisted: I used AI help for drafting, but I personally reproduced the bug, reviewed the diff, and ran local tests.