mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-04 13:20:12 +06:00

remove blank line (+1 squashed commit) Squashed commits: [24ccd2061] [run-slow]vit_msn,vision_encoder_decoder (+24 squashed commits) Squashed commits: [08bd27e7a] [run-slow]vit_msn,vision_encoder_decoder [ec96a8db3] [run-slow]vit_msn [ead817eca] fix vit msn multi gpu [d12cdc8fd] [run-slow]audio_spectrogram_transformer,deit,vision_encoder_decoder,vision_text_dual_encoder,vit,vit_hybrid,vit_mae,vit_msn,videomae,yolos [3fdbfa88f] doc [a3ff33e4a] finish implementation [e20b7b7fb] Update test_modeling_common.py [e290c5810] Update test_modeling_flax_common.py [d3af86f46] comment [ff7dd32d8] more comments [59b137889] suggestion [7e2ba6d67] attn_implementation as attribute of the class [fe66ab71f] minor [38642b568] Apply suggestions from code review Accept comments Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> [22cde7d52] Update tests/test_modeling_common.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> [48e137cc6] Update tests/test_modeling_common.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> [99f4c679f] Update tests/test_modeling_common.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> [96cf20a6d] Update src/transformers/models/vit_msn/modeling_vit_msn.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> [c59377d23] Update src/transformers/models/vit_mae/modeling_vit_mae.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> [b70a47259] Update tests/models/vision_text_dual_encoder/test_modeling_vision_text_dual_encoder.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> [00c84d216] [run-slow]audio_spectrogram_transformer,deit,vision_encoder_decoder,vision_text_dual_encoder,vit,vit_hybrid,vit_mae,vit_msn,videomae,yolos [61f00ebb0] all tests are passing locally [e9e0b82b7] vision encoder/decoder [4d5076b56] test-vision (+20 squashed commits) Squashed commits: [d1add8db9] yolo [9fde65716] fix flax [986566c28] minor [ca2f21d1f] vit [3333efd7a] easy models change [ebfc21402] [run-slow]audio_spectrogram_transformer,deit,vision_encoder_decoder,vision_text_dual_encoder,vit,vit_hybrid,vit_mae,vit_msn,videomae,yolos [b8b8603ed] [run-slow]vision_encoder_decoder,vision_text_dual_encoder,yolos [48ecc7e26] all tests are passing locally [bff7fc366] minor [62f88306f] fix yolo and text_encoder tests [121507555] [run-slow]audio_spectrogram_transformer,deit,vit,vit_hybrid,vit_mae,vit_msn,videomae [1064cae0a] [run-slow]vision_encoder_decoder,vision_text_dual_encoder,yolos [b7f52ff3a] [run-slow]audio_spectrogram_transformer,deit,vit,vit_hybrid,vit_mae,vit_msn,videomae [cffaa10dd] fix-copies [ef6c511c4] test vit hybrid [7d4ba8644] vit hybrid [66f919033] [run-slow]audio_spectrogram_transformer,deit,vit,vit_hybrid,vit_mae,vit_msn,videomae [1fcc0a031] fixes [cfde6eb21] fixup [e77df1ed3] all except yolo end encoder decoder (+17 squashed commits) Squashed commits: [602913e22] vit + vit_mae are working [547f6c4cc] RUN_SLOW=1 pytest tests/models/audio_spectrogram_transformer/ tests/models/deit/ tests/models/videomae/ passes [61a97dfa9] it s the complete opposite... [aefab37d4] fix more tests [71802a1b9] fix all torch tests [40b12eb58] encoder - decoder tests [941552b69] slow decorator where appropriate [14d055d80] has_attentions to yolo and msn [3381fa19f] add correct name [e261316a7] repo consistency [31c6d0c08] fixup [9d214276c] minor fix [11ed2e1b7] chore [eca6644c4] add sdpa to vit-based models [cffbf390b] make fix-copies result [6468319b0] fix style [d324cd02a] add sdpa for vit Co-authored-by: Liubov Yaronskaya <luba.yaronskaya@gmail.com>
96 lines
3.8 KiB
Python
96 lines
3.8 KiB
Python
# coding=utf-8
|
|
# Copyright 2023 The HuggingFace Inc. team.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""
|
|
Utility that checks the supports of 3rd party libraries are listed in the documentation file. Currently, this includes:
|
|
- flash attention support
|
|
- SDPA support
|
|
|
|
Use from the root of the repo with (as used in `make repo-consistency`):
|
|
|
|
```bash
|
|
python utils/check_support_list.py
|
|
```
|
|
|
|
It has no auto-fix mode.
|
|
"""
|
|
import os
|
|
from glob import glob
|
|
|
|
|
|
# All paths are set with the intent you should run this script from the root of the repo with the command
|
|
# python utils/check_doctest_list.py
|
|
REPO_PATH = "."
|
|
|
|
|
|
def check_flash_support_list():
|
|
with open(os.path.join(REPO_PATH, "docs/source/en/perf_infer_gpu_one.md"), "r") as f:
|
|
doctext = f.read()
|
|
|
|
doctext = doctext.split("FlashAttention-2 is currently supported for the following architectures:")[1]
|
|
doctext = doctext.split("You can request to add FlashAttention-2 support")[0]
|
|
|
|
patterns = glob(os.path.join(REPO_PATH, "src/transformers/models/**/modeling_*.py"))
|
|
patterns_tf = glob(os.path.join(REPO_PATH, "src/transformers/models/**/modeling_tf_*.py"))
|
|
patterns_flax = glob(os.path.join(REPO_PATH, "src/transformers/models/**/modeling_flax_*.py"))
|
|
patterns = list(set(patterns) - set(patterns_tf) - set(patterns_flax))
|
|
archs_supporting_fa2 = []
|
|
for filename in patterns:
|
|
with open(filename, "r") as f:
|
|
text = f.read()
|
|
|
|
if "_supports_flash_attn_2 = True" in text:
|
|
model_name = os.path.basename(filename).replace(".py", "").replace("modeling_", "")
|
|
archs_supporting_fa2.append(model_name)
|
|
|
|
for arch in archs_supporting_fa2:
|
|
if arch not in doctext:
|
|
raise ValueError(
|
|
f"{arch} should be in listed in the flash attention documentation but is not. Please update the documentation."
|
|
)
|
|
|
|
|
|
def check_sdpa_support_list():
|
|
with open(os.path.join(REPO_PATH, "docs/source/en/perf_infer_gpu_one.md"), "r") as f:
|
|
doctext = f.read()
|
|
|
|
doctext = doctext.split(
|
|
"For now, Transformers supports SDPA inference and training for the following architectures:"
|
|
)[1]
|
|
doctext = doctext.split("Note that FlashAttention can only be used for models using the")[0]
|
|
|
|
patterns = glob(os.path.join(REPO_PATH, "src/transformers/models/**/modeling_*.py"))
|
|
patterns_tf = glob(os.path.join(REPO_PATH, "src/transformers/models/**/modeling_tf_*.py"))
|
|
patterns_flax = glob(os.path.join(REPO_PATH, "src/transformers/models/**/modeling_flax_*.py"))
|
|
patterns = list(set(patterns) - set(patterns_tf) - set(patterns_flax))
|
|
archs_supporting_sdpa = []
|
|
for filename in patterns:
|
|
with open(filename, "r") as f:
|
|
text = f.read()
|
|
|
|
if "_supports_sdpa = True" in text:
|
|
model_name = os.path.basename(filename).replace(".py", "").replace("modeling_", "")
|
|
archs_supporting_sdpa.append(model_name)
|
|
|
|
for arch in archs_supporting_sdpa:
|
|
if arch not in doctext and arch not in doctext.replace("-", "_"):
|
|
raise ValueError(
|
|
f"{arch} should be in listed in the SDPA documentation but is not. Please update the documentation."
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
check_flash_support_list()
|
|
check_sdpa_support_list()
|