hatchetProject / QuEST

QuEST: Efficient Finetuning for Low-bit Diffusion Models
26 stars 2 forks source link

Can you share your calibration script and evaluation script? #2

Closed GuCheng123 closed 4 months ago

GuCheng123 commented 4 months ago

Hi, your work is so cool! I generated the calibration data according to the calibration method of your paper, but the generated results and accuracy are not good. Could you share your calibration script and accuracy evaluation script for the three types of Diffusion?

hatchetProject commented 4 months ago

Hi, may I know under which setting (task and weight-act-bits) are you generating the results, as well as the hyper-parameters and command lines you are using?

The calibration data for LSUN-Bedrooms/Churches and Stable Diffusion can be downloaded from the Q-Diffusion repo, I will release the calibration dataset for ImageNet soon.

GuCheng123 commented 4 months ago

Hi, may I know under which setting (task and weight-act-bits) are you generating the results, as well as the hyper-parameters and command lines you are using?

The calibration data for LSUN-Bedrooms/Churches and Stable Diffusion can be downloaded from the Q-Diffusion repo, I will release the calibration dataset for ImageNet soon.

Thanks, I meant to refer to your code for collecting the calibration dataset. Second, when I run your stable diffusion quantization, why is there no PLMSSampler_Timewise class?

hatchetProject commented 4 months ago

Hi, may I know under which setting (task and weight-act-bits) are you generating the results, as well as the hyper-parameters and command lines you are using? The calibration data for LSUN-Bedrooms/Churches and Stable Diffusion can be downloaded from the Q-Diffusion repo, I will release the calibration dataset for ImageNet soon.

Thanks, I meant to refer to your code for collecting the calibration dataset. Second, when I run your stable diffusion quantization, why is there no PLMSSampler_Timewise class?

Hi, I uploaded a script (get_calibration_set_imagenet_ddim.py) for getting the calibration set on ImageNet (with DDIM sampler). You can refer to it and collect your own calibration data. The main idea is to extract the direct inputs to the UNet model using the intermediate outputs of the sampler. The command for running the process is:

python get_calibration_set_imagenet_ddim.py -r <FP_Model_Path> -n 10 --batch_size 10 -c 20 -e 1.0 -seed 40 -l output/ --cond

For the PLMSSampler_Timewise, thanks for pointing this out. I have added it to ldm/models/diffusion/plms.py. It only adds one line code to match the timewise activation quantizer.

GuCheng123 commented 4 months ago

Hi, may I know under which setting (task and weight-act-bits) are you generating the results, as well as the hyper-parameters and command lines you are using? The calibration data for LSUN-Bedrooms/Churches and Stable Diffusion can be downloaded from the Q-Diffusion repo, I will release the calibration dataset for ImageNet soon.

Thanks, I meant to refer to your code for collecting the calibration dataset. Second, when I run your stable diffusion quantization, why is there no PLMSSampler_Timewise class?

Hi, I uploaded a script (get_calibration_set_imagenet_ddim.py) for getting the calibration set on ImageNet (with DDIM sampler). You can refer to it and collect your own calibration data. The main idea is to extract the direct inputs to the UNet model using the intermediate outputs of the sampler. The command for running the process is:

python get_calibration_set_imagenet_ddim.py -r <FP_Model_Path> -n 10 --batch_size 10 -c 20 -e 1.0 -seed 40 -l output/ --cond

For the PLMSSampler_Timewise, thanks for pointing this out. I have added it to ldm/models/diffusion/plms.py. It only adds one line code to match the timewise activation quantizer.

Thanks for the script! But according to your command, there are still some bugs, such as 'UNetModel' object has no attribute 'set_timestep', etc.

hatchetProject commented 4 months ago

I assume the issue should be in ldm/models/diffusion/ddim.py line149~154. Please comment them.

The key here is that: If you are using the UNet model when doing sampling, then comment these lines. If you are using quantized model (qnn) for sampling, then include them and adjust them according to sampled timesteps.

GuCheng123 commented 4 months ago

I assume the issue should be in ldm/models/diffusion/ddim.py line149~154. Please comment them.

The key here is that: If you are using the UNet model when doing sampling, then comment these lines. If you are using quantized model (qnn) for sampling, then include them and adjust them according to sampled timesteps.

Sorry to bother you again. When I run quantized imagenet, I get the following error: image

hatchetProject commented 4 months ago

Hi, I think you can comment line 210 in qdiff/post_layer_recon.py. Since alpha is not actually optimized.

This error should come from the fact that the weights of the model are not quantized using the AdaRound quantizer (which is introduced in the weight reconstruction process: layer_recon.py and block_recon.py).

GuCheng123 commented 4 months ago

Hi, I think you can comment line 210 in qdiff/post_layer_recon.py. Since alpha is not actually optimized.

This error should come from the fact that the weights of the model are not quantized using the AdaRound quantizer (which is introduced in the weight reconstruction process: layer_recon.py and block_recon.py).

I collected the data from your get_calibration_set_imagenet_ddim.py and got the following error: It is also recommended that you run each diffusion quantization to check your code for bugs. image

hatchetProject commented 4 months ago

Hi, you can overcome this by replacing the current post_layer_recon.py's code with the newly uploaded qdiff/post_layer_recon_imagenet.py's content.

Apologies for the bugs, as this repo is mixed of different tasks and settings. The current one should be mainly based on unconditional generation. Recently I am a little busy but I will take time to refine the structure as soon as possible. Thanks for your kind consideration!

GuCheng123 commented 4 months ago

Hi, you can overcome this by replacing the current post_layer_recon.py's code with the newly uploaded qdiff/post_layer_recon_imagenet.py's content.

Apologies for the bugs, as this repo is mixed of different tasks and settings. The current one should be mainly based on unconditional generation. Recently I am a little busy but I will take time to refine the structure as soon as possible. Thanks for your kind consideration!

Sorry to keep bothering you. You are very nice! I will communicate with you if there are bugs. I wish you all the best in your research!