mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 18:22:34 +06:00
Fix performance in get_imports regexp (#34298)
* fix: Fix performance in get_imports regexp * Minimize get_imports content regexp
This commit is contained in:
parent
4e2e8809ff
commit
f55595b177
@ -152,7 +152,8 @@ def get_imports(filename: Union[str, os.PathLike]) -> List[str]:
|
||||
content = f.read()
|
||||
|
||||
# filter out try/except block so in custom code we can have try/except imports
|
||||
content = re.sub(r"\s*try\s*:\s*.*?\s*except\s*.*?:", "", content, flags=re.MULTILINE | re.DOTALL)
|
||||
content = re.sub(r"\s*try\s*:.*?except.*?:", "", content, flags=re.DOTALL)
|
||||
|
||||
# filter out imports under is_flash_attn_2_available block for avoid import issues in cpu only environment
|
||||
content = re.sub(
|
||||
r"if is_flash_attn[a-zA-Z0-9_]+available\(\):\s*(from flash_attn\s*.*\s*)+", "", content, flags=re.MULTILINE
|
||||
|
Loading…
Reference in New Issue
Block a user