GANLearner Error No Implementation Found on types that implement InvisibleTensor

Hello everyone,

I started to implement a simple GAN project, however I am getting the following error:

no implementation found for 'torch.tensor.__rsub__' on types that implement __torch_function__: [<class 'fastai.vision.gan.InvisibleTensor'>, <class 'fastai.torch_core.TensorImage'>]

I am uncertain if this is related to the issue on github.

I tested already different fastai versions, such as the current one from github. I tested the attached code on my local machine as well as on google colab. The attached file also includes the full stack trace as well as implementation details. I also tried to update pytorch via !pip install -U torch torchvision.
gan_test.pdf (88.9 KB)

I would appreciate your help (also because it will be a secret Santa project :slight_smile: )

Hi Jens, I am having the same issue. Have you found a solution? I will be very interested in the solution. Thank you.

no, unfortunately not yet

@hagarciapinto
If found a solution. I found out that the issue is actually related to a different issue.

However, I had trouble on downgrading the version due to a missing log_args.
As suggested in another issue one can downgrade via

pip install "fastai<2.1"
pip install "fastcore==1.3.2"

and then everything works again :).

2 Likes

Hi @scribbler, thank you for the update.

It seems that this solution works for fastai V1.

Do you know if there is a solution for fastai V2?

His solution is for v2, as it installs a fastai higher than 1.x.x (2.0.9 or something like that). V2 was merged into fastai a few months back.

1 Like

I guess you are both right. It worked on my local machine, but not in Colab, it installed actually V1.
Sorry, I forgot to check for Colab.

But it will work with

!pip install "fastcore==1.3.2"
!pip install "fastai>2,<2.1"

I think the problem is that Colab uses the pre-installed version, which is actually V1.

With

import fastai
import torch
import fastcore
print(fastai.__version__, torch.__version__, fastcore.__version__)

I get the following versions on Colab and the above pip install:
2.0.19 1.6.0 1.3.2.
@hagarciapinto I hope this helps.

4 Likes

Thank you, @scribbler and @muellerzr. My notebook in colab is up and running now =)

1 Like

The other solution to any of these that I’ve been doing is casting to a TensorBase. For instance:

ce = nn.CrossEntropyLoss()

def _contiguous(x): return TensorBase(x.transpose(-1,-1).contiguous())
def calc_loss(criterion, x, y):
  x,y = map(_contiguous, (x,y))
  return criterion(x,y)

fastai's BaseLoss class will do this, but this is needed if you don’t want to use that and instead just use raw pytorch by itself for the loss in these instances where x and y aren’t the same type

I’m also trying to run a simple GANs notebook in google colab.

Running

!pip install "fastcore==1.3.2"
!pip install "fastai>2,<2.1"

solves the InvisibleTensor problem for me, but then the GPU is no longer available.

I tried combining it with the light-the-torch solution shown here by running:

!pip install light-the-torch >> /.tmp
!ltt install torch torchvision >> /.tmp
!pip install "fastcore==1.3.2" >> /.tmp
!pip install "fastai>2,<2.1" >> /.tmp

but the GPU is still unavailable.

Should I just not downgrade, and try casting to TensorBase? Also, how to go about that because just casting to TensorBase instead of to InvisibleTensor seems to fail as well.

Just to be sure you enabled the GPU in your runtime settings?

@muellerzr Yeah lol. It’s also definitely been warning me over and over that I’ve got the GPU enabled, but it isn’t being utilized.

You need to downgrade the torch version you’re using as well I think.

1 Like

I tried to downgrade to what people seem to have about. Still doesn’t seem to work.

print(fastai.__version__, torch.__version__, fastcore.__version__)
2.0.19 1.6.0 1.3.2

It keeps saying the Nvidia driver I have is too old for this version of pytorch, but the driver and torch version apparently match on the torch website.

@muellerzr @scribbler Thanks for the help, actually worked after combining it all with the ltt install.

!pip install light-the-torch >> /.tmp
!ltt install "torch==1.6.0" "torchvision==0.7.0" >> /.tmp
!pip install "fastcore==1.3.2" >> /.tmp
!pip install "fastai>2,<2.1" >> /.tmp

1 Like

Just in case anyone else is as slow as me and finds this thread later:

The solutions in this thread initially didn’t appear to work for me because I wasn’t able to fully grasp them at first. But what did work was to apply @muellerzr’s _contiguous re-casting idea to the .forward() of my critic model (which was, in retrospect, what he was recommending for general use cases). As in the following:

class MyCritic(nn.Module):
    def __init__(self, im_chan=3, hidden_dim=64):
        super(MyCritic, self).__init__()
        self.crit = nn.Sequential(
          ...stuff....
          )
    def forward(self, x):
        x = TensorBase(x.transpose(-1,-1).contiguous())
        return self.crit(x)

my_critic = MyCritic(im_chan=3, hidden_dim=64)
(my_generator was already working fine)

learn = GANLearner.wgan(dls, my_generator, my_critic, crit_loss_func=calc_loss, opt_func=partial(Adam, mom=0.))

…problem solved! No more InvisibleTensor errors!

1 Like