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

convert str backend to enum backend #772

Merged
merged 4 commits into from
Dec 5, 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
1 change: 1 addition & 0 deletions gptqmodel/utils/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BACKEND(Enum):

def get_backend(backend: str):
try:
backend = backend.upper()
return BACKEND[backend]
except KeyError:
raise ValueError(f"Invalid Backend str: {backend}")
8 changes: 6 additions & 2 deletions gptqmodel/utils/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..nn_modules.qlinear.tritonv2 import TRITON_AVAILABLE, TRITON_INSTALL_HINT, TritonV2QuantLinear
from ..quantization import FORMAT
from ..utils.logger import setup_logger
from .backend import BACKEND
from .backend import BACKEND, get_backend

logger = setup_logger()

Expand Down Expand Up @@ -57,10 +57,14 @@ def hf_select_quant_linear(
desc_act: bool,
sym: bool,
checkpoint_format: str,
backend: Optional[BACKEND] = None,
backend: Optional[Union[str, BACKEND]] = None,
meta: Optional[Dict[str, any]] = None,
device_map: Optional[Union[str, dict]] = None,
) -> Type[BaseQuantLinear]:
# convert hf string backend to backend.enum
if isinstance(backend, str):
backend = get_backend(backend)

if device_map is not None:
devices = [device_map] if isinstance(device_map, str) else list(device_map.values())
if "cpu" in devices or torch.device("cpu") in devices:
Expand Down