[Q] Does support for embedding and conv2d layers in bnb.py at tuners/lora make sense?
Feature request
Currently, bnb.py at peft/tuners/lora has classes for Linear4bit and Linear8bit. But layers.py at peft/tuners/lora defines implementations for LoRA in Linear, Embedding, and Conv2d (I believe in the future, it would also include Conv3d as per #1193).
I was wondering if it makes sense to extend quantization support for Embedding and Conv2d layers? Could they be a thing in bnb.py? (possibly in other tuners as well). Sorry if this is obvious.
Motivation
I was just curious about bnb.py only having support for Linear when LoRA can be implemented through other layer types (please correct me if I'm wrong).
Your contribution
With some help, I would be happy to contribute a PR towards this, starting with bnb for Embedding.
Yes, in principle, it should be possible add support for the Embedding layer from bnb to PEFT. Feel free to open a PR and ping us so that we can give feedback and help with open questions.
Regarding Conv2d, I don't think it's supported by bnb and thus could not be easily added to PEFT.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Thank you very much for making such a great project open source, I learned a lot of new things by using PEFT, thank you again. I have a puzzle of class Linear8bitLt in peft/src/peft/tuners/lora/bnb.py. By reading the code I understand that it is different from the definition in bitsanbytes because the latter uses int8 precision during calculation. I used PEFT in Alpaca-lora finetune. In the transfoemer model obtained with is_load_8bit, the parts (q, v) replaced by lora still use Linear8bitLt on the surface, but actually use torch.nn.Linear in peft/src/peft/tuners/lora/layer.py update_layer(). Lora layer does not use int8 to participate in the calculation, it is for the sake of accuracy. Is that right, or did I not understand the whole calling program correctly?
Hi @asr-sheep1
Below is what happens under the hood if you initialize a Linear8bitLt class from peft
In blue you have the original linear layer (which is in 8bit) and we simply attach the LoRA adapters next to it and calculate the sum of both hidden states.
The original Linear8bit layer performs some part of the matmul in 8-bit and other parts (outliers) in 16-bit but the resulting hidden states will be in 16-bit precision. See https://huggingface.co/blog/hf-bitsandbytes-integration for more details
Hi @asr-sheep1
Below is what happens under the hood if you initialize a
Linear8bitLtclass from peftIn blue you have the original linear layer (which is in 8bit) and we simply attach the LoRA adapters next to it and calculate the sum of both hidden states.
The original
Linear8bitlayer performs some part of the matmul in 8-bit and other parts (outliers) in 16-bit but the resulting hidden states will be in 16-bit precision. See https://huggingface.co/blog/hf-bitsandbytes-integration for more details
Thanks! I have reviewed this material. So, during the calculation process, Lora_A and Lora_B, these two layers of networks, did not use int8 matmul, right?
Correct yes, Lora_A and Lora_B do not use int8 matmul in this case
Correct yes, Lora_A and Lora_B do not use int8 matmul in this case
Thank you very much for your reply, helping me resolve a confusion. I will further study the excellent work on PEFT. Salute to you all.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.