Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundError when using SentenceTransformerTrainingArguments(load_best_model_at_end=True) and Peft #3056

Open
GTimothee opened this issue Nov 14, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@GTimothee
Copy link

GTimothee commented Nov 14, 2024

When I try to train a peft model with the load_best_model_at_end=True option enabled, it crashes, raising a FileNotFoundError.

Here is the example code as a gist: gist

Error I get: FileNotFoundError: [Errno 2] No such file or directory: 'training_trial/checkpoint-250/pytorch_model.bin'

@tomaarsen tomaarsen added bug Something isn't working good first issue Good for newcomers labels Nov 14, 2024
@GTimothee
Copy link
Author

GTimothee commented Nov 14, 2024

Here you go #3057

Edit: from what I understand, the issue is the following; there is a function in transformers that checks if the model is a PeftMixedModel or not. If not, it is not considered a peft model and the trainer tries to load the model as usual. The problem is our model is a PeftAdapterMixin so it is not recognized as a peft model.

Edit2: The fix is just a temporary fix to remove the error, as we probably need to update transformers directly. So the fix I did is just to check if the model has adapters on it (is a PeftAdapterMixin)

Edit3: I figured out it probably does not work then lol, I need to check if there are some adapters on it instead. Will do.

Edit4: Found a way to find if there is at least one adapter, so it should work now

Edit5: Tried it with and without adapter, it works

Edit6: I added a little warning so that the user can actually see the log: /usr/local/lib/python3.10/dist-packages/transformers/trainer.py:2601: UserWarning: Could not load best model, as the model has at least one adapter set. Please wait for an update of the transformers library to enable this feature. self._load_best_model()

@GTimothee
Copy link
Author

opened a ticket in transformers to request the change huggingface/transformers#34747

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants