Deep Learning Specialization Programming assignment download Unit Tests fails in Local

Hello,

I completed Deep Learning Specialization courses. Then downloaded the Jupyter Notebooks of Programming assignments. They all were passed 100% in Coursera jupyter server site. When I run the “Sequence Models: Week 4 Assignment 1 (Transformers)” in my local Jupyter lab environment the unit test “EncoderLayer_test” fails. Is there any reason, it would fail in my local environment v/s Coursera environment.
I am using latest version of Tensorflow (2.11.0) etc. in local environment.

comparing to 'encoded' fails in local environment:  **tf.Tensor(**
**[[[ 0.41425663 -1.287347    1.3825846  -0.509494 ]**
**  [-1.2822112  -0.35399127  1.485949    0.1502535 ]**
**  [ 1.0478418  -1.2993164  -0.6430867   0.89456135]]], shape=(1, 3, 4), dtype=float32)**
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[18], line 2
      1 # UNIT TEST
----> 2 EncoderLayer_test(EncoderLayer)

File C:\Prashant\AI\Coursera\DeepLearning\C5 - Sequence Models\Files\W4A1\public_tests.py:92, in EncoderLayer_test(target)
     89 assert tuple(tf.shape(encoded).numpy()) == (1, q.shape[1], q.shape[2]), f"Wrong shape. We expected ((1, {q.shape[1]}, {q.shape[2]}))"
     91 print("comparing to 'encoded' fails in local environment: ", encoded)
---> 92 assert np.allclose(encoded.numpy(), 
     **93                    [[ 0.23017104, -0.98100424, -0.78707516,  1.5379084 ],**
**     94                    [-1.2280797 ,  0.76477575, -0.7169283 ,  1.1802323 ],**
**     95                    [ 0.14880152, -0.48318022, -1.1908402 ,  1.5252188 ]]), "Wrong values when training=True"**
     97 encoded = encoder_layer1(q, False, np.array([[1, 1, 0]]))
     98 assert np.allclose(encoded.numpy(), [[ 0.5167701 , -0.92981905, -0.9731106 ,  1.3861597 ],
     99                        [-1.120878  ,  1.0826552 , -0.8671041 ,  0.905327  ],
    100                        [ 0.28154755, -0.3661362 , -1.3330412 ,  1.4176297 ]]), "Wrong values when training=False"

AssertionError: Wrong values when training=True

Thanks & Regards,
Prashant Mahajan

Coursera Labs does not use the latest version of TensorFlow or Keras.

Hi TMosh,

Yes, I know - Coursera Labs uses Tensorflow version 2.4 - which is not available anymore. Tensorflow is now available in versions >=2.5.

My issue is to know all of following:

  1. What would cause the test failures of labs code with Tensorflow version 2.11, while the same tests pass for the same labs code with Tensorflow version 2.4?
  2. If I run the code in the labs with few minor changes with latest version of Tensorflow, and then the tests fail, how would I know what I have changed in code is right or wrong?
  3. Is it necessary for the tests to pass to learn the subject in the labs using latest version of Tensorflow?
  4. How would you recommend to amend the test cases while using latest version of Tensorflow?

Thanks for your reply.

Regards,
Prashant Mahajan

There are several Forum posts about how to use the lab notebooks on other platforms.

Try this as a starting point:

Besides Tom’s suggestion, if you really want to find out what makes the difference, then I am afraid you will need to make comparisons step-by-step, and see at which step of the notebook, the results start to be different.

However, one quick thing I would check is whether they the NNs initialize to the same set of weights, because different initialization leads to different results.

Also, you may want to read the change log of tensorflow and see if there is any major changes that can affect you…

Raymond