W3_C4: Fail to understand why trax doesn't recognize function as layer

Hi,

When implementing W3_C4, I run into a strange problem.

The comment before the line is

 # Use the function `EncoderBlock` (implemented above) and pass in the parameters over `n_layers`

The comments regarding the error are that EncoderBlocks are passed as parameters. However, when define previously the EncoderBlocks, has no default parameter. This means the next line TransformerEncoder(n_layers=1) will absolutely create an error. I am guessing the unit tests will have the same problem as well.

I am not sure whether this is the issue, despite the fact that I highly suspect that.

Hey @R_Wang,
I agree that EncoderBlock doesn’t have any default parameters, but TransformerEncoder has default parameters, if you look carefully. All the parameters that are needed by EncoderBlock have default values defined in TransformerEncoder, hence, the next line won’t give an error. The same argument goes for the unit test-cases. I hope this helps.

Cheers,
Elemento

@Elemento Thank you very much for your help. If it is possible, can you have a look at the notebook then? I am very confused because basically I am faced with two dilemmas. Either I ignored the EncoderBlock = EncoderBlock or I initialize them in inside the function. I think in that case, the EncoderBlock = EncoderBlock argument will not be used.

Thank you very much.

Hey @R_Wang,
Sure and I am a little confused regarding your statement too. To sort that out, can you please DM me your implementation of TransformerEncoder so that I can understand your dilemma better.

Cheers,
Elemento