Week3 Lab last 3.3 - Train the Model kept failing even though it seems not requires us write any code

Hello, @biz2024,

From your post, I understand that you had passed all previous tests and you didn’t expect any error from this provided code. However, this provided code used functions that you wrote and if any of them didn’t work perfectly, provided code will crash. There are two possibilities here:

  1. your functions are all correct, but some provided code was somehow altered unintentionally. In this case, you can get a fresh copy and retry. This post shows you how.

  2. some of your functions were not perfect, and unfortunately, the tests were not able to detect them. In this case, we need to understand the origin of the error, and try to sort it out ourselves.

Origin of error

This error happens when there are no valid gradient values for all variables, which you can verify by adding a print like below.

image

With the error, this should show a list of six None. In normal case, they should not be None.

This problem happens when it didn’t use any of the trainable variables to compute the loss. In other words, to avoid this error, you need to make sure all variables are involved in the calculation of the loss.

By the design of the notebook, as your screenshot showed, the variables should go through the path ( 1 → 5 ) and end up as the loss:

Note that this path uses your functions. Your work would be to follow this path and check each of your function to make sure the trainable variables are correctly used, and they and their downstream processed outputs are always processed by tensorflow functions (tensorflow functions start with tf.xxxxx, if you see any np.xxxxx, there is a problem :wink: . tf stands for tensorflow, whereas np stands for numpy. We need to use only tensorflow functions here. )

If you used any np function in the middle of the path, even you started out using the variables correctly, the np function will convert them (or their downstream processed outputs) to something else which means the variables (or their downstream processed outputs) will get kicked out of the remaining steps of the path. We don’t want them to get kicked out, so no np function ever in the path.

Good luck!

Cheers,
Raymond

1 Like