Skip to content

SyntaxError when patching SFTTrainer in tokenizer_utils.py #1700

Closed

Description

@kkailaasa

While attempting to use Unsloth for faster finetuning, encountered a SyntaxError during the patching process of the SFTTrainer.

Environment
Python Version: 3.11 (Colab)
Unsloth Version: main

🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!

SyntaxError: invalid syntax (<string>, line 4)

Full traceback:
RuntimeError                              Traceback (most recent call last)
/usr/local/lib/python3.11/dist-packages/unsloth/tokenizer_utils.py in <module>
   1060     try:
-> 1061         exec(trainer_text, globals())
   1062     except:
-> 1063         raise RuntimeError(f"Unsloth: Please file a bug report! Error patching {trainer_name}")
   1064     exec(f"trl.trainer.{trainer_name} = Unsloth{trainer_name}", globals())
   1065 pass

RuntimeError: Unsloth: Please file a bug report! Error patching SFTTrainer

Activity

  1. ChagoLB commented on Feb 13, 2025

    @ChagoLB

    This issue is being discussed in #1698 and #1699, the solutions in those issues worked for me at least!

  2. QiangGeCode commented on Feb 13, 2025

    @QiangGeCode

    @ChagoLB Thanks, it works! it cost me 2 hours to install/reinstall/uninstall packages, until I find this post!

  3. andresgr96 commented on Feb 13, 2025

    @andresgr96

    Using an older version of trl solved it for me:

    !pip install unsloth
    !pip install "trl<0.15.0"

  4. ChagoLB commented on Feb 13, 2025

    @ChagoLB

    @ChagoLB Thanks, it works! it cost me 2 hours to install/reinstall/uninstall packages, until I find this post!

    Glad it worked for you too! i was in the same situation earlier this week, happy it all worked out

  5. danielhanchen commented on Feb 13, 2025

    @danielhanchen
    Member

    Working on a fix asap!

  6. danielhanchen commented on Feb 13, 2025

    @danielhanchen
    Member

    Just fixed - for now please use TRL < 0.15.0 - I updated all notebooks as well - so refresh them if you're using them. Ie do:

    pip uninstall trl -y && pip install --no-cache-dir --force-reinstall --no-deps "trl<0.15.0"

    I'm still trying to work on supporting the latest TRL 0.15.0, so it'll take a bit more time.

    For GRPO runs, please use "unsloth==2025.2.4" so pip install "unsloth==2025.2.4"

    Using pip install unsloth should work since it'll use an old TRL version

  7. added
    fixed - pending confirmation
    and removed
    currently fixing
    on Feb 13, 2025
  8. andresgr96 commented on Feb 13, 2025

    @andresgr96

    Hey @danielhanchen , so I finetuned a model while you fixed it using the fix I commented, but when uploading the gguf versión to HF I got an error because Unslot couldn't find llamacpp/quantize or llamacpp/llama-quantize.

    I fixed it by manually changing the save.py (or whatever file has the check for those two paths) to point to the folder with the same name in the examples folder of llamacpp.

    I'm not sure if this is relevant for you, but in guessing that using that older version of tlr somehow broke this.

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