Open alex-jw-brooks opened 1 month ago
Seems like a bug indeed, thanks for the great report! cc @Rocketknight1, can you take a look at this?
Confirmed the bug, and thanks for the clean reproduction script! I suspect this is an issue with how we construct the autoclass mappings, I'm working on it now.
Awesome, thank you both! 🙂
After investigation, the issue seems to be here. Manually setting an attribute of the transformers
library like that seems to break other stuff in our imports, and it interacts with the AutoProcessor
import in ways I don't fully understand
Final diagnosis:
transformers
root. As a result, it fails when the image processor class is custom code and not present in the transformers
root._get_arguments_from_pretrained
so that it can handle custom code classes correctly, and then make a PR to the Microsoft repo to remove the line that assigns the class as a root attribute of transformers
.cc @zucchini-nlp - can you see an obvious fix to that method that would work for custom classes? I can take this if you're overloaded!
Hey @Rocketknight1, thanks for investigating this.
The quickest worrkaround I see is to change this line in Microsoft repo to be an AutoImageProcessor
. Just tried it by modifying the code locally, works as expected because the AutoClass
will be importable in any case. I am not sure though that forcing autoclass within our loading code would work in all cases, since some classes can be non-automappable? 🤔
But I agree that we need a better solution here than forcing folks on the hub to use AutoClasses
. I cannot say right now what would be the best option, and yeah would be super cool if you have any ideas for long-term solution 😄
Yeah, that's a really good point! Let me investigate this when I get a chance, maybe I can come up with a (semi-) clean solution.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Any update on this?
System Info
transformers
version: 4.45.2Who can help?
Probably @zucchini-nlp @amyeroberts, and @qubvel
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
There seems to be an edge-case in the loading behavior that can sometimes be hit if something is initialized with
from_pretrained
throughAutoImageProcessor
beforeAutoProcessor
is imported, and thenfrom_pretrained
is used onAutoProcessor
.Repro case - this works as expected
But this breaks:
with
AttributeError: module transformers has no attribute Phi3VImageProcessor
.I've tried to reproduce this with a few other models, but haven't been able to yet. It is also probably worth noting that the
AutoProcessor
doesn't return the same class asAutoImageProcessor
for this model, which might matterExpected behavior
AutoImageProcessor
/AutoProcessor
from_pretrained
should have the same behavior if possible, regardless of import and invocation order