-
Notifications
You must be signed in to change notification settings - Fork 29k
RuntimeError when converting and saving Flax ViT model to PyTorch #37999
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
Comments
@nobodyPerfecZ Hey, just wondering, does using the |
I tried using the Code: from transformers import FlaxViTForImageClassification, ViTForImageClassification
# Simulate fine-tuning by loading the base model and saving it
flax_model = FlaxViTForImageClassification.from_pretrained(
pretrained_model_name_or_path="google/vit-base-patch16-224",
num_labels=5,
id2label={
0: "bicycle",
1: "bus",
2: "car",
3: "crosswalk",
4: "hydrant",
},
label2id={
"bicycle": 0,
"bus": 1,
"car": 2,
"crosswalk": 3,
"hydrant": 4,
},
ignore_mismatched_sizes=True,
)
flax_model.save_pretrained("./test-vit-finetuned-patch16-224-recaptchav2")
# Load the fine-tuned model and convert it to PyTorch
pt_model = ViTForImageClassification.from_pretrained(
pretrained_model_name_or_path="./test-vit-finetuned-patch16-224-recaptchav2",
from_flax=True,
)
pt_model.save_pretrained("./test-vit-finetuned-patch16-224-recaptchav2", safe_serialization=False)
# Loading the model again
pt_model = ViTForImageClassification.from_pretrained(
pretrained_model_name_or_path="./test-vit-finetuned-patch16-224-recaptchav2",
) # NotImplementedError Traceback:
|
My workaround would be: Opening a PR and testing if it will be solid enough. |
System Info
Env:
Who can help?
@gante @Rocketknight1
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
Example script to reproduce the bug:
The complete traceback is shown below:
Expected behavior
The converted PyTorch ViT model should be saved/loaded successfully without requiring manual intervention given a Flax ViT model.
The text was updated successfully, but these errors were encountered: