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

[FEATURE] add liger_kernel support #394

Merged
merged 1 commit into from
Sep 26, 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
2 changes: 2 additions & 0 deletions gptqmodel/models/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ def from_pretrained(
pretrained_model_name_or_path: str,
quantize_config: QuantizeConfig,
trust_remote_code: bool = False,
use_liger_kernel: bool = False,
**model_init_kwargs,
) -> BaseGPTQModel:
model_type = check_and_get_model_type(pretrained_model_name_or_path, trust_remote_code)
return MODEL_MAP[model_type].from_pretrained(
pretrained_model_name_or_path=pretrained_model_name_or_path,
quantize_config=quantize_config,
trust_remote_code=trust_remote_code,
use_liger_kernel=use_liger_kernel,
**model_init_kwargs,
)

Expand Down
10 changes: 10 additions & 0 deletions gptqmodel/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ def from_pretrained(
pretrained_model_name_or_path: str,
quantize_config: QuantizeConfig,
trust_remote_code: bool = False,
use_liger_kernel: bool = False,
torch_dtype: [str | torch.dtype] = "auto",
**model_init_kwargs,
):
Expand Down Expand Up @@ -1031,6 +1032,15 @@ def skip(*args, **kwargs):

config = AutoConfig.from_pretrained(pretrained_model_name_or_path, **model_init_kwargs)

if use_liger_kernel:
from liger_kernel.transformers.monkey_patch import MODEL_TYPE_TO_APPLY_LIGER_FN

apply_fn = MODEL_TYPE_TO_APPLY_LIGER_FN.get(config.model_type, None)
if apply_fn is None:
raise ValueError(f"apply_fn is not defined for model type {config.model_type}")

apply_fn()

if torch_dtype == "auto":
torch_dtype = auto_dtype_from_config(config)
elif not isinstance(torch_dtype, torch.dtype):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ intel_extension_for_transformers>=1.4.2
auto-round==0.3
huggingface-hub>=0.24.2
lm_eval==0.4.3
liger-kernel>=0.3.0
Loading