mirror of
https://github.com/huggingface/transformers.git
synced 2025-08-02 19:21:31 +06:00
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: Matt <Rocketknight1@users.noreply.github.com> --------- Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
This commit is contained in:
parent
16ed0640be
commit
cc832cbd19
@ -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
|
||||
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 = re.findall(r"^\s*import\s+(\S+)\s*$", content, flags=re.MULTILINE)
|
||||
|
Loading…
Reference in New Issue
Block a user