Skip to content

RoPE Scaling issues #47

Closed
Closed

Description

@hrhdegenetrix

Hey there,

Worked on this quite a lot yesterday with the help of GPT-4, but I'm having some issues with errors similar to the following:

Traceback (most recent call last):
  File "/mnt/c/Users/magda/OneDrive/Desktop/python_work/unsloth_finetuner.py", line 67, in <module>
    trainer.train()
  File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 1537, in train
    return inner_training_loop(
  File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 1854, in _inner_training_loop
    tr_loss_step = self.training_step(model, inputs)
  File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 2744, in training_step
    self.accelerator.backward(loss)
  File "/home/harry/.local/lib/python3.10/site-packages/accelerate/accelerator.py", line 1903, in backward
    self.scaler.scale(loss).backward(**kwargs)
  File "/home/harry/.local/lib/python3.10/site-packages/torch/_tensor.py", line 492, in backward
    torch.autograd.backward(
  File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/__init__.py", line 251, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/function.py", line 288, in apply
    return user_fn(self, *args)
  File "/home/harry/.local/lib/python3.10/site-packages/torch/utils/checkpoint.py", line 288, in backward
    torch.autograd.backward(outputs_with_grad, args_with_grad)
  File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/__init__.py", line 251, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/function.py", line 288, in apply
    return user_fn(self, *args)
  File "/home/harry/.local/lib/python3.10/site-packages/torch/cuda/amp/autocast_mode.py", line 140, in decorate_bwd
    return bwd(*args, **kwargs)
  File "/home/harry/.local/lib/python3.10/site-packages/unsloth/kernels/fast_lora.py", line 291, in backward
    dX = torch.matmul(dQ, QW.t(), out = X)
RuntimeError: Expected out tensor to have dtype c10::Half, but got float instead

I'm running an RTX 3090 locally, for the record--I want to say CUDA 118. Downgraded Pytorch to 2.1.0 as well. Here's what the script is looking like right now. This is my first time trying to locally finetune, so I'm not sure if the args are wrong, or what, but any advice would be very much appreciated.

from unsloth import FastLlamaModel, FastMistralModel
import torch
max_seq_length = 4096 # Can change to any number <= 4096
HAS_BFLOAT16 = torch.cuda.is_bf16_supported()
dtype = torch.bfloat16 if HAS_BFLOAT16 else torch.float16
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.

# Load Llama model
model, tokenizer = FastLlamaModel.from_pretrained(
    model_name = "unsloth/llama-2-7b", # Supports any llama model eg meta-llama/Llama-2-7b-hf
    max_seq_length = max_seq_length,
    dtype = dtype,
    load_in_4bit = load_in_4bit,
    token = "hf...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)

# Do model patching and add fast LoRA weights
model = FastLlamaModel.get_peft_model(
    model,
    r = 16,
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj",],
    lora_alpha = 16,
    lora_dropout = 0, # Currently only supports dropout = 0
    bias = "none",    # Currently only supports bias = "none"
    use_gradient_checkpointing = True,
    random_state = 3407,
    max_seq_length = max_seq_length,
)

from transformers import Trainer, TrainingArguments
from datasets import load_dataset

dataset = load_dataset('json', data_files='processed_data.json', split='train')
# Tokenize the dataset
def tokenize_and_prepare_labels(examples):
    tokenized_inputs = tokenizer(examples['text'], padding='max_length', truncation=True, max_length=max_seq_length)
    # Shift the tokenized inputs to the right for the labels
    tokenized_inputs["labels"] = tokenized_inputs["input_ids"].copy()
    return tokenized_inputs

tokenized_dataset = dataset.map(tokenize_and_prepare_labels, batched=True)

# Define training arguments
training_args = TrainingArguments(
    output_dir='outputs',          
    num_train_epochs=3,            
    per_device_train_batch_size=8, 
    warmup_steps=500,              
    weight_decay=0.01,             
    logging_dir='./logs',          
    logging_steps=10,
    fp16=True,  # Enable mixed precision
)


# Initialize Trainer with the entire tokenized dataset
trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=tokenized_dataset,
    eval_dataset=None  # Set this to your evaluation dataset if you have one
)


print(f"Max sequence length: {max_seq_length}")
trainer.train()
print(f"Training done! Check outputs")

For the record, when I remove fp16 = True, it errors out a lot faster and gives a slight variation of the error:

RuntimeError: expected mat1 and mat2 to have the same dtype, but got: c10::BFloat16 != float

Activity

  1. danielhanchen commented on Dec 21, 2023

    @danielhanchen
    Member

    @hrhdegenetrix Instead of fp16 = True, since u have a RTX 3090 which supports bfloat16, replace fp16 = True with bf16 = True

  2. hrhdegenetrix commented on Dec 22, 2023

    @hrhdegenetrix
    Author

    @hrhdegenetrix Instead of fp16 = True, since u have a RTX 3090 which supports bfloat16, replace fp16 = True with bf16 = True

    Thank you so much! That helped get me off the ground. Didn't seem to save (at least where I expected it to) but I'll figure that out later today. Before this is marked as close, could I get your help with this assertion error? I tried changing max sequence length to 8192, but wound up with this. Do I need to manually add a RoPE scaling dictionary as you mentioned to another user, or is there something else afoot here? Maybe I should try a different base model?

    Traceback (most recent call last):
      File "/mnt/c/Users/magda/OneDrive/Desktop/python_work/unsloth_finetuner.py", line 69, in <module>
        trainer.train()
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 1537, in train
        return inner_training_loop(
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 1854, in _inner_training_loop
        tr_loss_step = self.training_step(model, inputs)
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 2735, in training_step
        loss = self.compute_loss(model, inputs)
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 2758, in compute_loss
        outputs = model(**inputs)
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/utils/operations.py", line 680, in forward
        return model_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/utils/operations.py", line 668, in __call__
        return convert_to_fp32(self.model_forward(*args, **kwargs))
      File "/home/harry/.local/lib/python3.10/site-packages/torch/amp/autocast_mode.py", line 16, in decorate_autocast
        return func(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 579, in PeftModelForCausalLM_fast_forward
        return self.base_model(
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/peft/tuners/tuners_utils.py", line 103, in forward
        return self.model.forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 521, in LlamaForCausalLM_fast_forward
        outputs = self.model(
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 447, in LlamaModel_fast_forward
        layer_outputs = torch.utils.checkpoint.checkpoint(
      File "/home/harry/.local/lib/python3.10/site-packages/torch/_compile.py", line 24, in inner
        return torch._dynamo.disable(fn, recursive)(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 328, in _fn
        return fn(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/_dynamo/external_utils.py", line 17, in inner
        return fn(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/utils/checkpoint.py", line 451, in checkpoint
        return CheckpointFunction.apply(function, preserve, *args)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/function.py", line 539, in apply
        return super().apply(*args, **kwargs)  # type: ignore[misc]
      File "/home/harry/.local/lib/python3.10/site-packages/torch/utils/checkpoint.py", line 230, in forward
        outputs = run_function(*args)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 443, in custom_forward
        return module(*inputs, past_key_value, output_attentions, padding_mask=padding_mask)
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 305, in LlamaDecoderLayer_fast_forward
        hidden_states, self_attn_weights, present_key_value = self.self_attn(
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 205, in LlamaAttention_fast_forward
        Q, K = fast_rope_embedding(Q, K, cos, sin)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/kernels/rope_embedding.py", line 126, in fast_rope_embedding
        Q = Fast_RoPE_Embedding.apply(Q.transpose(1, 2), cos, sin).transpose(1, 2)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/function.py", line 539, in apply
        return super().apply(*args, **kwargs)  # type: ignore[misc]
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/kernels/rope_embedding.py", line 77, in forward
        assert(seq_len <= cos.shape[0])
    AssertionError
    
  3. danielhanchen commented on Dec 22, 2023

    @danielhanchen
    Member

    @hrhdegenetrix Ok that's weird - when you changed max_seq_length = 8192 did u put this in 2 places? Both in FastLlamaModel.from_pretrained and FastLlamaModel.get_peft_model

    You should get the following warning message:

    Unsloth: unsloth/llama-2-7b can only handle sequence lengths of of most 4096.
    But with kaiokendev's RoPE scaling of 2.0, it can be magically be extended to 8192!
    
  4. hrhdegenetrix commented on Dec 22, 2023

    @hrhdegenetrix
    Author

    @hrhdegenetrix Ok that's weird - when you changed max_seq_length = 8192 did u put this in 2 places? Both in FastLlamaModel.from_pretrained and FastLlamaModel.get_peft_model

    You should get the following warning message:

    Unsloth: unsloth/llama-2-7b can only handle sequence lengths of of most 4096.
    But with kaiokendev's RoPE scaling of 2.0, it can be magically be extended to 8192!
    

    Yeah it's a weird one! It looks like I've got max_seq_length in 2 places for sure. And I do get the warning message, but then I get the traceback like so:

    ==((====))==  Unsloth: Fast Llama patching release 2023.12
       \\   /|    GPU: NVIDIA GeForce RTX 3090. Max memory: 24.0 GB
    O^O/ \_/ \    CUDA compute capability = 8.6
    \        /    Pytorch version: 2.1.0+cu121. CUDA Toolkit = 12.1
     "-____-"     bfloat16 = TRUE. Platform = Linux
    
    Unsloth: unsloth/llama-2-7b can only handle sequence lengths of of most 4096.
    But with kaiokendev's RoPE scaling of 2.0, it can be magically be extended to 8192!
    Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████| 3/3 [00:15<00:00,  5.06s/it]
    Max sequence length: 8192
      0%|                                                                                           | 0/234 [00:00<?, ?it/s]`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...
    Traceback (most recent call last):
      File "/mnt/c/Users/magda/OneDrive/Desktop/python_work/unsloth_finetuner.py", line 69, in <module>
        trainer.train()
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 1537, in train
        return inner_training_loop(
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 1854, in _inner_training_loop
        tr_loss_step = self.training_step(model, inputs)
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 2735, in training_step
        loss = self.compute_loss(model, inputs)
      File "/home/harry/.local/lib/python3.10/site-packages/transformers/trainer.py", line 2758, in compute_loss
        outputs = model(**inputs)
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/utils/operations.py", line 680, in forward
        return model_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/utils/operations.py", line 668, in __call__
        return convert_to_fp32(self.model_forward(*args, **kwargs))
      File "/home/harry/.local/lib/python3.10/site-packages/torch/amp/autocast_mode.py", line 16, in decorate_autocast
        return func(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 579, in PeftModelForCausalLM_fast_forward
        return self.base_model(
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/peft/tuners/tuners_utils.py", line 103, in forward
        return self.model.forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 521, in LlamaForCausalLM_fast_forward
        outputs = self.model(
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 447, in LlamaModel_fast_forward
        layer_outputs = torch.utils.checkpoint.checkpoint(
      File "/home/harry/.local/lib/python3.10/site-packages/torch/_compile.py", line 24, in inner
        return torch._dynamo.disable(fn, recursive)(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 328, in _fn
        return fn(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/_dynamo/external_utils.py", line 17, in inner
        return fn(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/utils/checkpoint.py", line 451, in checkpoint
        return CheckpointFunction.apply(function, preserve, *args)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/function.py", line 539, in apply
        return super().apply(*args, **kwargs)  # type: ignore[misc]
      File "/home/harry/.local/lib/python3.10/site-packages/torch/utils/checkpoint.py", line 230, in forward
        outputs = run_function(*args)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 443, in custom_forward
        return module(*inputs, past_key_value, output_attentions, padding_mask=padding_mask)
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 305, in LlamaDecoderLayer_fast_forward
        hidden_states, self_attn_weights, present_key_value = self.self_attn(
      File "/home/harry/.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/harry/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/accelerate/hooks.py", line 165, in new_forward
        output = module._old_forward(*args, **kwargs)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/models/llama.py", line 205, in LlamaAttention_fast_forward
        Q, K = fast_rope_embedding(Q, K, cos, sin)
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/kernels/rope_embedding.py", line 126, in fast_rope_embedding
        Q = Fast_RoPE_Embedding.apply(Q.transpose(1, 2), cos, sin).transpose(1, 2)
      File "/home/harry/.local/lib/python3.10/site-packages/torch/autograd/function.py", line 539, in apply
        return super().apply(*args, **kwargs)  # type: ignore[misc]
      File "/home/harry/.local/lib/python3.10/site-packages/unsloth/kernels/rope_embedding.py", line 77, in forward
        assert(seq_len <= cos.shape[0])
    AssertionError
      0%|          | 0/234 [00:01<?, ?it/s]
    
  5. danielhanchen commented on Dec 23, 2023

    @danielhanchen
    Member

    @hrhdegenetrix Hmm I'll have to check my code on how I approached RoPE scaling - maybe I did it wrong oops.

    For now, could it be possible for you to just try 4096 for now - I'll update Unsloth in a bit :)

  6. danielhanchen commented on Dec 25, 2023

    @danielhanchen
    Member

    @hrhdegenetrix Sorry on the delay - just updated Unsloth - would it be possible for you to update Unsloth and see if RoPE scaling works now? Thanks so much!

  7. changed the title [-]Float problems?[/-] [+]RoPE Scaling issues[/+] on Dec 25, 2023
  8. hrhdegenetrix commented on Dec 29, 2023

    @hrhdegenetrix
    Author

    @hrhdegenetrix Sorry on the delay - just updated Unsloth - would it be possible for you to update Unsloth and see if RoPE scaling works now? Thanks so much!

    Hey man! Merry Christmas and Happy New Year, thanks for working so hard during the holiday season. So, I updated Unsloth and then just to be sure I ended up doing a clean install of it. 4096 works, but 8192 gets hung up. You can see Map never completed; it just sat here looking like this with the GPU running but nothing happening for around an hour or so:

    ==((====))==  Unsloth: Fast Llama patching release 2023.12
       \\   /|    GPU: NVIDIA GeForce RTX 3090. Max memory: 24.0 GB
    O^O/ \_/ \    CUDA capability = 8.6. Xformers = 0.0.22.post7. FA = True.
    \        /    Pytorch version: 2.1.0+cu121. CUDA Toolkit = 12.1
     "-____-"     bfloat16 = TRUE. Platform = Linux
    
    Unsloth: unsloth/llama-2-7b can only handle sequence lengths of at most 4096.
    But with kaiokendev's RoPE scaling of 2.0, it can be magically be extended to 8192!
    Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████| 3/3 [00:15<00:00,  5.25s/it]
    Unsloth 2023.12 patched 32 layers with 32 QKV layers, 32 O layers and 32 MLP layers.
    Max sequence length: 8192
      0%|                                                                                           | 0/348 [00:00<?, ?it/s]Unsloth: `use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`
    

    No error this time, but no progress beyond this point.

  9. danielhanchen commented on Dec 30, 2023

    @danielhanchen
    Member

    @hrhdegenetrix Hey early HNY! Hmm ok ok hm I'll do more checking - sorry my fixes didn't fix it :(

    I'll have to manaully create some long context datasets and see why Unsloth is getting stuck

  10. danielhanchen commented on Dec 31, 2023

    @danielhanchen
    Member

    So I tried it with max_seq_length=8192 so RoPE Scaling of 2 on Llama-2-7b. I manually editted the Alpaca dataset by ensuring I see 8000 spaces ie, and sampling the first 1% of examples:

    if text.count(" ") < 8000:
                text = text * int(np.ceil(8000 / text.count(" ")))
    

    Running the tokenizer on the first exampl ull get around 13,932 tokens, which is what we want (tokenizer will truncate this).

    I ran the model, and it's super SLOW - the backward pass is notoriously taking loads of time - I'll have to check why, but it seems like the attention layer is the culprit since O(N^2) during the backward pass must really hurt Flash Attention.

    Google Colab showing forward pass:
    image

    And the extremely painstakinly slow backward pass:
    image

    After a horribly 3 minutes and 36 seconds on bsz=2, ga=4, finally 1 step is completed... On 60 steps we need a crazy 3 hours:
    image

    My notebook: https://colab.research.google.com/drive/1TLI18PEeWXYR_4IeOx0wG-NvHYNBxdEW?usp=sharing

  11. added
    fixed - pending confirmation
    on Jan 27, 2024
  12. neru1234 commented on Jul 3, 2024

    @neru1234

    Hi @danielhanchen
    My gpu can't use bf16, but it looks like bf16 supported?

    ==((====))==  Unsloth: Fast Llama patching release 2024.6
       \\   /|    GPU: NVIDIA GeForce RTX 4060 Ti. Max memory: 15.674 GB. Platform = Linux.
    O^O/ \_/ \    Pytorch: 2.3.0. CUDA = 8.9. CUDA Toolkit = 12.1.
    \        /    Bfloat16 = TRUE. Xformers = 0.0.26.post1. FA = False.
     "-____-"     Free Apache license: http://github.com/unslothai/unsloth
    
    +---------------------------------------------------------------------------------------+
    | NVIDIA-SMI 535.113.01             Driver Version: 535.113.01   CUDA Version: 12.2     |
    |-----------------------------------------+----------------------+----------------------+
    | GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
    |                                         |                      |               MIG M. |
    |=========================================+======================+======================|
    |   0  NVIDIA GeForce RTX 4060 Ti     Off | 00000000:01:00.0  On |                  N/A |
    | 49%   63C    P2             151W / 165W |   7718MiB / 16380MiB |    100%      Default |
    |                                         |                      |                  N/A |
    +-----------------------------------------+----------------------+----------------------+
                                                                                             
    +---------------------------------------------------------------------------------------+
    | Processes:                                                                            |
    |  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
    |        ID   ID                                                             Usage      |
    |=======================================================================================|
    |    0   N/A  N/A      1082      G   /usr/lib/xorg/Xorg                          725MiB |
    |    0   N/A  N/A      1457      G   /usr/bin/gnome-shell                        135MiB |
    |    0   N/A  N/A      7372      G   ...seed-version=20240628-130141.777000      334MiB |
    |    0   N/A  N/A      7568      G   clash-verge                                   2MiB |
    |    0   N/A  N/A    130538      G   ...irefox/4483/usr/lib/firefox/firefox       16MiB |
    |    0   N/A  N/A    303763      G   ...sion,SpareRendererForSitePerProcess       92MiB |
    |    0   N/A  N/A    340918      C   python                                     6390MiB |
    +---------------------------------------------------------------------------------------+
    

    error:

      File "/home/shaobozhang/miniconda3/envs/unsloth_env/lib/python3.10/site-packages/unsloth/kernels/fast_lora.py", line 126, in backward
        dX = torch.matmul(df, upW.t(), out = X)
    RuntimeError: Expected out tensor to have dtype c10::BFloat16, but got float instead
    

    Thanks

  13. danielhanchen commented on Jul 4, 2024

    @danielhanchen
    Member

    @neru1234 Set fp16 = True and bf16 = False in the training args

  14. added a commit that references this issue on Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed - pending confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions