Strange Error with C2W2 assignment; 6.3 Mini-Batch with Adam "KeyError: 'dW3'"

When running the “6.3 Mini-Batch with Adam” cell, I get thrown an error: “KeyError: ‘dW3’”.

For reference:

-The error is in Exercise 5: initialize_adam; line 36 (despite passing the grader test for this)
-I have passed all tests up until 6.3

I have solved the issue.

Apparently the grader allows you to initialize with the “grads” dictionary rather than the intended “parameters” dictionary, but only throws an error when running it in cell 6.3.

To clarify for people with the same issue, there is no grad[‘dW3’] so you will get a key error.

parameters[‘dW3’].shape is not equal to grads[‘dW3’].shape

There are a number of different dictionaries in this exercise for different purposes: parameters for the W^{[l]} and b^{[l]} values, grads for the various gradients (dW^{[l]}) and v for velocities. They will be in different dictionaries, but it should be the case that the shape of W3 is the same as the shape of dW3.

I understand @Icely 's and @Mark_Edney 's comments. But how do you solve it? What exactly needs to be changed here?

This should be filed as bug. If I put an assert statement grads == None before the for-loop, it should return True and continue to initialize the dictionaries. Because grads is not supposed to be used (or test passing when used), when we’re finishing the initialize_adam method.

But what if grads is defined as a global variable? Then the assertion will fail. The variable exists, but it is a bug for you to reference it. Note that it is always a mistake to reference global variables from the body of a function in these courses.

1 Like