"git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "64ee3e57389bce76e22f4da7ae5716553a604ce3"
Unverified Commit cc832cbd authored by Ekaterina Aidova's avatar Ekaterina Aidova Committed by GitHub
Browse files

filter flash_attn optional imports loading remote code (#30954)



* filter flash_attn optional imports loading remote code

* improve pattern

* fix code style

* Update src/transformers/dynamic_module_utils.py
Co-authored-by: default avatarMatt <Rocketknight1@users.noreply.github.com>

---------
Co-authored-by: default avatarMatt <Rocketknight1@users.noreply.github.com>
parent 16ed0640
...@@ -149,6 +149,10 @@ def get_imports(filename: Union[str, os.PathLike]) -> List[str]: ...@@ -149,6 +149,10 @@ def get_imports(filename: Union[str, os.PathLike]) -> List[str]:
# filter out try/except block so in custom code we can have try/except imports # 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*:\s*.*?\s*except\s*.*?:", "", content, flags=re.MULTILINE | 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
)
# Imports of the form `import xxx` # Imports of the form `import xxx`
imports = re.findall(r"^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE) imports = re.findall(r"^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment