# W3A1: Problems that I encountered due to public\_tests.backward\_propagation\_test

**URL:** <https://community.deeplearning.ai/t/w3a1-problems-that-i-encountered-due-to-public-tests-backward-propagation-test/893027>\
**Category:** Neural Networks and Deep Learning\
**Tags:** week-module-3, assignment, coursera-platform\
**Created:** [June 22, 2026, 8:08pm UTC](https://community.deeplearning.ai/t/w3a1-problems-that-i-encountered-due-to-public-tests-backward-propagation-test/893027 "2026-06-22T20:08:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shriesh\_Kumar](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/shriesh_kumar/32/126194_2.png) [@Shriesh\_Kumar](https://community.deeplearning.ai/u/Shriesh_Kumar)\
**Post date:** [June 22, 2026, 8:08pm UTC](https://community.deeplearning.ai/t/w3a1-problems-that-i-encountered-due-to-public-tests-backward-propagation-test/893027/1 "2026-06-22T20:08:09Z")

</div>

In the assignment, the function used to test the implemented `backward_propagation` function in Exercise 6 is `backward_propagation_test` in the `public_tests.py` file. I encountered the error `AssertionError: Wrong values for dW1`, even after several correct indications like my implemented code matching the formulas in the slide, my output being the same as expected output and all the code cells after executing perfectly, matching their expected output too. I downloaded the workspace and inspected that file, and I want to address these two things I noticed:

1. The main problem was the predefined `expected_output` dictionary. I inspected the values by slightly modifying that function in my local environment and found out that the values in the arrays _dW1_ and _db1_ were way off from those present in `grads` returned by the learner’s implementated function, enough that the assertion using `np.allclose` would fail (although _dW2_ and _db2_ were fine). It would be really appreciated if the values were checked once, it is probably some minor calculation issue as _dW2_ and _db2_ are fine.
2. This is more on the conceptual side. I noticed in the same `backward_propagation_test` function, a test value of parameters _W_ and _b_ of both layers were randomly generated; clearly understandable as they would be used to verify further calculations. But the `cache` values (_A_ and _Z_ for both layers) were also being generated randomly. Shouldn’t these values be calculated from the already initialized _W_’s and _b_’s, and then passed into `target` /`backward_propagation` ? My reasoning being the gradient has to be taken out at a particular point defined by the current state of values in `parameters` and the input _X_, which also determine the values of `cache` at that instant. So this random generation of the `cache` values caught my eye.

I have attached some relevant screenshots, particularly for the first issue. Thank you for having a look.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/9/d/9d94b6c25b976c31a8d28aaf3788cc66e6ea20f9.png)

 ![image](https://global.discourse-cdn.com/dlai/original/3X/1/3/13f112ed625669432d868b4a54fdb5ac27865156.png)

 ![image](https://global.discourse-cdn.com/dlai/original/3X/7/8/78230dd592140b4ab6dc90dbfbf3511f017fccbd.png)

 ![image](https://global.discourse-cdn.com/dlai/original/3X/8/2/829d6a7afecbd5d77d7fed45ce0f65164967a910.png)

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [June 22, 2026, 9:08pm UTC](https://community.deeplearning.ai/t/w3a1-problems-that-i-encountered-due-to-public-tests-backward-propagation-test/893027/2 "2026-06-22T21:08:22Z")

</div>

> [@Shriesh\_Kumar](#):
>
> 1. But the `cache` values (_A_ and _Z_ for both layers) were also being generated randomly. Shouldn’t these values be calculated from the already initialized _W_’s and _b_’s, and then passed into `target` /`backward_propagation` ? My reasoning being the gradient has to be taken out at a particular point defined by the current state of values in `parameters` and the input _X_, which also determine the values of `cache` at that instant. So this random generation of the `cache` values caught my eye.

Thanks for your careful analysis of what is happening here. Yes, you’re right that the test case here is a bit sketchy. This issue has been known for a long time: [here’s a thread](https://community.deeplearning.ai/t/w3-a1-ex-6-backward-propagation-assertionerror-wrong-values-for-dw1/66727) about it from November 2021. I filed a bug about this in March 2023, but the course staff has decided that it is low priority enough that they have not done anything about it yet. Note that they literally wrote out the correct code for g^{[1]'}(Z^{[1]}) for you in the instructions. See the “Tips” section right before the function:

 ![Screenshot 2026-06-22 at 2.05.15 PM](https://global.discourse-cdn.com/dlai/original/3X/b/1/b1c24923ec9fd105d8c2fbe88e8b44cb8901be1f.jpeg)

If you instead implement it as:

`(1 - np.tanh(Z1)**2)`

then it passes the first visible test in the notebook, but it fails the one you pointed out that is imported because in that test case it is not true that:

`A1 = np.tanh(Z1)`

because they just randomly generated `A1` and `Z1`.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [June 22, 2026, 11:33pm UTC](https://community.deeplearning.ai/t/w3a1-problems-that-i-encountered-due-to-public-tests-backward-propagation-test/893027/3 "2026-06-22T23:33:16Z")

</div>

One other interesting note in following up on this:

I checked in the new version of DLS that is now on the DeepLearning.AI Learning Platform (as opposed to Coursera) and there they have fixed the grader so that it will accept the mathematically correct version of the implementation of `dZ1` that uses `(1 - np.tanh(Z1)**2)` as the derivative term. Interestingly they didn’t change the `backward_propagation_test` logic to fix the incorrect test case there, so you still fail the test in the notebook with the alternate (but mathematically correct) implementation even though you pass the grader. My guess is that they wanted to keep the `public_tests.py` file the same between the two versions of the course (the Coursera version and the DLAI LP version).

---

<div class="post-metadata">

**Author:** ![Shriesh\_Kumar](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/shriesh_kumar/32/126194_2.png) [@Shriesh\_Kumar](https://community.deeplearning.ai/u/Shriesh_Kumar)\
**Post date:** [June 23, 2026, 2:54pm UTC](https://community.deeplearning.ai/t/w3a1-problems-that-i-encountered-due-to-public-tests-backward-propagation-test/893027/4 "2026-06-23T14:54:14Z")

</div>

Ah! Thank you for looking in this Paul. I should have searched a little more properly on W3A1, somehow I missed that thread from 2021. Anyways, I did understand it now and got what you are saying in the second reply. Really appreciate it.
