1

a question regarding keywords in torch.nn.Sequential, it is possible in some way to forward keywords to specific models in a sequence?

 model = torch.nn.Sequential(model_0, MaxPoolingChannel(1)) res = model(input_ids_2, keyword_test=mask) 

here, keyword_test should be forwarded only to the first model.

Thank a lot and best regards!

my duplicate from - https://discuss.pytorch.org/t/keyword-arguments-in-torch-nn-sequential/53282

1 Answer 1

2

No; you cannot. This is only possible if all models passed to the nn.Sequential expects the argument you are trying to pass in their forward method (at least at the time of writing this).

Two workarounds could be (I'm not aware of the whole case, but anticipated from the question):

  • If your value is static, why not initializing your first model with that value, and access it during computation with self.keyword_test.

  • In case the value is dynamic, you could have it as an inherent property in the input; hence, you can access it, also, during computation with input_ids_2.keyword_test

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.