Skip to content

Commit

Permalink
catch xformers import
Browse files Browse the repository at this point in the history
  • Loading branch information
Isotr0py committed Sep 3, 2024
1 parent 3b59488 commit ebb5676
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions vllm/model_executor/models/blip.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
from vllm.multimodal.utils import (cached_get_tokenizer,
repeat_and_pad_placeholder_tokens)
from vllm.sequence import VLLM_TOKEN_ID_ARRAY_TYPE, SequenceData
from vllm.utils import is_cpu

USE_XFORMERS_OPS = not is_cpu()
if USE_XFORMERS_OPS:
try:
from xformers import ops as xops
USE_XFORMERS_OPS = True
except ImportError:
USE_XFORMERS_OPS = False


def get_blip_patch_grid_length(*, image_size: int, patch_size: int) -> int:
Expand Down
7 changes: 4 additions & 3 deletions vllm/model_executor/models/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
from vllm.multimodal.utils import (cached_get_tokenizer,
repeat_and_pad_placeholder_tokens)
from vllm.sequence import VLLM_TOKEN_ID_ARRAY_TYPE, SequenceData
from vllm.utils import is_cpu

USE_XFORMERS_OPS = not is_cpu()
if USE_XFORMERS_OPS:
try:
from xformers import ops as xops
USE_XFORMERS_OPS = True
except ImportError:
USE_XFORMERS_OPS = False


def get_clip_patch_grid_length(*, image_size: int, patch_size: int) -> int:
Expand Down
7 changes: 4 additions & 3 deletions vllm/model_executor/models/intern_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
RowParallelLinear)
from vllm.model_executor.layers.quantization import QuantizationConfig
from vllm.model_executor.model_loader.weight_utils import default_weight_loader
from vllm.utils import is_cpu

USE_XFORMERS_OPS = not is_cpu()
if USE_XFORMERS_OPS:
try:
from xformers import ops as xops
USE_XFORMERS_OPS = True
except ImportError:
USE_XFORMERS_OPS = False

NORM2FN = {
'rms_norm': RMSNorm,
Expand Down
7 changes: 4 additions & 3 deletions vllm/model_executor/models/siglip.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
from vllm.multimodal.utils import (cached_get_tokenizer,
repeat_and_pad_placeholder_tokens)
from vllm.sequence import VLLM_TOKEN_ID_ARRAY_TYPE, SequenceData
from vllm.utils import is_cpu

USE_XFORMERS_OPS = not is_cpu()
if USE_XFORMERS_OPS:
try:
from xformers import ops as xops
USE_XFORMERS_OPS = True
except ImportError:
USE_XFORMERS_OPS = False


def get_siglip_patch_grid_length(*, image_size: int, patch_size: int) -> int:
Expand Down

0 comments on commit ebb5676

Please sign in to comment.