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

qint4 failed for diffusers: QBitsTensor cannot be changed #312

Open
liyihao1230 opened this issue Sep 19, 2024 · 1 comment
Open

qint4 failed for diffusers: QBitsTensor cannot be changed #312

liyihao1230 opened this issue Sep 19, 2024 · 1 comment

Comments

@liyihao1230
Copy link

When I used qfloat8 to quantize the unet model of Kolors-diffusers, it works well. But failed with qint4.

use qint4/(qfloat8)

class KolorsUNet2DConditionModel(QuantizedDiffusersModel):
base_class = UNet2DConditionModel
model = UNet2DConditionModel.from_pretrained("./Kolors-diffusers", variant="fp16", subfolder="unet")
qmodel = KolorsUNet2DConditionModel.quantize(model, weights=qint4) # qfloat8
qmodel.save_pretrained("./kolors-qint4") # kolors-qfloat8

work well in qfloat8 but failed with qint4

unet = KolorsUNet2DConditionModel.from_pretrained('./model_zoo/kolors-int4')
#unet = KolorsUNet2DConditionModel.from_pretrained('./model_zoo/kolors-qfloat8')
pipe = KolorsPipeline.from_pretrained(
KOLORS_MODEL_PATH,
unet=unet._wrapped.to(dtype=torch.float16),
text_encoder=text_encoder,
torch_dtype=torch.float16, # torch.float16
variant="fp16",# use_safetensors=True
).to('cuda')

error log

Traceback (most recent call last):
File "/mnt/data/liyihao/workspace/text2img/text2img_kolors_v5_light.py", line 101, in
unet=unet._wrapped.to(dtype=torch.float16),
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1174, in to
return self._apply(convert)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 780, in _apply
module._apply(fn)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 805, in _apply
param_applied = fn(param)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1160, in convert
return t.to(
File "/usr/local/lib/python3.10/dist-packages/optimum/quanto/tensor/qtensor.py", line 93, in torch_function
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/optimum/quanto/tensor/qbits/qbits.py", line 258, in torch_dispatch
return qdispatch(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/optimum/quanto/tensor/qbits/qbits_ops.py", line 54, in _to_copy
raise ValueError("The dtype of a QBitsTensor cannot be changed")
ValueError: The dtype of a QBitsTensor cannot be changed

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Oct 20, 2024
@dacorvo dacorvo removed the Stale label Oct 22, 2024
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

No branches or pull requests

2 participants