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)
| 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 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected