You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, just found this wonderful project. May I ask how could I make the sufficient changes to support the model architecture Qwen-1.8B/7B/14B? The differences of that to LLAMA is that the Q, K, V projection matrices have biases and these weights are fused.
I think maybe if you split the matrices to Q, K, V as you provided, and probably change that line to addmm (though I can't confirm if addmm even works on a vector + matrix), then maybe it works?
Yes, that won't work because it will convert to a LLaMa2 model with attention_bias=True, which doesn't seem to be supported in this project. (As can be seen here, only the weights of the QKV and MLP layers are taken into consideration)
I think maybe if you split the matrices to Q, K, V as you provided, and probably change that line to addmm (though I can't confirm if addmm even works on a vector + matrix), then maybe it works?
I can do that, but after a second look, I guess rewriting that line to addmm is not right because this function is used for both the forward pass and the backward pass. Maybe The correct thing to do is to do an additional add in the forward pass and pass an addition argument back in the backward pass (the gradient of the bias term)
@peterjc123 Oh my it seems like Qwen support will be much more complicated - I never took an exact look at Qwen, but if it has biases, it will change especially the fast LoRA patching.
@hiyouga@danielhanchen Last time, I tried to perform llamafy_qwen first and then import the model through unsloth but it throws an error about the property max_seq_len of FastLlamaModel is not found.
@peterjc123@hiyouga Oh I think I fixed the max_seq_len issue. In terms of the bias term, I can provide a temporary patch which turns off the manual autograd engine for linear layers with biases, but the rest of the optimizations will stay put. This might make Unsloth 20% slower than the full optims which I'll do for a future release.
Actually I just noticed Qwen has a vocab size of 150,000 something? The CUDA max thread size is 2^16 = 65,536, so Llama is fine (32,000). I think some other models like Yi are cutting it close with a 64,000 vocab, whilst Qwen will definitely not work anyways for now.
There was another feature request for me to add in more than 2^16 vocab sizes, which will require a complete change of the CE Loss. I can temporarily disable the fast route for the CE Loss if in fact the vocab size exceeds 2^16, and use Pytorch's internal CE Loss.
Activity
danielhanchen commentedon Dec 24, 2023
@peterjc123 Thanks! Unsloth was just integrated with Llama-factory, so I think you can use https://github.com/hiyouga/LLaMA-Factory/blob/main/tests/llamafy_qwen.py which will llama-fy Qwen, however I'm assuming Qwen has biases right? Maybe llama-fying won't even work.
I think maybe if you split the matrices to Q, K, V as you provided, and probably change that line to
addmm(though I can't confirm if addmm even works on a vector + matrix), then maybe it works?peterjc123 commentedon Dec 24, 2023
Yes, that won't work because it will convert to a LLaMa2 model with
attention_bias=True, which doesn't seem to be supported in this project. (As can be seen here, only the weights of the QKV and MLP layers are taken into consideration)I can do that, but after a second look, I guess rewriting that line to addmm is not right because this function is used for both the forward pass and the backward pass. Maybe The correct thing to do is to do an additional
addin the forward pass and pass an addition argument back in the backward pass (the gradient of the bias term)danielhanchen commentedon Dec 24, 2023
@peterjc123 Oh my it seems like Qwen support will be much more complicated - I never took an exact look at Qwen, but if it has biases, it will change especially the fast LoRA patching.
peterjc123 commentedon Dec 25, 2023
It will be easier if the biases are non-trainable(by skipping the changes in the backward passes). I'll try out it first.
danielhanchen commentedon Dec 25, 2023
@peterjc123 Cool! Tell me how it goes! If you need help - ask away!
hiyouga commentedon Dec 28, 2023
unsloth/unsloth/models/llama.py
Lines 61 to 66 in 0369e7a
unsloth/unsloth/models/llama.py
Line 124 in 0369e7a
I think it might be possible to consider the bias term?
Additionally, I'll perform some empirical validation of the fine-tuning performance using llamafied Qwen w/ unsloth later.
peterjc123 commentedon Dec 28, 2023
@hiyouga @danielhanchen Last time, I tried to perform
llamafy_qwenfirst and then import the model through unsloth but it throws an error about the propertymax_seq_lenofFastLlamaModelis not found.danielhanchen commentedon Dec 28, 2023
@peterjc123 @hiyouga Oh I think I fixed the
max_seq_lenissue. In terms of the bias term, I can provide a temporary patch which turns off the manual autograd engine for linear layers with biases, but the rest of the optimizations will stay put. This might make Unsloth 20% slower than the full optims which I'll do for a future release.danielhanchen commentedon Dec 28, 2023
Actually I just noticed Qwen has a vocab size of 150,000 something? The CUDA max thread size is 2^16 = 65,536, so Llama is fine (32,000). I think some other models like Yi are cutting it close with a 64,000 vocab, whilst Qwen will definitely not work anyways for now.
There was another feature request for me to add in more than 2^16 vocab sizes, which will require a complete change of the CE Loss. I can temporarily disable the fast route for the CE Loss if in fact the vocab size exceeds 2^16, and use Pytorch's internal CE Loss.
danielhanchen commentedon Dec 29, 2023
@hiyouga @peterjc123 Just added prelim Qwen support! :)
danielhanchen commentedon Jan 4, 2024
Closing this now since Qwen is now supported!
Merge pull request unslothai#50 from unslothai/fix/auth-setup-rollback