# C5W4 exercise 6 DecoderLayer call method

**URL:** <https://community.deeplearning.ai/t/c5w4-exercise-6-decoderlayer-call-method/122233>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [April 25, 2022, 8:23am UTC](https://community.deeplearning.ai/t/c5w4-exercise-6-decoderlayer-call-method/122233 "2022-04-25T08:23:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Paterson](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@Kyle\_Paterson](https://community.deeplearning.ai/u/Kyle_Paterson)\
**Post date:** [April 25, 2022, 8:23am UTC](https://community.deeplearning.ai/t/c5w4-exercise-6-decoderlayer-call-method/122233/1 "2022-04-25T08:23:27Z")

</div>

Hello. I have managed to implement the calculation of the attention output (mult\_attn\_out2) of the second MHA block successfully, at least they pass the unit tests, but the values in the output of the feed forward network are wrong according to the final unit test. So something is going wrong with the add+norm layer of the second MHA block, the FFN layer, the dropout layer, the final add+norm layer, or some combination of all these. But I cannot find the problem. My code is attached below, hopefully someone can see what I cannot.

**DecoderLayer call method code**

```auto
mentor edit: code removed

```

**Error Message**

> * * *
> 
> AssertionError Traceback (most recent call last)  
> in   
> 1 # UNIT TEST  
> ----\> 2 DecoderLayer\_test(DecoderLayer, create\_look\_ahead\_mask)
> 
> ~/work/W4A1/public\_tests.py in DecoderLayer\_test(target, create\_look\_ahead\_mask)  
> 180 assert np.allclose(attn\_w\_b1[0, 0, 1], [0.5271505, 0.47284946, 0.], atol=1e-2), “Wrong values in attn\_w\_b1. Check the call to self.mha1”  
> 181 assert np.allclose(attn\_w\_b2[0, 0, 1], [0.32048798, 0.390301, 0.28921106]), “Wrong values in attn\_w\_b2. Check the call to self.mha2”  
> → 182 assert np.allclose(out[0, 0], [-0.22109576, -1.5455486, 0.852692, 0.9139523]), “Wrong values in out”  
> 183  
> 184
> 
> AssertionError: Wrong values in out

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [April 25, 2022, 2:09pm UTC](https://community.deeplearning.ai/t/c5w4-exercise-6-decoderlayer-call-method/122233/2 "2022-04-25T14:09:04Z")

</div>

The “output of the first block” is Q1, not mult\_attn\_out1.  
Also, the only layer that needs “training = training” is the dropout\_ffn() layer.

---

<div class="post-metadata">

**Author:** ![Kyle\_Paterson](https://avatars.discourse-cdn.com/v4/letter/k/9dc877/32.png) [@Kyle\_Paterson](https://community.deeplearning.ai/u/Kyle_Paterson)\
**Post date:** [April 25, 2022, 2:21pm UTC](https://community.deeplearning.ai/t/c5w4-exercise-6-decoderlayer-call-method/122233/3 "2022-04-25T14:21:05Z")

</div>

That sorted it, thanks. I knew it was something stupidly simple.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [July 6, 2023, 7:58pm UTC](https://community.deeplearning.ai/t/c5w4-exercise-6-decoderlayer-call-method/122233/5 "2023-07-06T19:58:41Z")

</div>

Closed on July 6, 2023, 7:58pm UTC


