You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reducing GPU utilization while working with CLAREAugmenter #812
I found that what causes this is the fact that recipes like CLARE that use TensorFlow end up allocating the entire memory when not using parallelization, as memory growth is only set then.
Simply applying this before loading the augmentation should fix it:
@tsalmonking thanks for looking into this, but I don't think the TensorFlow memory-growth theory holds up for the repro you posted: CLAREAugmenter only loads a PyTorch/HF distilroberta-base model (WordSwapMaskedLM / WordInsertionMaskedLM / WordMergeMaskedLM via transformers.AutoModelForCausalLM) — it never touches TensorFlow. The set_memory_growth call in attacker.py only matters for constraints like UniversalSentenceEncoder that load TF, and only in the --parallel multiprocessing path, neither of which is in play in your snippet. Applying that fix wouldn't change anything for this repro.
More likely culprits for the ~40GB: CLAREAugmenter builds two full copies of the masked-LM (shared_masked_lm is loaded once but referenced across a CompositeTransformation of three sub-transformations, each generating candidate sets), and with ~800-token inputs the candidate-generation matrices scale with sequence length. If you can share GPU memory usage broken down by call (or run with pct_words_to_swap lower / on a truncated input) that would help narrow it down further. Leaving this open — this needs actual profiling, not a one-line fix.
Activity
tsalmonking commentedon Dec 11, 2025
I found that what causes this is the fact that recipes like CLARE that use TensorFlow end up allocating the entire memory when not using parallelization, as memory growth is only set then.
Simply applying this before loading the augmentation should fix it:
TextAttack/textattack/attacker.py
Line 551 in 0d0929c
qiyanjun commentedon Aug 13, 2026
@tsalmonking thanks for looking into this, but I don't think the TensorFlow memory-growth theory holds up for the repro you posted:
CLAREAugmenteronly loads a PyTorch/HFdistilroberta-basemodel (WordSwapMaskedLM/WordInsertionMaskedLM/WordMergeMaskedLMviatransformers.AutoModelForCausalLM) — it never touches TensorFlow. Theset_memory_growthcall inattacker.pyonly matters for constraints likeUniversalSentenceEncoderthat load TF, and only in the--parallelmultiprocessing path, neither of which is in play in your snippet. Applying that fix wouldn't change anything for this repro.More likely culprits for the ~40GB:
CLAREAugmenterbuilds two full copies of the masked-LM (shared_masked_lmis loaded once but referenced across aCompositeTransformationof three sub-transformations, each generating candidate sets), and with ~800-token inputs the candidate-generation matrices scale with sequence length. If you can share GPU memory usage broken down by call (or run withpct_words_to_swaplower / on a truncated input) that would help narrow it down further. Leaving this open — this needs actual profiling, not a one-line fix.