Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch sdpa check function in specific module attributes table #12285

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/llm/src/ipex_llm/transformers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class _BaseAutoModelClass:

@classmethod
@patch("transformers.dynamic_module_utils.get_imports", patch_flash_attn_import)
@patch("transformers.utils.is_torch_sdpa_available", patch_sdpa_available, create=True)
@patch("transformers.modeling_utils.is_torch_sdpa_available", patch_sdpa_available, create=True)
def from_pretrained(cls,
*args,
**kwargs):
Expand Down Expand Up @@ -542,7 +542,7 @@ def load_convert(cls, q_k, optimize_model, *args, **kwargs):

@classmethod
@patch("transformers.dynamic_module_utils.get_imports", patch_flash_attn_import)
@patch("transformers.utils.is_torch_sdpa_available", patch_sdpa_available, create=True)
@patch("transformers.modeling_utils.is_torch_sdpa_available", patch_sdpa_available, create=True)
def load_low_bit(cls,
pretrained_model_name_or_path,
*model_args,
Expand Down
11 changes: 10 additions & 1 deletion python/llm/src/ipex_llm/transformers/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from typing import List
from transformers.dynamic_module_utils import get_imports
from transformers.utils import is_torch_sdpa_available
Copy link
Contributor

@Oscilloscope98 Oscilloscope98 Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if for the lower transformers version without support for is_torch_sdpa_available?

Maybe add sth like

def patch_sdpa_available() -> bool:
    if IPEXImporter.is_xpu_version_installed():
        return False
    else:
        try:
            from transformers.utils import is_torch_sdpa_available
            return is_torch_sdpa_available()
        except xxx:
            return False 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the import here

from ipex_llm.utils.ipex_importer import IPEXImporter


def patch_flash_attn_import(filename: str) -> List[str]:
Expand All @@ -28,4 +30,11 @@ def patch_flash_attn_import(filename: str) -> List[str]:


def patch_sdpa_available() -> bool:
return False
if IPEXImporter.is_xpu_version_installed():
return False
else:
try:
from transformers.utils import is_torch_sdpa_available
return is_torch_sdpa_available()
except ImportError:
return False
Loading