-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Operator] Add uniform, normal, resolve_neg & resolve_conj & zeros &…
… ones & full Ops with UT & Bench (#139)
- Loading branch information
Bowen12992
committed
Aug 6, 2024
1 parent
2bf0115
commit 48942a0
Showing
22 changed files
with
847 additions
and
103 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import torch | ||
|
||
from .performance_utils import ( | ||
FLOAT_DTYPES, | ||
POINTWISE_BATCH, | ||
SIZES, | ||
Benchmark, | ||
unary_arg, | ||
) | ||
|
||
|
||
def test_perf_rand(): | ||
def rand_kwargs(dtype, batch, size): | ||
return {"size": (batch, size), "dtype": dtype, "device": "cuda"} | ||
|
||
bench = Benchmark( | ||
op_name="rand", | ||
torch_op=torch.rand, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=rand_kwargs, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_randn(): | ||
def randn_kwargs(dtype, batch, size): | ||
return {"size": (batch, size), "dtype": dtype, "device": "cuda"} | ||
|
||
bench = Benchmark( | ||
op_name="randn", | ||
torch_op=torch.randn, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=randn_kwargs, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_rand_like(): | ||
bench = Benchmark( | ||
op_name="rand_like", | ||
torch_op=torch.rand_like, | ||
arg_func=unary_arg, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_normal(): | ||
def normal_arg(dtype, batch, size): | ||
loc = torch.full(size=(size, batch), fill_value=3.0, dtype=dtype, device="cuda") | ||
scale = torch.full( | ||
size=(size, batch), fill_value=10.0, dtype=dtype, device="cuda" | ||
) | ||
return loc, scale | ||
|
||
bench = Benchmark( | ||
op_name="distributions.normal.Normal", | ||
torch_op=torch.distributions.normal.Normal, | ||
arg_func=normal_arg, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_uniform(): | ||
bench = Benchmark( | ||
op_name="uniform_", | ||
torch_op=torch.Tensor.uniform_, | ||
arg_func=unary_arg, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_exponential_(): | ||
bench = Benchmark( | ||
op_name="exponential_", | ||
torch_op=torch.Tensor.exponential_, | ||
arg_func=unary_arg, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,58 @@ | ||
import torch | ||
|
||
from .performance_utils import ( | ||
FLOAT_DTYPES, | ||
POINTWISE_BATCH, | ||
SIZES, | ||
Benchmark, | ||
unary_arg, | ||
) | ||
from .performance_utils import POINTWISE_BATCH, SIZES, Benchmark | ||
|
||
|
||
def test_perf_rand(): | ||
def rand_kwargs(dtype, batch, size): | ||
return {"size": (batch, size), "dtype": dtype, "device": "cuda"} | ||
|
||
bench = Benchmark( | ||
op_name="rand", | ||
torch_op=torch.rand, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=rand_kwargs, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_randn(): | ||
def randn_kwargs(dtype, batch, size): | ||
return {"size": (batch, size), "dtype": dtype, "device": "cuda"} | ||
def test_perf_embedding(): | ||
def embedding_kwargs(dtype, batch, size): | ||
input = torch.randint(0, batch, (batch,), device="cuda") | ||
weight = torch.randn((batch + 1, size), device="cuda", dtype=dtype) | ||
return {"input": input, "weight": weight} | ||
|
||
bench = Benchmark( | ||
op_name="randn", | ||
torch_op=torch.randn, | ||
op_name="embedding", | ||
torch_op=torch.nn.functional.embedding, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
dtypes=[ | ||
torch.float32, | ||
torch.float16, | ||
], # Note(Zhengzekang): triton do not support bfloat16 atomic add which is used in embedding grad. | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=randn_kwargs, | ||
kwargs_func=embedding_kwargs, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_rand_like(): | ||
bench = Benchmark( | ||
op_name="rand_like", | ||
torch_op=torch.rand_like, | ||
arg_func=unary_arg, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() | ||
|
||
def test_perf_resolve_neg(): | ||
def resolve_neg_arg(dtype, batch, size): | ||
x = torch.randn(size=(batch, size), dtype=dtype, device="cuda") | ||
y = x.conj() | ||
z = y.imag | ||
return (z,) | ||
|
||
def test_perf_exponential_(): | ||
bench = Benchmark( | ||
op_name="exponential_", | ||
torch_op=torch.Tensor.exponential_, | ||
arg_func=unary_arg, | ||
dtypes=FLOAT_DTYPES, | ||
op_name="resolve_neg", | ||
torch_op=torch.resolve_neg, | ||
arg_func=resolve_neg_arg, | ||
dtypes=[torch.cfloat], | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_embedding(): | ||
def embedding_kwargs(dtype, batch, size): | ||
input = torch.randint(0, batch, (batch,), device="cuda") | ||
weight = torch.randn((batch + 1, size), device="cuda", dtype=dtype) | ||
return {"input": input, "weight": weight} | ||
def test_perf_resolve_conj(): | ||
def resolve_conj_arg(dtype, batch, size): | ||
x = torch.randn(size=(size, batch), dtype=dtype, device="cuda") | ||
return (x.conj(),) | ||
|
||
bench = Benchmark( | ||
op_name="embedding", | ||
torch_op=torch.nn.functional.embedding, | ||
arg_func=None, | ||
dtypes=[ | ||
torch.float32, | ||
torch.float16, | ||
], # Note(Zhengzekang): triton do not support bfloat16 atomic add which is used in embedding grad. | ||
op_name="resolve_conj", | ||
torch_op=torch.resolve_conj, | ||
arg_func=resolve_conj_arg, | ||
dtypes=[torch.cfloat], | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=embedding_kwargs, | ||
) | ||
bench.run() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import torch | ||
|
||
from .performance_utils import ( | ||
FLOAT_DTYPES, | ||
POINTWISE_BATCH, | ||
SIZES, | ||
Benchmark, | ||
unary_arg, | ||
) | ||
|
||
|
||
def test_perf_ones(): | ||
def ones_kwargs(dtype, batch, size): | ||
return {"size": (batch, size), "dtype": dtype, "device": "cuda"} | ||
|
||
bench = Benchmark( | ||
op_name="ones", | ||
torch_op=torch.ones, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=ones_kwargs, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_zeros(): | ||
def zeros_kwargs(dtype, batch, size): | ||
return {"size": (batch, size), "dtype": dtype, "device": "cuda"} | ||
|
||
bench = Benchmark( | ||
op_name="zeros", | ||
torch_op=torch.zeros, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=zeros_kwargs, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_full(): | ||
def full_kwargs(dtype, batch, size): | ||
return { | ||
"size": (batch, size), | ||
"fill_value": 3.1415926, | ||
"dtype": dtype, | ||
"device": "cuda", | ||
} | ||
|
||
bench = Benchmark( | ||
op_name="full", | ||
torch_op=torch.full, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=full_kwargs, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_ones_like(): | ||
bench = Benchmark( | ||
op_name="ones_like", | ||
torch_op=torch.ones_like, | ||
arg_func=unary_arg, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_zeros_like(): | ||
bench = Benchmark( | ||
op_name="zeros_like", | ||
torch_op=torch.zeros_like, | ||
arg_func=unary_arg, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
) | ||
bench.run() | ||
|
||
|
||
def test_perf_full_like(): | ||
def full_kwargs(dtype, batch, size): | ||
return { | ||
"input": torch.randn([batch, size], dtype=dtype, device="cuda"), | ||
"fill_value": 3.1415926, | ||
} | ||
|
||
bench = Benchmark( | ||
op_name="full_like", | ||
torch_op=torch.full_like, | ||
arg_func=None, | ||
dtypes=FLOAT_DTYPES, | ||
batch=POINTWISE_BATCH, | ||
sizes=SIZES, | ||
kwargs_func=full_kwargs, | ||
) | ||
bench.run() |
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
Oops, something went wrong.