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

Method forward

beginner_source/examples_nn/dynamic_net.py:28–43  ·  view source on GitHub ↗

For the forward pass of the model, we randomly choose either 4, 5 and reuse the e parameter to compute the contribution of these orders. Since each forward pass builds a dynamic computation graph, we can use normal Python control-flow operators like loops or conditi

(self, x)

Source from the content-addressed store, hash-verified

26 self.e = torch.nn.Parameter(torch.randn(()))
27
28 def forward(self, x):
29 """
30 For the forward pass of the model, we randomly choose either 4, 5
31 and reuse the e parameter to compute the contribution of these orders.
32
33 Since each forward pass builds a dynamic computation graph, we can use normal
34 Python control-flow operators like loops or conditional statements when
35 defining the forward pass of the model.
36
37 Here we also see that it is perfectly safe to reuse the same parameter many
38 times when defining a computational graph.
39 """
40 y = self.a + self.b * x + self.c * x ** 2 + self.d * x ** 3
41 for exp in range(4, random.randint(4, 6)):
42 y = y + self.e * x ** exp
43 return y
44
45 def string(self):
46 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected