Merged
Conversation
* This will require Intel oneAPI Toolkit 2024.0
Contributor
Author
|
Tested OK on my A770 16GB. I feel that it's a little faster on ChatGLM3-6B. |
Owner
|
Thanks for the update. @notsyncing since you have an A770, could you try the new HQQ loader at #4888? I think that it should allow you to run bigger models in 4-bit precision with your GPU. I recommend the following model for testing: https://huggingface.co/mobiuslabsgmbh/Llama-2-13b-chat-hf-4bit_g64-HQQ |
Contributor
Author
|
@oobabooga I'm getting this error with HQQ loader: Looks like it supports CUDA only. |
Owner
|
That's a bummer. Thanks for the test! |
1 task
Can you replace the from hqq.core.quantize import *
from hqq.models.hf.llama import LlamaHQQ
class LlamaHQQXPU(LlamaHQQ):
@classmethod
def from_quantized(cls, save_dir_or_hub, cache_dir=''):
#Get directory path
save_dir = cls.try_snapshot_download(save_dir_or_hub, cache_dir)
#Load model from config
model = cls.create_model(save_dir)
#Name the layers
cls.autoname_modules(model)
#Load weights
try:
weights = cls.load_weights(save_dir, map_location='xpu')
except Exception as error:
print("Failed to load the weights", error)
return
#load_state_dict() doesn't work with modules initialized with init_empty_weights(), so we need to do this manually
@torch.no_grad()
def _load_module(module, params=None):
if(module.name not in weights):
return module.half().to('xpu')
state_dict = weights[module.name]
if(('W_q' in state_dict) and ('meta' in state_dict)):
module = HQQLinear(linear_layer=None, quant_config=None)
module.load_state_dict(state_dict)
else:
for key in state_dict:
setattr(module, key, torch.nn.Parameter(state_dict[key], requires_grad=False))
return module
#Load modules
cls.patch_model(model, _load_module, _load_module, dict([(k, None) for k in cls.get_linear_tags()]))
#Load other weights that are not part of any module
cls.post_module_load(model, weights)
return model
model = LlamaHQQXPU.from_quantized(model_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist: