According to the original documentation in the UNQ_C7 task, the
get_gen_loss function should return
a torch scalar loss value for the current batch, meaning that it should be a single value (e.g. 1), not something of higher dimension like (1, 2).
However, looking into method
test_gen_reasonable right below, on line 15, you will see the following assertion
assert tuple(gen_loss_tensor.shape) == (num_images, z_dim)
IIUC, this is completely wrong right? The loss value should be a single scalar number, not 2-dimensional vector or a tensor of higher dimension.
Could someone clarify?
Thanks a lot
You’re right, but the test cells here are playing some pretty sophisticated games. Note that the
criterion function is an argument that is passed to
get_gen_loss, right? The “real” or normal
criterion function returns a scalar value and the return value of
criterion is what
get_gen_loss returns, but in some of the tests they pass a
criterion function that does not return a scalar value and then test for the results.
To understand why that test makes sense and what it’s really testing, you have to carefully study all the arguments that they are passing to
get_gen_loss in each test case.
Also notice that the
disc() functions are arguments that get passed to
get_gen_loss as well and that in some of the test cases they are not passing the real implementations of those functions either.
As Sir Walter Scott once said in a very different context “What a tangled web we weave, when first we practice to deceive …”.
Thanks for your answer. In that case, I really think the course organiser should fix either the comment or the function provided, since it’s so confusing.
Sorry, but I explained the situation. Their comments are completely clear and correct for the real functions that you actually have to write. The test cells play some other more sophisticated games, but you only really need to look at those when they fail. And if you’re going to look there, then you need to think a bit harder to understand what they are doing. It’s actually educational and you will learn some interesting techniques, but that is completely optional and unnecessary to achieving a correct solution to the actual functions you need to write.