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

Subsequent inference calls produce less good results #33

Closed
steve-barlow opened this issue Apr 15, 2022 · 1 comment
Closed

Subsequent inference calls produce less good results #33

steve-barlow opened this issue Apr 15, 2022 · 1 comment

Comments

@steve-barlow
Copy link

Following the code in README.md or example_inference.py to perform inference by calling model.preprocess_inputs(…) followed by model.generate(…) produces good results the first time the pair is called, but poor results for subsequent pairs of calls.

The reason is that model = Magma.from_checkpoint(…) loads the model with inconsistent training/eval settings. model.training is True but model.image_prefix.enc.training is False. The first call to model.preprocess_inputs(…) works correctly as the image encoder has training False and so its Batch Normalisation steps work correctly. The call to model.generate(…) records the training state on entry and restores it on exit, which because model.training is True puts the whole model into training state. Subsequent calls to model.preprocess_inputs(…) then don't perform Batch Normalisation steps correctly.

The play space at https://huggingface.co/spaces/EleutherAI/magma has this problem too.

The fix is to add model.eval() after model = Magma.from_checkpoint(…), setting the whole model to a consistent eval state.

@Mayukhdeb
Copy link
Contributor

Hi @steve-barlow 👋
Thanks for pointing out this issue -- I've added an eval() here which should fix the problem 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants