li-lab-mcgill / singlecell-deepfeature

Single Cell Generative Adversarial Network (scGAN)
13 stars 5 forks source link

TypeError: forward() takes from 2 to 4 positional arguments but 5 were given #1

Open flyboyleo opened 4 years ago

flyboyleo commented 4 years ago

TypeError: forward() takes from 2 to 4 positional arguments but 5 were given

when running: history = trainer.train(n_epochs=150, lr= lr1, eps=eps, disc_lr= lr 1, enc_lr = lr 0.0 ) & history = trainer.train(n_epochs=50, lr= lr1, eps=eps, disc_lr= lr 1, enc_lr = lr 0.05)

in MDDBrianCells_scGAN.py

python 3.8, Ubuntu 20.04LTS, CUDA 10.1, latest Tensorflow and Torch.

yifnzhao commented 4 years ago

I had the same error. There is an inconsistency in the VAE's forward() function (line 146) and how it is called in GANTrainer’s train() function (line 434), in scripts/utils_helper.py.

line 146: def forward(self, x, batch_index=None, y=None) line 434: reconst_loss, kl_divergence, z = self.model(sample_batch, local_l_mean, local_l_var, batch_index) .

In addition, line 434 expects 3 arguments to be returned but the forward() only returns 2 arguments, reconst_loss , kl_divergence (line 166).

yueliyl commented 4 years ago

Sorry for the errors. We will address this shortly. @mojtababahrami1993

mojtababahrami commented 4 years ago

Solved. It was due to some versioning of VAE class.

flyboyleo commented 4 years ago

Thanks, @mojtababahrami1993 and @yueliyl. However, I still met some new errors when running the updated script of MDDBrianCells_scGAN.py:

RuntimeError Traceback (most recent call last) ~/PycharmProjects/scDeepFeature/scripts/MDDBrainCells_scGAN.py in 114 115 # Pretraining --> 116 history = trainer.train(n_epochs=30, lr= lr1, eps=eps, disc_lr= lr 0.0, enc_lr = lr* 0.0 ) 117 118

~/PycharmProjects/scDeepFeature/scripts/utils_helper.py in train(self, n_epochs, lr, eps, params, enc_lr, disc_lr) 488 self.model.zero_grad() 489 reconst_loss, kl_divergence, z = self.model(sample_batch, batch_dis) --> 490 loss = torch.mean(reconst_loss + self.model.kl_weight * kl_divergence) 491 vae_loss_list_epoch.append(loss.item()) 492 loss.backward(retain_graph=True)

RuntimeError: The size of tensor a (33694) must match the size of tensor b (128) at non-singleton dimension 1

Eamonmca commented 2 years ago

Hello, I realise it has been quite some time since this question was asked. I was just wondering has there been any resolution to the issue? I am encountering the same problem.

yueliyl commented 2 years ago

Mojtaba, can you look into this? @mojtababahrami1993

Eamonmca commented 2 years ago

I appreciate your response, I am referring to the "RuntimeError: The size of tensor a (33694) must match the size of tensor b (128) at non-singleton dimension 1" issue specifcally.

mojtababahrami commented 2 years ago

The RuntimeError: The size of tensor ... is due to the new versions of scvi library. Use version scvi==0.4.1

Eamonmca commented 2 years ago

Thank you so much for your reply! I have implemented the fix, can i ask would you by chance have a list of the package versions used as I am still running into issues.

mojtababahrami commented 2 years ago

Yes sure. I will upload a clean requirements.txt file to the project. However, by then, find a little bit messy one attached here which is the output of pip freeze: requirements.txt

Eamonmca commented 2 years ago

Thank you very much for that. The messy version works perfectly thank you. I have unfortunately another issue:

RuntimeError
Traceback (most recent call last)

in 1 # Pretraining ----> 2 history = trainer.train(n_epochs=30, lr= lr*1, eps=eps, disc_lr= lr * 0.0, enc_lr = lr* 0.0 ) 2 frames /usr/local/lib/python3.7/dist-packages/torch/autograd/__init__.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs) 154 Variable._execution_engine.run_backward( 155 tensors, grad_tensors_, retain_graph, create_graph, inputs, --> 156 allow_unreachable=True, accumulate_grad=True) # allow_unreachable flag 157 158 RuntimeError: Found dtype Double but expected Float I am very grateful for your help and apologise for all the questions. I assume it may just be another dependency or versioning issue.
Eamonmca commented 2 years ago

I was actually able to solve the issue myself, was an environment issue on my part. Thanks for your help, it is working as expected now!