Created
February 23, 2024 21:39
-
-
Save anijain2305/7d07de29a574fbcb4a471760c16540ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
torch._dynamo.config.guard_nn_modules = True | |
class SubMod(torch.nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.linear = torch.nn.Linear(10, 10) | |
def forward(self, x): | |
return self.linear(x) | |
class TopModule(torch.nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.submods = [SubMod(), SubMod()] | |
self.submods = [torch.compile(mod) for mod in self.submods] | |
def forward(self, x): | |
for submod in self.submods: | |
x = submod(x) | |
return x | |
mod = TopModule() | |
x = torch.randn(10, 10) | |
mod(x) |
Author
anijain2305
commented
Feb 23, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment