Fix test suite: resolve 7 failures from dependency updates#821
Open
yanjunqiAz wants to merge 3 commits intoQData:masterfrom
Open
Fix test suite: resolve 7 failures from dependency updates#821yanjunqiAz wants to merge 3 commits intoQData:masterfrom
yanjunqiAz wants to merge 3 commits intoQData:masterfrom
Conversation
Code fixes: - Replace removed transformers.optimization.AdamW with torch.optim.AdamW in trainer.py (removed in transformers>=4.x) - Use AutoTokenizer/AutoModelForMaskedLM instead of BertTokenizer/BertForMaskedLM in ChineseWordSwapMaskedLM, since xlm-roberta-base requires its own tokenizer - Fix hardcoded CUDA device in ChineseWordSwapMaskedLM to auto-detect device Test fixes: - Update stale expected output for list_augmentation_recipes to include BackTranscriptionAugmenter - Add pytest.skip for tests requiring tensorflow_hub when not installed (interactive_mode, adv_metrics attack tests, train test) - Add pytest.skipif for test_embedding_gensim when gensim not installed - Replace deprecated gensim Word2VecKeyedVectors API with KeyedVectors
The [dev] extras include visdom (via [optional]), which fails to build in pip's isolated build environments because visdom's setup.py imports pkg_resources from setuptools, which is not available in isolated builds with newer pip versions. The formatting workflow only needs linting tools and the pytest workflow only needs test tools, so [test] extras are sufficient for both.
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
transformersandgensimChineseWordSwapMaskedLMusing wrong tokenizer class and hardcoded CUDAvisdombuild errorDetails
Code fixes
textattack/trainer.py—transformers.optimization.AdamWwas removed intransformers>=4.x. Replaced withtorch.optim.AdamW, which is the recommended substitute.textattack/transformations/word_swaps/chn_transformations/chinese_word_swap_masked.py:BertTokenizer/BertForMaskedLMcannot loadxlm-roberta-base(wrong tokenizer architecture). Switched toAutoTokenizer/AutoModelForMaskedLMwhich correctly auto-detect the model type."cuda"device with auto-detection (torch.cuda.is_available()), so the transformation works on CPU-only machines.Test fixes
tests/sample_outputs/list_augmentation_recipes.txt— Added missingBackTranscriptionAugmenterentry that was added to the codebase but not reflected in expected test output.tests/test_word_embedding.py— Replaced deprecatedgensim.models.keyedvectors.Word2VecKeyedVectors(removed in gensim 4.x) withgensim.models.KeyedVectors. Addedskipiffor whengensimis not installed.tests/test_command_line/test_attack.py,tests/test_command_line/test_train.py— Added skip markers for tests that requiretensorflow_hub(an optional dependency):interactive_mode,attack_from_transformers_adv_metrics,run_attack_hotflip_lstm_mr_4_adv_metrics, andtest_train_tiny.CI fix
.github/workflows/check-formatting.yml,.github/workflows/run-pytest.yml— Changedpip install -e .[dev]topip install -e .[test]. The[dev]extras includevisdom(via[optional]), which fails to build in pip's isolated build environments because itssetup.pyimportspkg_resourcesfromsetuptools. The formatting and test workflows only need[test]extras.Test plan
gensim.models.KeyedVectors.load_word2vec_formatworks with gensim 4.x