Skip to content

Paged_adam8_bit has casting issues #26

Closed

Description

@qy1026

An RuntimeError would occur when I use unsloth to qlora-fintune vicuna-7b-v1.5, which refers to the following lines:

dX = torch.matmul(DW_f, upW.t(), out = X)

dX = torch.matmul(dQ, QW.t(), out = X)

And I modified the line 163 from dX = torch.matmul(DW_f, upW.t(), out = X) to dX = torch.matmul(DW_f, upW.t()).to(X.dtype) ; the line 291 from dX = torch.matmul(dQ, QW.t(), out = X) to dX = torch.matmul(dQ, QW.t()).to(X.dtype)

The RuntimeError would be fixed.

Activity

  1. danielhanchen commented on Dec 11, 2023

    @danielhanchen
    Member

    @qy1026 oh are u using torch.cuda.amp.autocast? So in HF's trainer did u pass in either fp16 = True or bf16 = True (if it supports it)

    You can do that, except memory usage might balloon a bit. If it works, then thats good.

  2. discordianbelle commented on Dec 15, 2023

    @discordianbelle

    I'm a little less code inclined, and I'm struggling with this. I put together a Colab, and If I pass fp16=True or not I get this same error.

    If I wanted to implement this fix myself and use it in Colab, would I have to fork the repo and clone my fork?

  3. danielhanchen commented on Dec 15, 2023

    @danielhanchen
    Member

    @discordianbelle let me try out vicuna-7b-v1.5 to see if I can reproduce the error. If I can, I'll push a fix, and it should be fixed by tomorrow!

  4. qy1026 commented on Dec 15, 2023

    @qy1026
    Author

    @qy1026 oh are u using torch.cuda.amp.autocast? So in HF's trainer did u pass in either fp16 = True or bf16 = True (if it supports it)

    You can do that, except memory usage might balloon a bit. If it works, then thats good.

    I've already used dtype=torch.float16 in FastLlamaModel.from_pretrained() function.

  5. danielhanchen commented on Dec 15, 2023

    @danielhanchen
    Member
  6. discordianbelle commented on Dec 15, 2023

    @discordianbelle

    That worked! The only potentially relevant difference in our code I could see (with untrained eyes) is that I was using the "paged_adamw_8bit" optimizer from a prior qlora notebook, and you used the "adamw_8bit" optimizer. I assume that was the issue,

    Thank you so much!

  7. danielhanchen commented on Dec 15, 2023

    @danielhanchen
    Member

    @discordianbelle oh wait thats weird - let me check up on paged_adamw_8bit - all optimizers should work - so I'll get back to you.

  8. changed the title [-]RuntimeError: expected out tensor to have dtyoe c10::Half, but got float instead[/-] [+]Paged_adam8_bit has casting issues[/+] on Dec 15, 2023
  9. danielhanchen commented on Dec 16, 2023

    @danielhanchen
    Member

    Ok that's very weird - I just tried paged_adamw_8bit an it seems to work? Could the issue maybe be fixed after updating Unsloth?

  10. danielhanchen commented on Dec 25, 2023

    @danielhanchen
    Member

    Closing now since paged_adamw_8bit works fine on my trials

  11. added a commit that references this issue on Jun 8, 2025
  12. added a commit that references this issue on Jun 25, 2025
  13. added a commit that references this issue on Jul 7, 2025
  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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions