Repository navigation
Description
Other models like llama-3, solar-10.7b don't have this problem. When resuming mistral fine-tuning using "unsloth/mistral-7b-v0.2-bnb-4bit" (trainer_stats = trainer.train(resume_from_checkpoint = True)) i got this error:
Unsloth: Will patch your computer to enable 2x faster free finetuning. ==((====))== Unsloth: Fast Mistral patching release 2024.5 \\ /| GPU: NVIDIA GeForce RTX 3060. Max memory: 11.999 GB. Platform = Linux. O^O/ \_/ \ Pytorch: 2.1.1+cu121. CUDA = 8.6. CUDA Toolkit = 12.1. \ / Bfloat16 = TRUE. Xformers = 0.0.23. FA = True. "-____-" Free Apache license: http://github.com/unslothai/unsloth Unsloth 2024.5 patched 32 layers with 32 QKV layers, 32 O layers and 32 MLP layers. max_steps is given, it will override any value given in num_train_epochs GPU = NVIDIA GeForce RTX 3060. Max memory = 11.999 GB. 4.5 GB of memory reserved. ==((====))== Unsloth - 2x faster free finetuning | Num GPUs = 1 \\ /| Num examples = 52,002 | Num Epochs = 1 O^O/ \_/ \ Batch size per device = 2 | Gradient Accumulation steps = 4 \ / Total batch size = 8 | Total steps = 101 "-____-" Number of trainable parameters = 41,943,040 0%| | 0/101 [00:00<?, ?it/s]Traceback (most recent call last): File "/home/xxxx/test/alpaca_+_mistral_7b_full_example.py", line 164, in <module> trainer_stats = trainer.train(resume_from_checkpoint = True) File "<string>", line 121, in train File "<string>", line 348, in _fast_inner_training_loop File "/home/xxxx/.local/lib/python3.10/site-packages/transformers/trainer.py", line 3238, in training_step loss = self.compute_loss(model, inputs) File "/home/xxxx/.local/lib/python3.10/site-packages/transformers/trainer.py", line 3264, in compute_loss outputs = model(**inputs) File "/home/xxxx/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/accelerate/utils/operations.py", line 822, in forward return model_forward(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/accelerate/utils/operations.py", line 810, in __call__ return convert_to_fp32(self.model_forward(*args, **kwargs)) File "/home/xxxx/.local/lib/python3.10/site-packages/torch/amp/autocast_mode.py", line 16, in decorate_autocast return func(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 883, in PeftModelForCausalLM_fast_forward return self.base_model( File "/home/xxxx/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/peft/tuners/tuners_utils.py", line 179, in forward return self.model.forward(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 166, in new_forward output = module._old_forward(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/unsloth/models/mistral.py", line 213, in MistralForCausalLM_fast_forward outputs = self.model( File "/home/xxxx/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 166, in new_forward output = module._old_forward(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 651, in LlamaModel_fast_forward hidden_states = Unsloth_Offloaded_Gradient_Checkpointer.apply( File "/home/xxxx/.local/lib/python3.10/site-packages/torch/autograd/function.py", line 539, in apply return super().apply(*args, **kwargs) # type: ignore[misc] File "/home/xxxx/.local/lib/python3.10/site-packages/torch/cuda/amp/autocast_mode.py", line 113, in decorate_fwd return fwd(*args, **kwargs) File "/home/xxxx/.local/lib/python3.10/site-packages/unsloth/models/_utils.py", line 383, in forward saved_hidden_states = hidden_states.to("cpu", non_blocking = True) RuntimeError: CUDA error: out of memory CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. Compile withTORCH_USE_CUDA_DSA` to enable device-side assertions.
Activity
danielhanchen commentedon Jun 6, 2024
Oh you're going out of memory
duynt575 commentedon Jun 7, 2024
@danielhanchen I wonder why? With the same dataset, I don't have this problem fine-tuning llama-3 and Solar.
danielhanchen commentedon Jun 9, 2024
@duynt575 To be honest, I'm not sure - interestingly Mistral uses less memory than llama-3 or Solar - are you doing 4bit or 16bit Mistral?
duynt575 commentedon Jun 11, 2024
@danielhanchen I only used 4bit for all fine-tuning because I only have 12GB of vram. I was using same dataset but only mistral gave me that error, strange.
danielhanchen commentedon Jun 11, 2024
Very very weird - do you know if Colab works for your case?
duynt575 commentedon Jun 12, 2024
I don't use Colab so I don't have an answer for that, sorry. I'm using wsl on Windows 10.
duynt575 commentedon Jun 12, 2024
Another note: usually I test fine-tuning by running a few hundred steps to see if it works first. In this mistral case, after saving at 100 steps, when resuming I got that error. And when running, it's much slower than fine-tuning llama-3, like llama-3 got around 8-9 s/it, and mistral got 13-14 s/t.
danielhanchen commentedon Jun 13, 2024
Weird very weird hmmm tbh I'm stumped :(
vladrad commentedon Jun 20, 2024
@danielhanchen ive been trying to get wsl setup to finetune. while it launches ok in windows maybe my dataset is a bit to large. I also get an error on this line...
saved_hidden_states = hidden_states.to("cpu", non_blocking = True)
I think this is due to pinned memory being overfilled. https://docs.nvidia.com/cuda/wsl-user-guide/index.html ....
I have 96 gb ram but for some reason in wsl it shows as 210mb available for pinning and the rest is regular memory.
Pinned system memory (example: System memory that an application makes resident for GPU accesses) availability for applications is limited. ...
For example, some deep learning training workloads, depending on the framework, model and dataset size used, can exceed this limit and may not work.
Im not sure how to go about it... unless there is some env variable that says not to use pinned memory.
danielhanchen commentedon Jun 21, 2024
Oh so for now the workaround is to either use
use_gradient_checkpointing = Trueor changesaved_hidden_states = hidden_states.to("cpu", non_blocking = True)to `saved_hidden_states = hidden_states.to("cpu", non_blocking = False)