Repository navigation
Description
I am attempting to replicate the Mistral 7b model finetuning locally as outlined below Unsloth Open column in the README.md file. I have successfully downloaded the dataset and the model to my local machine, which is a deviation from the original jupyter notebook that used data directly from the cloud.
model_name = "./Mistral-7B-v0.1"
...
dataset = load_dataset(path = "./SlimOrca", split = "train")
The initial stages of the Jupyter notebook, which include multiple code blocks, were executed without any issues. However, I have run into an error during the execution of the trainer_stats = trainer.train() block. The issue arises with a ValueError stating that the Query/Key/Value must have either BMHK or BMK shape.
ValueError: Query/Key/Value should all have BMHK or BMK shape.
query.shape: torch.Size([4, 2021, 8, 4, 128])
key.shape : torch.Size([4, 2021, 8, 4, 128])
value.shape: torch.Size([4, 2021, 8, 4, 128])
I have even tried reverting back to using the HuggingFace dataset instead of the local one to see if the issue was related to my dataset location. Unfortunately, I encountered the same error.
Here’s a brief overview of my setup:
==((====))== Unsloth: Fast Mistral patching release 2023.12
\\ [/](https://file+.vscode-resource.vscode-cdn.net/)| GPU: NVIDIA GeForce RTX 4090. Max memory: 23.647 GB
O^O/ \_/ \ CUDA compute capability = 8.9
\ [/](https://file+.vscode-resource.vscode-cdn.net/) Pytorch version: 2.1.0.post300. CUDA Toolkit = 11.8
"-____-" bfloat16 support = TRUE
GPU = NVIDIA GeForce RTX 4090. Max memory = 23.647 GB.
4.66 GB of memory reserved.
Additionally, I have addressed an issue with the torch version format. The original Unsloth configuration didn't support version numbers with four segments, so I modified the version parsing by changing from major_torch, minor_torch, _ = torch.version.split(".") to major_torch, minor_torch, _ = torch.__version__.split(".")[0:3] to accommodate the expected format.
Would anyone be able to point me in the right direction, or has anyone experienced a similar issue while working on model finetuning replication? Your help would be greatly appreciated as this error is currently standing in the way of my progress.
Thank you in advance for any assistance!
Activity
danielhanchen commentedon Dec 17, 2023
@alvis233 Hey! Thanks for trying out Unsloth!
torch.versionissue - I'll add a fixpip install "unsloth[cu118] @ git+https://github.com/unslothai/unsloth.git"and notpip install "unsloth[cu118_ampere] @ git+https://github.com/unslothai/unsloth.git". Since you have a RTX 4090, the ampere path can speed things up even more.[-]Issues Encountered While Attempting to Replicate Mistral 7b Model Finetuning Locally[/-][+]ValueError: Query/Key/Value should all have BMHK or BMK shape for Mistral 7b[/+]danielhanchen commentedon Dec 17, 2023
@alvis233 I just ran the Mistral 7b notebook on a A100 and using your install path ie
cu118and notcu118_ampere.The trainer seems to be running fine:

Are you running the A100 Mistral 7b notebook? https://colab.research.google.com/drive/1SKrKGV-BZoU4kv5q3g0jtE_OhRgPtrrQ?usp=sharing
danielhanchen commentedon Dec 17, 2023
@alvis233 If you need more help - join our Discord! https://discord.gg/u54VK8m8tk
alvis233 commentedon Dec 17, 2023
Yes, I am using the notebook from the exact link that you provided. To rule out any issues with other changes that I might have made, I will reinstall it and try again.
alvis233 commentedon Dec 17, 2023
By the way, below are the complete error messages:
I would appreciate it if you could take a closer look.
danielhanchen commentedon Dec 17, 2023
@alvis233 Wait I just noticed - this is a Windows machine?
alvis233 commentedon Dec 17, 2023
After reinstalling UnSloth, the issue persists. Additionally, I found that NVCC is required for installation when attempting to install UnSloth from the Ampere path, as indicated by pip. However, my CUDA environment was set up through conda, which only provides minimal support without NVCC. Consequently, I followed the 'Installation Instructions' section in the README.md to reinstall UnSloth. I'm uncertain if the absence of NVCC is contributing to this issue.
alvis233 commentedon Dec 17, 2023
No, this is an Ubuntu system, running kernel version
Linux 6.2.0-39-generic 22.04.1-Ubuntu x86_64 GNU/Linuxdanielhanchen commentedon Dec 17, 2023
@alvis233 Ok my bad - I just get confused when I see vscode :))
danielhanchen commentedon Dec 17, 2023
For Conda - did u follow the conda install path and not the pip?
alvis233 commentedon Dec 17, 2023
I installed the unsloth by
pip install "unsloth[kaggle] @ git+https://github.com/unslothai/unsloth.git"as described under Installation Instructions - Conda section in the README.md file. All previous code blocks in the notebook, which involve importing and initializing UnSloth, have executed smoothly. The nvidia-smi command also runs smoothly, indicating that the GPU and drivers are operational.danielhanchen commentedon Dec 17, 2023
@alvis233 Including
conda install cudatoolkit xformers bitsandbytes pytorch pytorch-cuda=12.1 \ -c pytorch -c nvidia -c xformers -c conda-forge -yright?Hmm this sounds like a complex case - your error message is very weird since I can't seem to glean anything out of it
danielhanchen commentedon Dec 17, 2023
ACTUALLY @alvis233 can you run:
python -m xformers.infoin a terminal and print it out here :)
alvis233 commentedon Dec 17, 2023
I have executed the command as you suggested, and here is the output:
danielhanchen commentedon Dec 17, 2023
OHHH ur xformers is an old version!! version 0.22 was when group query attention was added - hence the error message!
danielhanchen commentedon Dec 17, 2023
I think if you upgrade xformers to the latest version, or any version above 0.0.22, Unsloth should work!
alvis233 commentedon Dec 17, 2023
I sincerely appreciate the time and effort you have invested in helping me troubleshoot this issue. It has come to my attention that newer versions of xformers do not support Python 3.11. Unfortunately, downgrading the Python version isn't straightforward for me either due to complex dependencies in my current environment.
I've encountered another issue while trying to set up a new environment with python=3.9; I am getting a SyntaxError complaint from pip during the installation of unsloth:
torch_version = = torch.version.split('.') SyntaxError: invalid syntax, which seems like it could result from a WIP commit(but I'm not sure).It looks like I need to allocate some time to resolve these cascading issues. I plan to make another attempt when I can find a suitable time window, and I will keep this issue updated with any progress.
Thank you once again for your kind assistance and patience.
danielhanchen commentedon Dec 18, 2023
@alvis233 Oops just fixed the == issue - thanks for spotting it. Hmm I can check Python 3.11 support - I'll have to get back to you
danielhanchen commentedon Dec 18, 2023
@alvis233 I made a new branch just for xformers-0.21! It should now be supported! :)
pip install "unsloth[cu118] @ git+https://github.com/unslothai/[email protected]"Your other choice is to install
flash-attnvia the ampere install path:pip install "unsloth[cu118_ampere] @ git+https://github.com/unslothai/unsloth.gitSelect either - maybe option 1 is easier!!
Hope they help!
alvis233 commentedon Dec 18, 2023
Thank you for your help with the installation issues, I managed to install
unslothsuccessfully now, but then I encountered another issue related tobitsandbytes. I noticed that the version ofbitsandbyteswas0.41.0, so I reinstalled it, upgrading to version0.41.3, which resolved the issue. Now everything is working fine. The Python dependencies are quite complex and frustrating. Why not provide arequirements.txtfile to simplify the setup process?danielhanchen commentedon Dec 18, 2023
@alvis233 Great you got it to work! So in fact I have an elaborate dispatching mechanism via
pyproject.tomlwhich is the "new"requirements.txt". The issue is if and else statements to dispatch to which is not allowed as of yet - that would require asetup.py`.Generally the setup process should be smooth, but i guess sometimes not so much.
But glady it works now!! Hopefully Unsloth will make training and everything faster!! If you need any help - join our Discord!! https://discord.gg/u54VK8m8tk
Again hope I was helpful!! (Closing this issue now!)
[-]ValueError: Query/Key/Value should all have BMHK or BMK shape for Mistral 7b[/-][+]Xformers and other dependency errors[/+]Merge pull request unslothai#38 from unslothai/fix/model-config-direc…
Studio sd.cpp: pin the prebuilt resynced with upstream master-1056 (u…