Skip to content

Any plans to support phi-2 finetuning? #85

Closed

Description

@asmith26

Hi there,

Just thought I'd ask if there were any plans to support phi-2 finetuning, https://huggingface.co/microsoft/phi-2?

Many thanks for any help, and this amazing lib!

Activity

  1. danielhanchen commented on Jan 12, 2024

    @danielhanchen
    Member

    @asmith26 On it! :)

  2. Imran-tech-lab commented on Jan 14, 2024

    @Imran-tech-lab

    Hi there,

    Just thought I'd ask if there were any plans to support phi-2 finetuning, https://huggingface.co/microsoft/phi-2?

    Many thanks for any help, and this amazing lib!

    I tried, fine tuning of phi-2. Which is not good.
    I just use hugging face transformer code not with unsloth..

  3. danielhanchen commented on Jan 15, 2024

    @danielhanchen
    Member

    @imrankh46 Ye smaller models can sometimes not follow instructions well. Could you approx give an example maybe to show Phi not following instructions?

  4. Imran-tech-lab commented on Jan 15, 2024

    @Imran-tech-lab

    @imrankh46 Ye smaller models can sometimes not follow instructions well. Could you approx give an example maybe to show Phi not following instructions?

    here is the code.

    https://colab.research.google.com/drive/1a7rL3UzWfo5I7OPyVmTEnR6_tRqIOblg?usp=sharing

  5. cm2435 commented on Jan 16, 2024

    @cm2435
    Contributor

    @danielhanchen I'm also interesting in contributing this, let me know if you have space on your PR for another helping hand.

  6. danielhanchen commented on Jan 16, 2024

    @danielhanchen
    Member

    @cm2435 Oh more than happy to collab if you're into it!! I actually took a look at Phi the other day:

    1. Phi seems to not use swiglu but just general f(gate) @ down. Swiglu is (f(gate) * up) @ down. This does mean the Triton kernels backprop has to be derived.
    2. Phi is using gelu instead of swish, and I think the first step is to derive the gradient for gelu. Gelu is f(x) = 0.5 * x* (1.0 + torch.tanh(math.sqrt(2.0 / math.pi) * (x+ 0.044715 * torch.pow(x, 3.0)))) Maybe using Desmos / hand derived
    3. Phi uses a general Layernom, not a RMS Layernorm this means again new kernels have to be written - although I think Triton's tutorials has this already done for us: https://triton-lang.org/main/getting-started/tutorials/05-layer-norm.html
    4. There is some dropout (0.1) after each attention and MLP module I think. This shouldn't be hard to implement hopefully.
    5. I don't know what partial_rotary_factor is in https://huggingface.co/microsoft/phi-2/blob/main/config.json. Need to investigate.

    In general Phi is possible, just there are a few blockers - esp (2) and (3). But again - if you want to take a crack at this @cm2435 - I'll be super grateful + I'll collab with you! :) Possibly taking a stab at some steps like (2) finding the derivative might be better as a first step :)

  7. cm2435 commented on Jan 18, 2024

    @cm2435
    Contributor

    @danielhanchen Started a fork and opened a staging PR to work off. I can start by adding some unit test coverage around the kernels if we need to test their accuracy, something simple like

    assert torch.allclose(triton_out, torch_out)

    or I can try to contribute some of the other steps you mentioned- what's your preference?

  8. added
    currently fixing
    on roadmap
    on Jan 27, 2024
  9. danielhanchen commented on Jan 27, 2024

    @danielhanchen
    Member

    @cm2435 Oh lmao just noticed i never responded on this thread WHOOPS! Well I responded on your other threads already I guess - sorry!!!

  10. asmith26 commented on Jun 20, 2024

    @asmith26
    Author

    I thought I'd close this as there are already some fantastic notebooks for finetuning phi-3 (many thanks!)

  11. 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

    currently fixingon roadmap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions