{{ message }}
Repository navigation
Commit 532a001
Fix remaining two review findings from PR #831
- GreedyWordSwapWIR: for wir_method="gradient", truncate_words_to
only bounded the cheap post-hoc index-scoring loop; the expensive
step (get_grad's tokenize+forward+backward pass) still ran over the
full untruncated text. Feed get_grad a text window matching the
same word span already selected, for single-sequence inputs (paired
inputs, e.g. premise/hypothesis, keep relying on the tokenizer's own
model_max_length truncation, since truncating a tuple input here
would need to preserve pair structure - out of scope). Build a
fresh AttackedText for the truncated span and reuse it for
align_with_model_tokens too, so the gradient array and
word2token_mapping's token indices stay consistent.
- Attack.cuda_/to_cuda: scope the hf_device_map skip to
transformers.PreTrainedModel specifically instead of any
torch.nn.Module, since this visitor also traverses non-HuggingFace
models (TensorFlow, sklearn, custom PyTorch modules) reachable from
a Constraint/GoalFunction/Transformation, and only transformers-
loaded models actually get this attribute set by
from_pretrained(device_map=...).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 52cbd8e commit 532a001
2 files changed
Lines changed: 44 additions & 3 deletions

0 commit comments