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

Simple QuaRot proof of concept. #407

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

sgsdxzy
Copy link

@sgsdxzy sgsdxzy commented Apr 11, 2024

How to enable QuaRot for weight quantization:

  1. install AutoQuarot pip install git+https://github.com/sgsdxzy/AutoQuarot.git
  2. convert the fp16 model to quarot weights
import transformers
import auto_quarot

model = transformers.AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16)
qrmodel = auto_quarot.AutoQuarotForForCausalLM.from_transformers(model)
qrmodel.fuse_layer_norms()
qrmodel.rotate_model("hadamard", device=0)
qrmodel.model.save_pretrained(rotated_model_path)
  1. use exllamav2 to quantize/run the rotated model, it will be recognized automatically.

@sgsdxzy sgsdxzy changed the title Simple quarot proof of concept. Simple QuaRot proof of concept. Apr 11, 2024
@Ph0rk0z
Copy link

Ph0rk0z commented Apr 12, 2024

Are the quants limited to 4bit only? Do they get smaller compared to quantizing the regular model? I know the paper said they lose some PPL. This might be helpful for all the huge models released now if so.

@sgsdxzy
Copy link
Author

sgsdxzy commented Apr 12, 2024

No you can use any quant (AutoGPTQ, AutoAWQ, exl2) with any bpw for weights, after the rotation the models weights still keep their original shape but should be smoother with less outliers. The problem is that the ppl doesn't seem to improve for exl2 quants. It does improve a bit for AutoGPTQ.

@sgsdxzy sgsdxzy marked this pull request as ready for review April 12, 2024 17:14
@sgsdxzy
Copy link
Author

sgsdxzy commented Apr 12, 2024

QuaRot of weights does not consistently improve ppl for exl2 quants.
QuaRot of kv cache improves ppl for fp8/q4 kv cache.

@turboderp
Copy link
Owner

Funnily enough I was just working on that. Fused it into the realtime quantization kernels though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants