# C5W4 - Cell #20. Can't compile the student's code. Error: AssertionError('Wrong values in attn\_w\_b2. Check the call to self.mha2')

**URL:** <https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [June 26, 2021, 2:57pm UTC](https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398 "2021-06-26T14:57:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![romain](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@romain](https://community.deeplearning.ai/u/romain)\
**Post date:** [June 26, 2021, 2:57pm UTC](https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398/1 "2021-06-26T14:57:12Z")

</div>

Hi !

I’ve this error.  
I put something like that :  
attn1, attn\_weights\_block1 = self.mha1(x, x, x, look\_ahead\_mask,return\_attention\_scores=True) # (batch\_size, target\_seq\_len, d\_model)  
attn2, attn\_weights\_block2 = self.mha2(enc\_output, enc\_output, out1, padding\_mask,return\_attention\_scores=True) # (batch\_size, target\_seq\_len, d\_model)

Do you have some tips to fix this error ?

Thanks !

---

<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:** [June 27, 2021, 6:05am UTC](https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398/2 "2021-06-27T06:05:59Z")

</div>

It would help if you specify which function you’re working on. I’m going to assume it is the “call” method of DecoderLayer().

Your arguments for mha2(…) are not correct.

---

<div class="post-metadata">

**Author:** ![romain](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@romain](https://community.deeplearning.ai/u/romain)\
**Post date:** [June 27, 2021, 9:25am UTC](https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398/3 "2021-06-27T09:25:59Z")

</div>

Yes it’s the call function of the block “decoder”.

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![gundewardv](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gundewardv](https://community.deeplearning.ai/u/gundewardv)\
**Post date:** [September 26, 2021, 11:21am UTC](https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398/4 "2021-09-26T11:21:41Z")

</div>

Hi ,  
I am facing same issue in Call Function in UNQ\_C6 ,

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)  
179  
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

AssertionError: Wrong values in attn\_w\_b2. Check the call to self.mha2

I am having below calls-

`{mentor edit: code removed}`

Can you please help to guide where I am going wrong.  
Thank you.

---

<div class="post-metadata">

**Author:** ![Nuwanda7](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@Nuwanda7](https://community.deeplearning.ai/u/Nuwanda7)\
**Post date:** [November 2, 2021, 2:17am UTC](https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398/5 "2021-11-02T02:17:40Z")

</div>

I’m having the same issue. I have tried similar code to yours, but I also replaced

self.mha2(mult\_attn\_out1 by {mentor edit: code removed}

where Q1 = {mentor edit: code removed}

Any suggestions appreciated!  
Edit: Figured it out. I needed: {mentor edit: code removed}

---

<div class="post-metadata">

**Author:** ![Akash\_Shah1](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@Akash\_Shah1](https://community.deeplearning.ai/u/Akash_Shah1)\
**Post date:** [October 2, 2022, 5:14am UTC](https://community.deeplearning.ai/t/c5w4-cell-20-cant-compile-the-students-code-error-assertionerror-wrong-values-in-attn-w-b2-check-the-call-to-self-mha2/17398/6 "2022-10-02T05:14:51Z")

</div>

Read documentation

> **[tf.keras.layers.MultiHeadAttention  |  TensorFlow v2.10.0](https://www.tensorflow.org/api_docs/python/tf/keras/layers/MultiHeadAttention)**
>
> MultiHeadAttention layer.
