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.

RuntimeError for LearnedMixin on MNIST

See original GitHub issue

Hello, I’m trying to run your LearnedMixin implementation on MNIST but I’m getting the following error:

[2021-07-03 06:58:30] start training
Traceback (most recent call last):
  File "", line 138, in <module>
  File "/home/barbano/.pyenv/versions/rebias/lib/python3.7/site-packages/fire/", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/barbano/.pyenv/versions/rebias/lib/python3.7/site-packages/fire/", line 471, in _Fire
  File "/home/barbano/.pyenv/versions/rebias/lib/python3.7/site-packages/fire/", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "", line 134, in main
  File "/home/barbano/rebias/", line 390, in train
    self._train_epoch(tr_loader, cur_epoch)
  File "/home/barbano/rebias/", line 362, in _train_epoch
    self._update_f(x, labels, loss_dict=loss_dict, prefix='train__')
  File "/home/barbano/rebias/", line 340, in _update_f
    _f_loss_indep = self.outer_criterion(f_feats, _g_feats, labels=labels, f_pred=preds)
  File "/home/barbano/.pyenv/versions/rebias/lib/python3.7/site-packages/torch/nn/modules/", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/barbano/rebias/criterions/", line 92, in forward
    loss = F.cross_entropy(f_pred+g_pred, labels)
RuntimeError: The size of tensor a (10) must match the size of tensor b (128) at non-singleton dimension 1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

SanghyukChuncommented, Jul 6, 2021

@carloalbertobarbano This issue is resolved by #10 I tested that ReBias works well by the following command

python --root /home/data --train_correlation 0.99 --optim AdamP

I have confirmed that ReBias unbiased accuracy is 90.11% with AdamP at rho=0.99, where my previous result was 89.60% (average over three different runs)

[2021-07-04 15:11:35] state dict is saved to ./checkpoints/last.pth, metadata: {'cur_epoch': 80, 'best_acc': 0.9011, 'scores': {'biased': {'f_acc': 1.0, 'g_0_acc': 0.9999, 'outer_0_loss': 2.9878953809384255e-05, 'inner_0_loss': -2.9878953809384255e-05}, 'rho0': {'f_acc': 0.8895, 'g_0_acc': 0.0098, 'outer_0_loss': 6.879471498859857e-06, 'inner_0_loss': -6.879471498859857e-06}, 'unbiased': {'f_acc': 0.9011, 'g_0_acc': 0.1088, 'outer_0_loss': 6.648345147550571e-06, 'inner_0_loss': -6.648345147550571e-06}}}

If you have any other questions, please don’t hesitate to bother me

SanghyukChuncommented, Jul 4, 2021

@carloalbertobarbano I just found that the interface of outer_criterion is wrong.

                _g_preds, _g_feats = g_net(x)

                _f_loss_indep = self.outer_criterion(f_feats, _g_feats, labels=labels, f_pred=preds)
                f_loss_indep += _f_loss_indep

Learned Mixin + H does not use features, but only predictions. I have to update outer_criterion interface to get g_pred as an argument. I will revise this in a few days.

Until then, please change the code.

                _f_loss_indep = self.outer_criterion(f_feats, _g_feats, labels=labels, f_pred=preds)


                _f_loss_indep = self.outer_criterion(f_feats, _g_preds, labels=labels, f_pred=preds)

for LearnedMixin + H.

It is very strange because all arguments and all numbers are verified before I release the code. Sorry for the inconvenience, and thanks for reporting the bug

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError when selecting 0s and 1s from MNIST dataset ...
I am following a guide to build a model to classify between only 0s and 1s from the MNIST dataset. However, what they...
Read more >
arXiv:1909.03683v1 [cs.CL] 9 Sep 2019
In practice, we ignore the p(c) factor because, on our datasets, either the classes are uniformly distributed (MNLI), the bias-only model cannot.
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 Post

No results found

github_iconTop Related Hashnode Post

No results found