FIX Loading with AutoPeftModel.from_pretrained #1449
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1430
When Using
AutoPeftModel.from_pretrained
, there is a check to see if a tokenizer can be found. This check will include a search for the tokenizer on HF Hub. However, when the model is stored locally, the path may not be a valid HF Hub repo ID. In that case, an error is raised byhuggingface_hub
.This PR consists of catching that error, and assuming that if the error occurs, the tokenizer does not exist. This resolves the issue.
Note
We do have tests for
AutoPeftModel.from_pretrained
, so why did they not catch the error? I think there was a mistake in the tests. The tests did something like this:As you can see, the model is loaded twice from the hub. I think the intent was that the 2nd time around, it should be loaded from the temporary directory (otherwise, why save it there?). I thus changed all the tests to load the model from the temporary directory. This way, the bug is triggered and the bug fix makes the tests pass again.
Please let me know if I misinterpreted the intent of the tests, then I will revert them and add a new test instead.