Is there a way to create a nn.Module without explicitly defining the class?

Hi, I am trying to define a local nn.Module (inside a function) which cannot be easily expressed as nn.Sequential, and I am wondering if there is a way to define it without explicitly defining the class within the function?

Thanks!

Can you develop the question (maybe with an example). I find the lexicon you used a bit confusing. One rarely defines a class within a function. Do you mean instantiate? What’s the relationship between nn.Module and nn.Sequential? Sequential is just a type of module.