MCPcopy Create free account
hub / github.com/pytorch/tutorials / Model

Class Model

intermediate_source/autograd_saved_tensors_hooks_tutorial.py:325–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323import torch.nn as nn
324
325class Model(nn.Module):
326 def __init__(self):
327 super().__init__()
328 self.w = nn.Parameter(torch.randn(5))
329
330 def forward(self, x):
331 with torch.autograd.graph.save_on_cpu(pin_memory=True):
332 # some computation
333 return self.w * x
334
335x = torch.randn(5)
336model = Model()

Calls

no outgoing calls

Tested by

no test coverage detected