Fix performance in get_imports regexp (#34298)

* fix: Fix performance in get_imports regexp

* Minimize get_imports content regexp
This commit is contained in:
Aleksey Lobanov 2024-10-29 20:29:24 +03:00 committed by GitHub
parent 4e2e8809ff
commit f55595b177
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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