Add basic linear layer tests
Browse files- build.toml +5 -0
- torch-ext/kernels_test/__init__.py +3 -0
- torch-ext/kernels_test/layers.py +24 -0
build.toml
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[general]
|
| 2 |
+
name = "kernels_test"
|
| 3 |
+
|
| 4 |
+
[torch]
|
| 5 |
+
universal = true
|
torch-ext/kernels_test/__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import layers
|
| 2 |
+
|
| 3 |
+
__all__ = ["layers"]
|
torch-ext/kernels_test/layers.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class LinearImplicitBackward(nn.Module):
|
| 6 |
+
def forward(self, input: torch.Tensor) -> torch.Tensor:
|
| 7 |
+
return F.linear(input, self.weight, self.bias)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class LinearBackward(nn.Module):
|
| 11 |
+
has_backward = True
|
| 12 |
+
|
| 13 |
+
def forward(self, input: torch.Tensor) -> torch.Tensor:
|
| 14 |
+
return F.linear(input, self.weight, self.bias)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class LinearNoBackward(nn.Module):
|
| 18 |
+
has_backward = False
|
| 19 |
+
|
| 20 |
+
def forward(self, input: torch.Tensor) -> torch.Tensor:
|
| 21 |
+
return F.linear(input, self.weight, self.bias)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
__all__ = ["LinearImplicitBackward", "LinearBackward", "LinearNoBackward"]
|