question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need help for reproducing linear eval results with published weights.

See original GitHub issue

Hi Mathilde,

I’m porting your models to JAX for further research. I have replicated it so that I get exactly the same outputs (logits, and all intermediates too) when passing the same random input to PyTorch and JAX on the same machine, loading the weights you published for ViT-B/16+linear. (I had to get some details right, like GELU being different between the frameworks.) However, when running full evaluation on ImageNet val using the JAX model, I’m getting 77.73% (resize=bilinear) or 77.548% (resize=bicubic), when I think I should get 78.162 according to these eval logs.

Thus, AFAICT, the only possible remaining causes for difference would be (1) before the model, i.e. preprocessing of images, or (2) after the model, i.e. computation of score, or (3) something not matching on your side.

For (1), I read the code and believe I’m doing the same, including setting resize mode to bicubic and antialias=False. However, it is TF resize, so that may make a difference. image

(2) is trivial, I’m sure I got it right.

(3) I don’t have ImageNet for PyTorch at hand and it would take me a while to get it.

Could you please double-check the number with your published weights and code for me? And do you have any more ideas, or would you ascribe it to different framework’s resize functions at this point?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

4reactions
lucasb-eyercommented, Oct 27, 2021

Confirming that with these fixes, both frameworks produce almost the same images, and I do get 78.02% with that model, it’s still 0.1% too low, but that’s a diff that I can believe comes from slightly different resize. The initial diff of 0.5 was way too large for that.

This is now close enough that I don’t feel I’ll mis-represent the DINO model and can continue with a clear conscience.

Thanks for being my 🦆

image

2reactions
lucasb-eyercommented, Oct 26, 2021

oh, shoot! Two differences in resize:

  • in Torchvision, Resize(256) means “small side 256, keep aspect ratio”. In my code, Resize(256) is a shortcut for Resize((256, 256)), and I just assumed it to be that way in PyTorch. Ugh.
  • in Torchvision, depending where in the pipeline you put ToTensor, it invokes either PIL or Torch’s resize. In the order used here, it will use PIL, which actually always uses antialias=True, no matter what option was set.

Will check with those two changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Get Reproducible Results with Keras
How to Get Reproducible Results from Neural Networks with Keras ... If you need help setting up your Python environment, see this post:....
Read more >
5 – Reproducibility – Machine Learning Blog | ML@CMU
Reproducing a study is a common practice for most researchers as this can help confirm research findings, get inspiration from others' work, ...
Read more >
Weighted Genomic Best Linear Unbiased Prediction for ...
At present, the Hanwoo breeding program considers the estimated breeding values for carcass traits, such as backfat thickness (BFT), carcass ...
Read more >
Batch normalization in 3 levels of understanding
BN relies on batch first and second statistical moments (mean and variance) to normalize hidden layers activations. The output values are then ...
Read more >
Fitting Linear Mixed-Effects Models using lme4
Keywords: sparse matrix methods, linear mixed models, penalized least squares, Cholesky decomposition. A version of this manuscript has been published online in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found