C1W1_Your_First_GAN - UNQ_C6 - test_disc_reasonable(),test_disc_loss()

The test_disc_reasonable function passes tensor creating methods for gen and disc to the get_disc_loss function while the test_disc_loss function passes a generator and discriminator instance for the same.

How can one piece of code handle both ? Are we supposed to check isinstance of the variables passed and write if else blocks to handle them differently based on their type ?

Thanks in advance

Hi Sumanth,
Welcome to the community :wave:!

I request you to just follow the instructions given to you in the cell. And pls don’t worry about how those test functions are implemented, if you have followed the instructions given in the cell and if your code is logically and syntactically correct, it would pass the test functions.
And yes you have to handle both in GANs, you will first get the generated output (fake) which is the result (return) of the Generator class’s forward function call through the object gen.
You will then pass this to the Discriminator class’s forward function call through the object disc. The steps are clearly mentioned in the cell, please trust and just follow them, no need to write if else blocks separately. If you still feel that you are not clear about what you are trying to do, feel free to post the issue.


I tend to agree… when run the test it fails with

AttributeError: ‘builtin_function_or_method’ object has no attribute 'forward
because gen is not of type Generator.

ok, I solved this, however, while test_disc_reasonable() passes, test_disc_loss() does not.
It fails on the following assert

assert gen.gen[0][0].weight.grad is None

based on the comment “# Check that they detached correctly”, I guess I’m not calling detach at the right place.

Hi Alex!

Please check your implementation,(you are making some mistakes), there is nothing wrong with the test cases.
Kindly, follow the instructions given in the notebook.


I did a bit of research on how detach() works and finally got it.