Skip to content

hf_select_quant_linear add device_map #732

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

Merged
merged 5 commits into from
Dec 3, 2024
Merged
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
9 changes: 8 additions & 1 deletion gptqmodel/utils/importer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import OrderedDict

import torch
from typing import Optional, Union

from .backend import BACKEND
from ..nn_modules.qlinear.qlinear_bitblas import BitBLASQuantLinear
Expand Down Expand Up @@ -40,11 +40,18 @@ def hf_select_quant_linear(
group_size: int,
desc_act: bool,
sym: bool,
device_map: Optional[Union[str, dict]] = None,
backend: BACKEND = BACKEND.AUTO,
format: FORMAT = FORMAT.GPTQ,
pack: bool = False,
dynamic=None,
):
# force backend to ipex if cpu/xpu is designated device
if device_map is not None:
devices = [device_map] if isinstance(device_map, str) else list(device_map.values())
if any(dev in devices or torch.device(dev) in devices for dev in ["cpu", "xpu"]):
backend = BACKEND.IPEX

return select_quant_linear(
bits=bits,
group_size=group_size,
Expand Down
4 changes: 2 additions & 2 deletions gptqmodel/utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def convert_gptq_v1_to_v2_format(
qlinear_kernel: nn.Module,
):
# skip v1 to v2 conversion for ipex
if isinstance(qlinear_kernel, IPEXQuantLinear):
if qlinear_kernel == IPEXQuantLinear:
return model

# Limit thread usage to avoid auto-parallizataion regression
Expand Down Expand Up @@ -255,7 +255,7 @@ def convert_gptq_v2_to_v1_format(
qlinear_kernel: nn.Module,
):
# skip v2 to v1 conversion for ipex
if isinstance(qlinear_kernel, IPEXQuantLinear):
if qlinear_kernel == IPEXQuantLinear:
return model

# Limit thread usage to avoid auto-parallizataion regression
Expand Down