Created
November 5, 2022 02:00
-
-
Save smithjessk/abccdd4d21f9fc65c4a22565b67d095b to your computer and use it in GitHub Desktop.
benchmarked typeguard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %% | |
from torchtyping import TensorType as TT, patch_typeguard | |
import torch as t | |
from typeguard import typechecked | |
patch_typeguard() | |
# %% | |
def compute_times(size): | |
x = t.rand(size, size) | |
print(f'{x.shape=}') | |
print("computing x @ x inline without a function call") | |
%timeit x @ x | |
@typechecked | |
def at(x: TT[size, size], y: TT[size, size]) -> TT[size, size]: | |
return x @ y | |
print("computing x @ x with a function call that uses typeguard") | |
%timeit at(x, x) | |
for dim in [1, 10, 100, 1000]: | |
compute_times(dim) | |
# %% | |
for dim in [2000, 4000]: | |
compute_times(dim) | |
# %% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment