[fx] refactored the file structure of patched function and module (#1238)

* [fx] refactored the file structure of patched function and module

* polish code
This commit is contained in:
Frank Lee
2022-07-12 15:01:58 +08:00
committed by GitHub
parent 17ed33350b
commit 7531c6271f
15 changed files with 353 additions and 318 deletions

View File

@@ -0,0 +1,9 @@
import torch
from ..registry import meta_patched_module
@meta_patched_module.register(torch.nn.Linear)
def torch_nn_linear(self, input):
last_dim = input.shape[-1]
assert last_dim == self.in_features, f'Expected hidden size {self.in_features} but got {last_dim} for the torch.nn.Linear patch'
return torch.empty(input.shape[:-1] + (self.out_features,), device="meta")