Skip to content

Commit f56aeb1

Browse files
committed
typing
1 parent 0579903 commit f56aeb1

42 files changed

Lines changed: 162 additions & 227 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/benchmark_sdnq_inference.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional, Union
2-
31
import time
42
import torch
53
from tqdm import tqdm
@@ -35,11 +33,11 @@ def benchmark_linear(name: str, linear: torch.nn.Linear, x: torch.Tensor, steps:
3533
def main(
3634
steps: int = 50,
3735
mnk: int = 8192,
38-
dtype: Optional[Union[torch.dtype, str]] = None,
39-
device: Optional[str] = None,
40-
m: Optional[int] = None,
41-
n: Optional[int] = None,
42-
k: Optional[int] = None,
36+
dtype: torch.dtype | str = None,
37+
device: str = None,
38+
m: int = None,
39+
n: int = None,
40+
k: int = None,
4341
) -> None:
4442
if device is None:
4543
device = "cuda" if torch.cuda.is_available() else "xpu" if hasattr(torch, "xpu") and torch.xpu.is_available() else None

scripts/benchmark_sdnq_training.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Union, Callable
1+
from collections.abc import Callable
22

33
import time
44
import torch
@@ -58,11 +58,11 @@ def benchmark_linear(name: str, linear: Callable, x: torch.Tensor, y: torch.Tens
5858
def main(
5959
steps: int = 50,
6060
mnk: int = 8192,
61-
dtype: Optional[Union[torch.dtype, str]] = None,
62-
device: Optional[str] = None,
63-
m: Optional[int] = None,
64-
n: Optional[int] = None,
65-
k: Optional[int] = None,
61+
dtype: torch.dtype | str = None,
62+
device: str = None,
63+
m: int = None,
64+
n: int = None,
65+
k: int = None,
6666
) -> None:
6767
if device is None:
6868
device = "cuda" if torch.cuda.is_available() else "xpu" if hasattr(torch, "xpu") and torch.xpu.is_available() else None

src/sdnq/dequantizer.py

Lines changed: 21 additions & 22 deletions
Large diffs are not rendered by default.

src/sdnq/forward.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pylint: disable=protected-access
22

3-
from typing import Callable
3+
from collections.abc import Callable
44

55
from .common import dtype_dict, conv_types, conv_transpose_types, use_tensorwise_fp8_matmul
66

src/sdnq/layers/conv/conv_fp16.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# pylint: disable=relative-beyond-top-level,redefined-builtin,protected-access
22

3-
from typing import List
4-
53
import torch
64

75
from ...common import compile_func, fp_mm_func # noqa: TID252
@@ -18,10 +16,10 @@ def conv_fp16_matmul(
1816
weight: torch.Tensor,
1917
scale: torch.FloatTensor,
2018
result_shape: torch.Size,
21-
reversed_padding_repeated_twice: List[int],
19+
reversed_padding_repeated_twice: list[int],
2220
padding_mode: str, conv_type: int,
23-
groups: int, stride: List[int],
24-
padding: List[int], dilation: List[int],
21+
groups: int, stride: list[int],
22+
padding: list[int], dilation: list[int],
2523
bias: torch.FloatTensor = None,
2624
svd_up: torch.FloatTensor = None,
2725
svd_down: torch.FloatTensor = None,

src/sdnq/layers/conv/conv_fp8.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# pylint: disable=relative-beyond-top-level,redefined-builtin,protected-access
22

3-
from typing import List
4-
53
import torch
64

75
from ...common import compile_func # noqa: TID252
@@ -17,10 +15,10 @@ def conv_fp8_matmul(
1715
weight: torch.Tensor,
1816
scale: torch.FloatTensor,
1917
result_shape: torch.Size,
20-
reversed_padding_repeated_twice: List[int],
18+
reversed_padding_repeated_twice: list[int],
2119
padding_mode: str, conv_type: int,
22-
groups: int, stride: List[int],
23-
padding: List[int], dilation: List[int],
20+
groups: int, stride: list[int],
21+
padding: list[int], dilation: list[int],
2422
bias: torch.FloatTensor = None,
2523
svd_up: torch.FloatTensor = None,
2624
svd_down: torch.FloatTensor = None,

src/sdnq/layers/conv/conv_fp8_tensorwise.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# pylint: disable=relative-beyond-top-level,redefined-builtin,protected-access
22

3-
from typing import List
4-
53
import torch
64

75
from ...common import compile_func # noqa: TID252
@@ -18,10 +16,10 @@ def conv_fp8_matmul_tensorwise(
1816
weight: torch.Tensor,
1917
scale: torch.FloatTensor,
2018
result_shape: torch.Size,
21-
reversed_padding_repeated_twice: List[int],
19+
reversed_padding_repeated_twice: list[int],
2220
padding_mode: str, conv_type: int,
23-
groups: int, stride: List[int],
24-
padding: List[int], dilation: List[int],
21+
groups: int, stride: list[int],
22+
padding: list[int], dilation: list[int],
2523
bias: torch.FloatTensor = None,
2624
svd_up: torch.FloatTensor = None,
2725
svd_down: torch.FloatTensor = None,

src/sdnq/layers/conv/conv_int8.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# pylint: disable=relative-beyond-top-level,redefined-builtin,protected-access
22

3-
from typing import List
4-
53
import torch
64

75
from ...common import compile_func, int_mm_func # noqa: TID252
@@ -18,10 +16,10 @@ def conv_int8_matmul(
1816
weight: torch.Tensor,
1917
scale: torch.FloatTensor,
2018
result_shape: torch.Size,
21-
reversed_padding_repeated_twice: List[int],
19+
reversed_padding_repeated_twice: list[int],
2220
padding_mode: str, conv_type: int,
23-
groups: int, stride: List[int],
24-
padding: List[int], dilation: List[int],
21+
groups: int, stride: list[int],
22+
padding: list[int], dilation: list[int],
2523
bias: torch.FloatTensor = None,
2624
svd_up: torch.FloatTensor = None,
2725
svd_down: torch.FloatTensor = None,

src/sdnq/layers/conv/forward.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# pylint: disable=relative-beyond-top-level,redefined-builtin,protected-access
22

3-
from typing import Optional
4-
53
import torch
64

75

@@ -78,16 +76,16 @@ def quantized_conv_forward(self, input) -> torch.FloatTensor:
7876
return self._conv_forward(input, self.sdnq_dequantizer(self.weight, self.scale, self.zero_point, self.svd_up, self.svd_down), self.bias)
7977

8078

81-
def quantized_conv_transpose_1d_forward(self, input: torch.FloatTensor, output_size: Optional[list[int]] = None) -> torch.FloatTensor:
79+
def quantized_conv_transpose_1d_forward(self, input: torch.FloatTensor, output_size: list[int] = None) -> torch.FloatTensor:
8280
output_padding = self._output_padding(input, output_size, self.stride, self.padding, self.kernel_size, 1, self.dilation)
8381
return torch.nn.functional.conv_transpose1d(input, self.sdnq_dequantizer(self.weight, self.scale, self.zero_point, self.svd_up, self.svd_down), self.bias, self.stride, self.padding, output_padding, self.groups, self.dilation)
8482

8583

86-
def quantized_conv_transpose_2d_forward(self, input: torch.FloatTensor, output_size: Optional[list[int]] = None) -> torch.FloatTensor:
84+
def quantized_conv_transpose_2d_forward(self, input: torch.FloatTensor, output_size: list[int] = None) -> torch.FloatTensor:
8785
output_padding = self._output_padding(input, output_size, self.stride, self.padding, self.kernel_size, 2, self.dilation)
8886
return torch.nn.functional.conv_transpose2d(input, self.sdnq_dequantizer(self.weight, self.scale, self.zero_point, self.svd_up, self.svd_down), self.bias, self.stride, self.padding, output_padding, self.groups, self.dilation)
8987

9088

91-
def quantized_conv_transpose_3d_forward(self, input: torch.FloatTensor, output_size: Optional[list[int]] = None) -> torch.FloatTensor:
89+
def quantized_conv_transpose_3d_forward(self, input: torch.FloatTensor, output_size: list[int] = None) -> torch.FloatTensor:
9290
output_padding = self._output_padding(input, output_size, self.stride, self.padding, self.kernel_size, 3, self.dilation)
9391
return torch.nn.functional.conv_transpose3d(input, self.sdnq_dequantizer(self.weight, self.scale, self.zero_point, self.svd_up, self.svd_down), self.bias, self.stride, self.padding, output_padding, self.groups, self.dilation)

src/sdnq/layers/linear/forward.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# pylint: disable=relative-beyond-top-level,redefined-builtin,protected-access
22

3-
from typing import Tuple
4-
53
import torch
64

75
from ...common import use_contiguous_mm # noqa: TID252
86

97

10-
def check_mats(input: torch.Tensor, weight: torch.Tensor, allow_contiguous_mm: bool = True) -> Tuple[torch.Tensor, torch.Tensor]:
8+
def check_mats(input: torch.Tensor, weight: torch.Tensor, allow_contiguous_mm: bool = True) -> tuple[torch.Tensor, torch.Tensor]:
119
input = input.contiguous()
1210
if allow_contiguous_mm and use_contiguous_mm:
1311
weight = weight.contiguous()

0 commit comments

Comments
 (0)