C5W4A1 Ex-4 Wrong values when training=True

I am having an error others have also seemed to have, however none of those threads helped me solve it.

ERROR:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-105-00617004b1af> in <module>
      1 # UNIT TEST
----> 2 EncoderLayer_test(EncoderLayer)

~/work/W4A1/public_tests.py in EncoderLayer_test(target)
     92                        [[ 0.23017104, -0.98100424, -0.78707516,  1.5379084 ],
     93                        [-1.2280797 ,  0.76477575, -0.7169283 ,  1.1802323 ],
---> 94                        [ 0.14880152, -0.48318022, -1.1908402 ,  1.5252188 ]]), "Wrong values when training=True"
     95 
     96     encoded = encoder_layer1(q, False, np.array([[1, 1, 0]]))

AssertionError: Wrong values when training=True

The issue is the “training=True” remark clearly, so I am having trouble what to do with that.

training is passed to the call() function, but where to actually use it / pass the value.

On the mha layer call only, as training=training?

On all the mha layer and the dropout layer?

On all the layers?

Thanks in advance.

@Adam_Moses , if you read again the guides on the lines of the exercise, there’s only one place where the training is mentioned. Try adding training=training to that function.

@TMosh @Juan_Olano

I figured it out in the end, but I do think the guidance before the exercise could be far more clear, if read verbatim without examining some of the extra documentation the way to do this is un-obvious.

1 Like

Hi Folks,
I’ve read thru past postings for the same error, but do not believe I am hitting any one of the them exactly. Code is (abstracted for honor code) – will provide if a mentor requests:

Thank you Al

AssertionError: Wrong values when training=True

Tip:
The only places in your code you should use the “training” argument are:

  • In the EncoderLayer() dropout_ffn(...) layer.
  • In the Encoder() dropout(...) layer and the enc_layers[i](...) call.
  • In the Decoder() dropout(...) layer and the dec_layers[i](...) call.

Also in the Transformer() layer calls to encoder() and decoder().

I have the same error
AssertionError: Wrong values when training=True
training = training i also add
but error is exist

I am currently unavailable. Please start a new thread.

This is the code I am facing the errors on. I’ve read some of those threads but none helps me solving which layer should I try with the training parameter.

def call(self, x, training, mask):
“”"
Forward pass for the Encoder Layer

    Arguments:
        x -- Tensor of shape (batch_size, input_seq_len, embedding_dim)
        training -- Boolean, set to true to activate
                    the training mode for dropout layers
        mask -- Boolean mask to ensure that the padding is not 
                treated as part of the input
    Returns:
        out2 -- Tensor of shape (batch_size, input_seq_len, embedding_dim)
    """
    # START CODE HERE

    # mentor edit: code removed

    # END CODE HERE
    
    return encoder_layer_out

Please do not post your code on the forum. That is not allowed by the course Code of Conduct.

From inspecting your code, your layers are not in the correct order. And the doctext for the return parameter is incorrect.

I think you may be using an obsolete version of the notebook.