optimum icon indicating copy to clipboard operation
optimum copied to clipboard

Single-token dummy attention mask generation raises ValueError

Open WitBlue6 opened this issue 1 month ago • 1 comments

System Info

Optimum main (2.4.0.dev0), Python 3.10.17, macOS arm64, PyTorch and NumPy.

Information

Direct use of the public dummy input generators, also used for model export inputs. No model download is required.

Reproduction

from transformers import DistilBertConfig
from optimum.utils import DummyTextInputGenerator, NormalizedConfigManager
config = NormalizedConfigManager.get_normalized_config_class("distilbert")(DistilBertConfig())
generator = DummyTextInputGenerator("text-classification", config, batch_size=2, sequence_length=1)
generator.generate("attention_mask", framework="np")

This raises ValueError: empty range for randrange() (1, 1, 0) because random_mask_tensor chooses a padding length with random.randint(1, 0). PyTorch and encoder_attention_mask have the same issue; multiple-choice inputs are also affected.

Expected behavior

A single-token input has an all-one mask of the requested shape and integer dtype. It cannot have a positive padding length while retaining an unmasked token.

AI disclosure: found and reproduced by OpenAI Codex; no production incident is claimed. A fix and regression tests are prepared.

WitBlue6 avatar Oct 11 '26 05:10 WitBlue6

This issue has been marked as stale because it has been open for 30 days with no activity. This thread will be automatically closed in 5 days if no further activity occurs.

github-actions[bot] avatar Nov 11 '26 01:11 github-actions[bot]