(self, apply_regional_compilation)
| 80 | |
| 81 | class Model(torch.nn.Module): |
| 82 | def __init__(self, apply_regional_compilation): |
| 83 | super().__init__() |
| 84 | self.linear = torch.nn.Linear(10, 10) |
| 85 | # Apply compile only to the repeated layers. |
| 86 | if apply_regional_compilation: |
| 87 | self.layers = torch.nn.ModuleList( |
| 88 | [torch.compile(Layer()) for _ in range(64)] |
| 89 | ) |
| 90 | else: |
| 91 | self.layers = torch.nn.ModuleList([Layer() for _ in range(64)]) |
| 92 | |
| 93 | def forward(self, x): |
| 94 | # In regional compilation, the self.linear is outside of the scope of `torch.compile`. |