Created
February 6, 2024 19:35
-
-
Save anijain2305/eaf344fdeadf5c6aeba477db045b1b20 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 | |
from torch.utils.checkpoint import checkpoint | |
class MyModule(torch.nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.linear = torch.nn.Linear(10, 10) | |
def _forward_helper(self, x): | |
a = torch.sin(x) | |
b = self.linear(a) | |
torch._dynamo.graph_break() | |
c = torch.cos(b) | |
return c | |
def forward(self, x): | |
return checkpoint(self._forward_helper, x, use_reentrant=False) | |
x = torch.randn(10, 10) | |
mod = MyModule() | |
ref = mod(x) | |
opt_mod = torch.compile(mod, backend="eager") | |
res = opt_mod(x) |
Author
anijain2305
commented
Feb 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment