How to set an Module attribute after constructing it? #1220
Answered
by
marcvanzee
marcvanzee
asked this question in
Q&A
-
Original question by @salayatana66: I want a unit_test that checks whether a certain submodule gets called. I have something like this: bound_transformer = Transformer(self.trans_cfg, self.aspect_vocab_size,
AdditiveEmbeddingsApplicationMode.ADD, self.start_layer_tail,
parent=flax.core.Scope(params))
decoder_head = bound_transformer.decoder_head
decoder_head.decode_embedded_targets = mock.Mock(side_effect=decoder_head.decode_embedded_targets)
... but then Flax complains at |
Beta Was this translation helpful? Give feedback.
Answered by
marcvanzee
Apr 8, 2021
Replies: 1 comment
-
You can use object.__setattr__(decoder_head, 'decode_embedded_targets', mock.Mock(side_effect=decoder_head.decode_embedded_targets) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
marcvanzee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
object.__setattr__
: