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

[Draft] proposal for ipex quant support #6440

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions vllm/model_executor/layers/quantization/awq.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def apply(self,
out_shape = (x.shape[:-1] + (qweight.shape[-1] * pack_factor, ))
reshaped_x = x.reshape(-1, x.shape[-1])

if use_ipex():
# detail api depends on ipex, it may fuse bias.
out = ipex_awq_gemm(x, qweight, scales, qzeros, pack_factor, ...)
return out

# num_tokens >= threshold
FP16_MATMUL_HEURISTIC_CONDITION = x.shape[:-1].numel() >= 256

Expand Down
8 changes: 8 additions & 0 deletions vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ def is_xpu() -> bool:
return hasattr(torch, "xpu") and torch.xpu.is_available()


@lru_cache(maxsize=None)
def use_ipex() -> bool:
try:
import intel_extension_for_pytorch as ipex # noqa: F401
return True
except ImportError:
return False

@lru_cache(maxsize=None)
def get_max_shared_memory_bytes(gpu: int = 0) -> int:
"""Returns the maximum shared memory per thread block in bytes."""
Expand Down
10 changes: 10 additions & 0 deletions vllm/worker/xpu_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def from_broadcasted_tensor_dict(
attn_backend, tensor_dict)
return cls(**tensor_dict)

# ipex (Both CPU and XPU) will have some optimization on model weight layout
# to fully leverage hardware potential. We want to add cpu quant optimization
# cpu would performs best with a specific weight layout (which is different to cuda device layout),
# so a repack api should be called.
def IpexXPUModelQuantWeightWrapper():
# todo: for quant model, call ipex repack API.
# eg: return ipex.repack_awq(model)
pass

class XPUModelRunner(ModelRunnerBase[ModelInputForXPU]):

Expand Down Expand Up @@ -144,6 +152,8 @@ def load_model(self) -> None:
logger.info("Loading model weights took %.4f GB",
self.model_memory_usage / float(2**30))

self.model = IpexXPUModelQuantWeightWrapper(self.model)

@property
def vocab_size(self) -> int:
return self.model_config.get_vocab_size()
Expand Down
Loading