repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
pytorch | pytorch-main/benchmarks/nested/nested_bmm_bench.py | import argparse
import random
import torch
def bench(nt_a, nt_b, niter):
# Warmup
nt_c = nt_a.bmm(nt_b)
torch.cuda.synchronize()
start_event = torch.cuda.Event(enable_timing=True)
end_event = torch.cuda.Event(enable_timing=True)
start_event.record()
for iter in range(niter):
nt_c... | 1,573 | 28.148148 | 86 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/benchmark_test_generator.py | from benchmark_core import _register_test
from benchmark_pytorch import create_pytorch_op_test_case
def generate_pt_test(configs, pt_bench_op):
""" This function creates PyTorch op test based on the given operator
"""
_register_test(configs, pt_bench_op, create_pytorch_op_test_case, False)
def generate_... | 1,711 | 37.909091 | 100 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/benchmark_runner.py | import argparse
import torch
import benchmark_core
import benchmark_utils
"""Performance microbenchmarks's main binary.
This is the main function for running performance microbenchmark tests.
It also registers existing benchmark tests via Python module imports.
"""
parser = argparse.ArgumentParser(
description=... | 4,736 | 27.196429 | 115 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/benchmark_utils.py | import numpy as np
import itertools
import random
import os
import bisect
"""Performance microbenchmarks's utils.
This module contains utilities for writing microbenchmark tests.
"""
# Here are the reserved keywords in the benchmark suite
_reserved_keywords = {"probs", "total_samples", "tags"}
_supported_devices = ... | 11,999 | 33.482759 | 94 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/benchmark_pytorch.py | import time
import json
import torch
import benchmark_cpp_extension # noqa: F401
"""PyTorch performance microbenchmarks.
This module contains PyTorch-specific functionalities for performance
microbenchmarks.
"""
class TorchBenchmarkBase(torch.nn.Module):
""" This is a base class used to create Pytorch operator... | 7,687 | 38.025381 | 94 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/operator_benchmark.py | # TODO (mingzhe09088): get rid of noqa
import benchmark_runner # noqa: F401
from benchmark_pytorch import TorchBenchmarkBase # noqa: F401
from benchmark_test_generator import * # noqa: F401,F403
from benchmark_utils import * # noqa: F401,F403
| 247 | 40.333333 | 62 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/benchmark_core.py | import functools
import numpy as np
import timeit
import json
import torch
import copy
import ast
# needs to be imported after torch
import torch.utils.cpp_extension as cpp_extension # noqa: F401
import benchmark_utils
from collections import namedtuple
"""Performance microbenchmarks.
This module contains core fun... | 17,255 | 41.818859 | 120 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/benchmark_caffe2.py | from caffe2.python import workspace
from caffe2.python import core
from caffe2.proto import caffe2_pb2
import benchmark_utils
from collections import namedtuple
from benchmark_test_generator import _register_test
"""Caffe2 performance microbenchmarks.
This module contains Caffe2-specific functionalities for performan... | 7,869 | 37.203883 | 100 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/repeat_benchmark.py | import numpy as np
import torch
import time
"""Microbenchmarks for Tensor repeat operator. Supports PyTorch."""
input_shapes = (
(4, 4, 1),
(16, 1, 32),
(64, 64, 1, 1),
(8, 256, 128),
(1, 64, 128, 32),
(512, 512),
)
repeats = ... | 1,709 | 28.482759 | 97 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/tests/jit_forward_test.py | import operator_benchmark as op_bench
import torch
intraop_bench_configs = op_bench.config_list(
attrs=[
[8, 16],
],
attr_names=["M", "N"],
tags=["short"],
)
@torch.jit.script
def torch_sumall(a, iterations):
# type: (Tensor, int)
result = 0.0
for _ in range(iterations):
re... | 951 | 24.052632 | 67 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/tests/pt_configs_list_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for element-wise Add operator. Supports both Caffe2/PyTorch."""
add_short_configs = op_bench.config_list(
attr_names=['M', 'N', 'K'],
attrs=[
[8, 16, 32],
[16, 16, 64],
[64, 64, 128],
],
cross_product_configs... | 939 | 25.111111 | 92 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/tests/random_sample_test.py | import operator_benchmark as op_bench
import torch
configs = op_bench.random_sample_configs(
M=[1, 2, 3, 4, 5, 6],
N=[7, 8, 9, 10, 11, 12],
K=[13, 14, 15, 16, 17, 18],
# probs saves the weights of each value
probs=op_bench.attr_probs(
M=[0.5, 0.2, 0.1, 0.05, 0.03, 0.1],
N=[0.1, 0.3... | 892 | 23.805556 | 56 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/tests/pt_cpu_gpu_forward_backward_test.py | import operator_benchmark as op_bench
import torch
add_configs = op_bench.cross_product_configs(
M=[8],
N=[8],
K=[8],
device=["cuda", "cpu"],
tags=["short"]
)
class AddBenchmark(op_bench.TorchBenchmarkBase):
def init(self, M, N, K, device):
self.input_one = torch.rand(M, N, K, device... | 729 | 23.333333 | 79 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/tests/pt_backward_test.py | import operator_benchmark as op_bench
import torch
add_configs = op_bench.cross_product_configs(
M=[8, 1],
N=[8, 2],
K=[8, 4],
tags=["short"]
)
# This benchmark uses the auto_set to automatically set requires_grad
# for both inputs. The test name can also be used for filtering.
class AddBenchmark(op_... | 828 | 26.633333 | 75 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/tests/c2_cpu_gpu_forward_backward_test.py | import operator_benchmark as op_bench
from caffe2.python import core
add_configs = op_bench.cross_product_configs(
M=[8],
N=[8],
K=[8],
tags=["short"],
device=["cuda", "cpu"]
)
class AddBenchmark(op_bench.Caffe2BenchmarkBase):
def init(self, M, N, K, device):
self.set_module_name("add... | 1,231 | 28.333333 | 77 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/common/tests/add_ops_list_test.py | import operator_benchmark as op_bench
import torch
# Configs for pointwise unary ops
unary_ops_configs = op_bench.config_list(
attrs=[
[128, 128],
],
attr_names=["M", "N"],
tags=["short"]
)
unary_ops_list = op_bench.op_list(
attr_names=["op_name", "op_func"],
attrs=[
["abs", ... | 763 | 19.105263 | 92 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/replace_nan_test.py | import benchmark_caffe2 as op_bench_c2
import operator_benchmark as op_bench
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core
"""Microbenchmarks for element-wise ReplaceNaN operator."""
# Configs for C2 ReplaceNaN operator
replace_nan_long_configs = op_bench.cross_product... | 1,144 | 25.022727 | 83 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/concat_test.py | import operator_benchmark as op_bench
import benchmark_caffe2 as op_bench_c2
import random
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core
"""Microbenchmarks for Concat operator. Supports both Caffe2/PyTorch."""
cross_product_configs = {
'device': ['cpu', 'cuda'],
... | 4,529 | 33.580153 | 104 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/clip_ranges_test.py | import benchmark_caffe2 as op_bench_c2
import operator_benchmark as op_bench
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core, dyndep
dyndep.InitOpsLibrary("@/caffe2/caffe2/fb/operators:clip_ranges_op")
"""Microbenchmarks for ClipRanges operator."""
# Configs for C2 ClipR... | 1,393 | 25.807692 | 98 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/quantile_op_test.py | import benchmark_caffe2 as op_bench_c2
import operator_benchmark as op_bench
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core
"""Microbenchmarks for QuantileOp operator."""
# Configs for C2 QuantileOp operator
quantile_op_long_configs = op_bench.cross_product_configs(
... | 1,269 | 25.458333 | 85 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/batch_box_cox_test.py | import benchmark_caffe2 as op_bench_c2
import operator_benchmark as op_bench
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core
"""Microbenchmarks for BatchBoxCox operator."""
# Configs for C2 BatchBoxCox operator
batch_box_cox_long_configs = op_bench.cross_product_configs(... | 1,307 | 26.829787 | 101 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/add_test.py | import operator_benchmark as op_bench
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core
"""Microbenchmarks for element-wise Add operator. Supports both Caffe2/PyTorch."""
# Configs for C2 add operator
add_long_configs = op_bench.cross... | 1,282 | 25.729167 | 82 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/batch_gather_test.py | import benchmark_caffe2 as op_bench_c2
import operator_benchmark as op_bench
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core
import numpy
"""Microbenchmarks for element-wise BatchGather operator."""
# Configs for C2 BatherGather operator
batch_gather_configs_short = op_b... | 1,566 | 26.491228 | 97 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/c2/matmul_test.py |
import operator_benchmark as op_bench
import benchmark_caffe2 as op_bench_c2
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
from caffe2.python import core
"""Microbenchmarks for MatMul operator"""
# Configs for C2 Matmul operator
mm_long_configs = op_bench.cross_product_configs(
M=[8, 64, 128],
... | 1,436 | 27.176471 | 81 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qcomparators_test.py | import torch
import operator_benchmark as op_bench
qcomparators_configs = op_bench.cross_product_configs(
N=(8, 64),
dtype=(torch.quint8, torch.qint8, torch.qint32),
contig=(False, True),
other_scalar=(False, True),
out_variant=(False, True),
tags=('short',)
)
qcomparators_ops = op_bench.op_l... | 2,155 | 28.944444 | 95 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/bmm_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for add_ operator. Supports both Caffe2/PyTorch."""
class BmmBenchmark(op_bench.TorchBenchmarkBase):
def init(self, B, M, N, K, device, op):
self.inputs = {
"batch1": torch.rand((B, M, K), device=device, requires_grad=self.a... | 925 | 27.9375 | 90 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/nan_to_num_test.py | import operator_benchmark as op_bench
import torch
import math
"""Microbenchmarks for torch.nan_to_num / nan_to_num_ operators"""
# Configs for PT torch.nan_to_num / nan_to_num_ operators
nan_to_num_ops_list = op_bench.op_list(
attr_names=['op_name', 'op_func'],
attrs=[
['nan_to_num', torch.nan_to_n... | 1,592 | 23.890625 | 82 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/pool_test.py | import operator_benchmark as op_bench
import torch
import torch.nn as nn
"""
Microbenchmarks for MaxPool1d and AvgPool1d operators.
"""
# Configs for pool-1d ops
pool_1d_configs_short = op_bench.config_list(
attr_names=[
'kernel', 'stride', 'N', 'C', 'L'
],
attrs=[
[3, 1, 8, 256, 256],
... | 4,345 | 23.553672 | 102 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/conv_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn as nn
from pt import configs
"""
Microbenchmarks for Conv1d and ConvTranspose1d operators.
"""
class Conv1dBenchmark(op_bench.TorchBenchmarkBase):
def init(self, IC, OC, kernel, stride, N, L, device):
self.inputs = {
"input":... | 4,373 | 32.646154 | 98 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/chunk_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for Chunk operator"""
# Configs for PT Chunk operator
chunk_short_configs = op_bench.config_list(
attr_names=["M", "N", "chunks"],
attrs=[
[8, 8, 2],
[256, 512, 2],
[512, 512, 2],
],
cross_product_configs={... | 1,072 | 20.897959 | 68 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/gelu_test.py |
import operator_benchmark as op_bench
import torch
"""
Microbenchmarks for the gelu operators.
"""
gelu_configs_long = op_bench.cross_product_configs(
N=[1, 4],
C=[3],
H=[16, 256],
W=[16, 256],
device=['cpu'],
tags=['long']
)
class GeluBenchmark(op_bench.TorchBenchmarkBase):
def init(s... | 645 | 17.457143 | 59 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qlayernorm_test.py |
import operator_benchmark as op_bench
import torch
"""Microbenchmarks for quantized layernorm operator."""
layernorm_configs_short = op_bench.cross_product_configs(
dims=(
(1, 8, 16),
(8, 8, 16),
(32, 8, 16),
(64, 128, 56, 56),
),
dtype=(torch.qint8,),
tags=["short"],... | 1,322 | 25.46 | 87 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qarithmetic_test.py | import torch
from torch._ops import ops
import operator_benchmark as op_bench
qarithmetic_binary_configs = op_bench.cross_product_configs(
N=(2, 8, 64, 512),
dtype=(torch.quint8, torch.qint8, torch.qint32),
contig=(False, True),
tags=('short',)
)
qarithmetic_binary_ops = op_bench.op_list(
attrs=(... | 2,817 | 31.390805 | 85 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qembedding_pack_test.py |
import operator_benchmark as op_bench
import torch
embeddingbag_conversion_short_configs = op_bench.cross_product_configs(
num_embeddings=(80,),
embedding_dim=(128, 256, 512),
tags=('short',)
)
embeddingbag_conversion_long_configs = op_bench.cross_product_configs(
num_embeddings=(100, 120, 1000),
... | 3,837 | 37.767677 | 117 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/linear_unpack_fp16_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for linear_unpack_fp16_ operator. Supports both Caffe2/PyTorch."""
# Configs for PT linear_unpack_fp16 operator
linear_unpack_fp16_long_configs = op_bench.cross_product_configs(
M=[8, 128],
N=[32, 64],
K=[256, 512],
device=['cpu'],
... | 1,593 | 32.208333 | 120 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/instancenorm_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn.functional as F
"""Microbenchmarks for instancenorm operator."""
instancenorm_configs_short = op_bench.cross_product_configs(
dims=(
(32, 8, 16),
(32, 8, 56, 56),
),
tags=["short"],
)
class InstanceNormBenchmark(op_benc... | 932 | 23.552632 | 76 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/clip_ranges_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for ClipRanges operator."""
torch.ops.load_library("//caffe2/torch/fb/sparsenn:sparsenn_operators")
# Configs for C2 ClipRanges operator
clip_ranges_long_configs = op_bench.cross_product_configs(
LENGTH=range(1, 100),
M=[1],
N=[2],
... | 1,410 | 24.654545 | 77 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qembedding_bag_lookups_test.py |
import operator_benchmark as op_bench
import torch
import numpy as np
from typing import Optional
from torch.testing._internal.common_quantization import (
lengths_to_offsets
)
torch.ops.load_library("//caffe2/torch/fb/sparsenn:sparsenn_operators")
embedding_bag_rowwise_offsets_short_configs = op_bench.cross_p... | 9,652 | 37.767068 | 116 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qactivation_test.py | import torch
import torch.ao.nn.quantized.functional as qF
import operator_benchmark as op_bench
r"""Microbenchmarks for the quantized activations."""
qactivation_long_configs = op_bench.cross_product_configs(
dims=(
# VGG-16 relu's with original shape: (-1, 3, 224, 224)
( 64, 224, 224), # ReLU-... | 3,632 | 31.4375 | 93 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/gather_test.py | import operator_benchmark as op_bench
import torch
import numpy
"""Microbenchmarks for gather operator."""
# An example input from this configuration is M=4, N=4, dim=0.
gather_configs_short = op_bench.config_list(
attr_names=["M", "N", "dim"],
attrs=[
[256, 512, 0],
[512, 512, 1],
],
... | 1,269 | 23.423077 | 90 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/linear_prepack_fp16_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for linear_prepack_fp16_ operator. Supports both Caffe2/PyTorch."""
# Configs for PT linear_prepack_fp16 operator
linear_prepack_fp16_long_configs = op_bench.cross_product_configs(
M=[8, 128],
N=[32, 64],
K=[256, 512],
device=['cpu'... | 1,329 | 28.555556 | 123 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/index_select_test.py | import operator_benchmark as op_bench
import torch
import numpy
"""Microbenchmarks for index_select operator."""
# An example input from this configuration is M=4, N=4, dim=0.
index_select_configs_short = op_bench.config_list(
attr_names=["M", "N", "K", "dim"],
attrs=[
[8, 8, 1, 1],
[256, 512... | 1,474 | 24.431034 | 95 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/tensor_to_test.py | import operator_benchmark as op_bench
import torch
tensor_conversion_short_configs = op_bench.cross_product_configs(
M=(8, 16, 32,),
N=(16, 64, 128,),
device=['cpu', 'cuda'],
tags=['short'],
)
tensor_conversion_long_configs = op_bench.cross_product_configs(
M=(64, 128, 256, 512,),
N=(256, 512,... | 1,441 | 31.772727 | 96 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qpool_test.py | import torch
import operator_benchmark as op_bench
# 2D pooling will have input matrix of rank 3 or 4
qpool2d_long_configs = op_bench.config_list(
attrs=(
# C H W k s p
( 1, 3, 3, (3, 3), (1, 1), (0, 0)), # dummy # noqa: E201,E241
( 3, 64, 64, (3, 3), (... | 4,604 | 34.423077 | 95 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/as_strided_test.py | import operator_benchmark as op_bench
import torch
from typing import List
"""Microbenchmarks for as_strided operator"""
# Configs for PT as_strided operator
as_strided_configs_short = op_bench.config_list(
attr_names=["M", "N", "size", "stride", "storage_offset"],
attrs=[
[8, 8, (2, 2), (1, 1), 0],... | 1,460 | 24.631579 | 80 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qgroupnorm_test.py |
import operator_benchmark as op_bench
import torch
"""Microbenchmarks for quantized groupnorm operator."""
groupnorm_configs_short = op_bench.cross_product_configs(
dims=(
(32, 8, 16),
(32, 8, 56, 56),
),
num_groups=(2, 4),
dtype=(torch.qint8,),
tags=["short"],
)
class QGroupNo... | 1,362 | 26.26 | 104 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/ao_sparsifier_test.py |
import operator_benchmark as op_bench
import torch
from torch import nn
from torch.ao import pruning
"""Microbenchmarks for sparsifier."""
sparse_configs_short = op_bench.config_list(
attr_names=["M", "SL", "SBS", "ZPB"],
attrs=[
[(32, 16), 0.3, (4, 1), 2],
[(32, 16), 0.6, (1, 4), 4],
... | 1,526 | 27.277778 | 67 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/sum_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for sum reduction operator."""
# Configs for PT add operator
sum_configs = op_bench.cross_product_configs(
R=[64, 256], # Length of reduced dimension
V=[32, 512], # Length of other dimension
dim=[0, 1],
contiguous=[True, False],
... | 1,326 | 26.081633 | 72 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/hardswish_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn as nn
"""
Microbenchmarks for the hardswish operators.
"""
# Configs for hardswish ops
hardswish_configs_short = op_bench.config_list(
attr_names=[
'N', 'C', 'H', 'W'
],
attrs=[
[1, 3, 256, 256],
[4, 3, 256, 256]... | 1,299 | 19.3125 | 89 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/fill_test.py | import operator_benchmark as op_bench
import torch
from torch.testing._internal.common_device_type import get_all_device_types
"""Microbenchmark for Fill_ operator."""
fill_short_configs = op_bench.config_list(
attr_names=["N"],
attrs=[
[1],
[1024],
[2048],
],
cross_product_co... | 1,164 | 23.270833 | 75 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qconv_test.py |
import operator_benchmark as op_bench
import torch
import torch.ao.nn.quantized as nnq
from pt import configs
"""
Microbenchmarks for qConv operators.
"""
class QConv1dBenchmark(op_bench.TorchBenchmarkBase):
# def init(self, N, IC, OC, L, G, kernel, stride, pad):
def init(self, IC, OC, kernel, stride, N, L,... | 2,783 | 35.631579 | 126 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/layernorm_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn.functional as F
"""Microbenchmarks for layernorm operator."""
layernorm_configs_short = op_bench.cross_product_configs(
dims=(
(1, 8, 16),
(8, 8, 16),
(32, 8, 16),
(64, 128, 56, 56),
),
tags=["short"],
)
... | 975 | 23.4 | 71 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/unary_test.py |
import operator_benchmark as op_bench
import torch
"""Microbenchmarks for point-wise unary operator."""
# Configs for pointwise unary ops
unary_ops_configs_short = op_bench.config_list(
attr_names=['M', 'N'],
attrs=[
[512, 512],
],
cross_product_configs={
'device': ['cpu', 'cuda'],
... | 4,192 | 24.882716 | 89 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/matrix_mult_test.py | import operator_benchmark as op_bench
import torch
"""
Microbenchmarks for batch matrix mult with einsum and torch.bmm.
"""
batch_mm_configs_short = op_bench.config_list(
attr_names=["B", "M", "N", "K"],
attrs=[
[4, 5, 3, 2],
[32, 25, 20, 30],
[128, 100, 120, 110],
],
cross_pro... | 2,971 | 23.766667 | 71 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/interpolate_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for interpolate operator."""
class InterpolateBenchmark(op_bench.TorchBenchmarkBase):
def init(self, input_size, output_size, channels_last=False, mode='linear', dtype=torch.float):
input_image = torch.randint(0, 256, size=input_size,... | 4,098 | 27.268966 | 99 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/embeddingbag_test.py | import operator_benchmark as op_bench
import torch
import numpy
from pt import configs
"""Embedding and EmbeddingBag Operator Benchmark"""
class EmbeddingBagBenchmark(op_bench.TorchBenchmarkBase):
def init(self, embeddingbags, dim, mode, input_size, offset, sparse, include_last_offset, device):
self.embed... | 2,015 | 40.142857 | 103 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qtensor_method_test.py | import operator_benchmark as op_bench
import torch
# Configs for pointwise and reduction unary ops
qmethods_configs_short = op_bench.config_list(
attr_names=['M', 'N'],
attrs=[
[32, 32],
],
cross_product_configs={
'dtype': [torch.quint8],
'contig': [False, True],
},
tags... | 1,436 | 25.127273 | 71 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/add_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for add_ operator. Supports both Caffe2/PyTorch."""
# Configs for PT add operator
add_long_configs = op_bench.cross_product_configs(
M=[8, 128],
N=[32, 64],
K=[256, 512],
device=['cpu', 'cuda'],
tags=["long"]
)
add_short_confi... | 3,981 | 30.109375 | 103 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qbatchnorm_test.py |
import operator_benchmark as op_bench
import torch
"""Microbenchmarks for quantized batchnorm operator."""
batchnorm_configs_short = op_bench.config_list(
attr_names=["M", "N", "K"],
attrs=[
[1, 256, 3136],
],
cross_product_configs={
'device': ['cpu'],
'dtype': (torch.qint8,)... | 2,458 | 25.159574 | 93 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qatembedding_ops_test.py | import operator_benchmark as op_bench
import torch
import torch.ao.nn.qat as nnqat
import numpy
from pt import configs
from torch.ao.quantization import default_embedding_qat_qconfig
"""
Microbenchmarks for QAT Embedding + EmbeddingBag operators.
"""
class QATEmbeddingBagBenchmark(op_bench.TorchBenchmarkBase):
def... | 2,614 | 41.177419 | 102 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/softmax_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn as nn
"""
Microbenchmarks for the softmax operators.
"""
# Configs for softmax ops
softmax_configs_short = op_bench.config_list(
attr_names=[
'N', 'C', 'H', 'W'
],
attrs=[
[1, 3, 256, 256],
[4, 3, 256, 256],
... | 2,300 | 21.125 | 85 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qembeddingbag_test.py |
import operator_benchmark as op_bench
import torch
import torch.ao.nn.quantized as nnq
import numpy
from pt import configs
"""
Microbenchmarks for qEmbeddingBag operators.
"""
class QEmbeddingBagBenchmark(op_bench.TorchBenchmarkBase):
def init(self, embeddingbags, dim, mode, input_size, offset, sparse, include_l... | 1,242 | 32.594595 | 107 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/cat_test.py | import operator_benchmark as op_bench
import torch
import random
from typing import List
"""Microbenchmarks for Cat operator"""
cross_product_configs = {
'device': ['cpu', 'cuda'],
}
# Configs for PT Cat operator
cat_configs_short = op_bench.config_list(
attr_names=['sizes', 'N', 'dim'],
attrs=[
... | 4,136 | 32.634146 | 104 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qinterpolate_test.py | import operator_benchmark as op_bench
import torch
'''Microbenchmarks for the quantized interpolate op.
Note: We are not benchmarking `upsample` as it is being depricated, and calls
the `interpolate` anyway.
'''
qinterpolate_long_configs = op_bench.config_list(
attr_names=['M', 'N', 'K'],
attrs=[
[51... | 2,237 | 31.911765 | 81 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/split_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for Split operator"""
# Configs for PT Split operator
split_configs_short = op_bench.config_list(
attr_names=["M", "N", "parts"],
attrs=[
[8, 8, 2],
[256, 512, 2],
[512, 512, 2],
],
cross_product_configs={
... | 1,079 | 21.040816 | 67 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qinstancenorm_test.py |
import operator_benchmark as op_bench
import torch
"""Microbenchmarks for quantized instancenorm operator."""
instancenorm_configs_short = op_bench.cross_product_configs(
dims=(
(32, 8, 16),
(32, 8, 56, 56),
),
dtype=(torch.qint8,),
tags=["short"],
)
class QInstanceNormBenchmark(op... | 1,278 | 25.645833 | 87 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/quantization_test.py |
import operator_benchmark as op_bench
import torch
import torch.ao.nn.quantized as nnq
import torch.ao.quantization as tq
import torch.nn as nn
"""Microbenchmarks for general quantization operations."""
# mode is used to show the direction of the benchmark:
# if 'Q', benchmark quantization, else dequantization
quan... | 11,606 | 32.449568 | 125 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/hardsigmoid_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn as nn
"""
Microbenchmarks for the hardsigmoid operator.
"""
# Configs for hardsigmoid ops
hardsigmoid_configs_short = op_bench.config_list(
attr_names=[
'N', 'C', 'H', 'W'
],
attrs=[
[1, 3, 256, 256],
[4, 3, 256,... | 1,322 | 19.671875 | 93 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/diag_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for diag operator"""
# Configs for PT diag operator
diag_configs_short = op_bench.config_list(
attr_names=['dim', 'M', 'N', 'diagonal', 'out'],
attrs=[
[1, 64, 64, 0, True],
[2, 128, 128, -10, False],
[1, 256, 256,... | 1,166 | 24.933333 | 99 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qlinear_test.py |
import operator_benchmark as op_bench
import torch
import torch.ao.nn.quantized as nnq
import torch.ao.nn.quantized.dynamic as nnqd
from pt import configs
"""
Microbenchmarks for Quantized Linear operators.
"""
class _QLinearBenchmarkBase(op_bench.TorchBenchmarkBase):
def init(self, N, IN, OUT, linear_under_te... | 1,880 | 32 | 131 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/groupnorm_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn.functional as F
"""Microbenchmarks for groupnorm operator."""
groupnorm_configs_short = op_bench.cross_product_configs(
dims=(
(32, 8, 16),
(32, 8, 56, 56),
),
num_groups=(2, 4),
tags=["short"],
)
class GroupNormBen... | 1,016 | 24.425 | 72 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qcat_test.py | import operator_benchmark as op_bench
import torch
import torch.ao.nn.quantized as nnq
from typing import List
"""Microbenchmarks for quantized Cat operator"""
# Configs for PT Cat operator
qcat_configs_short = op_bench.config_list(
attr_names=['M', 'N', 'K', 'L', 'dim'],
attrs=[
[256, 512, 1, 2, 0]... | 2,035 | 26.890411 | 78 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/channel_shuffle_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for channel_shuffle operator."""
# Configs for PT channel_shuffle operator
channel_shuffle_long_configs = op_bench.cross_product_configs(
batch_size=[4, 8],
channels_per_group=[32, 64],
height=[32, 64],
width=[32, 64],
groups=... | 1,672 | 26.883333 | 88 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/binary_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for binary operators."""
# Benchmark ops performance with broadcast
binary_ops_bcast_list = op_bench.op_list(
attr_names=['op_name', 'op_func'],
attrs=[
['add', torch.add],
],
)
# Configs with broadcast
binary_configs_broadca... | 2,687 | 24.846154 | 83 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/remainder_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for remainder operators."""
# Benchmark ops performance with broadcast
remainder_ops_list = op_bench.op_list(
attr_names=['op_name', 'op_func'],
attrs=[
['fmod', torch.fmod],
['remainder', torch.remainder],
],
)
remai... | 1,752 | 24.779412 | 89 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/batchnorm_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn.functional as F
"""Microbenchmarks for batchnorm operator."""
# Benchmark cudnn if available
if torch.backends.cudnn.is_available:
def cudnn_benchmark_configs(configs):
result = []
for config in configs:
is_cuda = any... | 3,576 | 30.9375 | 110 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qobserver_test.py |
import operator_benchmark as op_bench
import torch
import torch.ao.quantization.observer as obs
qobserver_short_configs_dict = {
'attr_names': ('C', 'M', 'N', 'dtype', 'device'),
'attrs': (
(3, 512, 512, torch.quint8, 'cpu'),
(3, 512, 512, torch.quint8, 'cuda'),
),
'tags': ('short',),
... | 4,284 | 28.349315 | 87 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/linear_test.py |
import operator_benchmark as op_bench
import torch
import torch.nn as nn
from pt import configs
"""Microbenchmarks for Linear operator."""
class LinearBenchmark(op_bench.TorchBenchmarkBase):
def init(self, N, IN, OUT, device):
self.inputs = {
"input_one": torch.rand(N, IN, device=device)
... | 697 | 22.266667 | 85 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/matmul_test.py | import operator_benchmark as op_bench
import torch
"""Microbenchmarks for MatMul operator"""
# Configs for PT Matmul operator
mm_short_configs = op_bench.config_list(
attr_names=["M", "N", "K", "trans_a", "trans_b"],
attrs=[
[1, 1, 1, True, False],
[128, 128, 128, True, False],
[256, 2... | 1,331 | 24.132075 | 78 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/stack_test.py | import operator_benchmark as op_bench
import torch
import random
from typing import List
"""Microbenchmarks for Stack operator"""
# Configs for PT stack operator
stack_configs_static_runtime = op_bench.config_list(
attr_names=['sizes', 'N'],
attrs=[
[(20, 40), 5],
[(1, 40), 5],
],
cro... | 2,811 | 27.40404 | 104 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qunary_test.py |
import operator_benchmark as op_bench
import torch
"""Microbenchmarks for quantized unary operators (point-wise and reduction)."""
# Configs for pointwise and reduction unary ops
qunary_ops_configs_short = op_bench.config_list(
attr_names=['M', 'N'],
attrs=[
[512, 512],
],
cross_product_con... | 5,609 | 30.516854 | 91 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt/qrnn_test.py |
import operator_benchmark as op_bench
import torch
from torch import nn
"""
Microbenchmarks for RNNs.
"""
qrnn_configs = op_bench.config_list(
attrs=[
[1, 3, 1],
[5, 7, 4],
],
# names: input_size, hidden_size, num_layers
attr_names=["I", "H", "NL"],
cross_product_configs={
... | 2,185 | 29.361111 | 80 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt_extension/setup.py | from setuptools import setup
from torch.utils.cpp_extension import CppExtension, BuildExtension
setup(name='benchmark_cpp_extension',
ext_modules=[CppExtension('benchmark_cpp_extension', ['extension.cpp'])],
cmdclass={'build_ext': BuildExtension})
| 261 | 36.428571 | 79 | py |
pytorch | pytorch-main/benchmarks/operator_benchmark/pt_extension/cpp_extension_test.py | import unittest
import benchmark_cpp_extension # noqa: F401
import torch
class TestConsumeOp(unittest.TestCase):
def test_jit_consume_op(self):
iters = 6
def foo(x):
for i in range(iters):
result = torch.ops.operator_benchmark._consume(torch.sum(x))
retur... | 1,174 | 24.543478 | 83 | py |
pytorch | pytorch-main/benchmarks/serialization/nested_annotation_str.py | import torch
import torch.utils.benchmark as benchmark
MEMO = {}
def create_nested_dict_type(layers):
if layers == 0:
return torch._C.StringType.get()
if layers not in MEMO:
less_nested = create_nested_dict_type(layers - 1)
result = torch._C.DictType(torch._C.StringType.get(), torch._C.... | 843 | 34.166667 | 109 | py |
pytorch | pytorch-main/benchmarks/serialization/simple_measurement.py | import torch
from pyarkbench import Benchmark, Timer, default_args
use_new = True
class Basic(Benchmark):
def benchmark(self):
x = [torch.ones(200, 200) for i in range(30)]
with Timer() as big1:
torch.save(x, "big_tensor.zip", _use_new_zipfile_serialization=use_new)
with Timer... | 1,066 | 30.382353 | 85 | py |
pytorch | pytorch-main/caffe2/__init__.py | import warnings
from torch.onnx import _CAFFE2_ATEN_FALLBACK
if not _CAFFE2_ATEN_FALLBACK:
warnings.warn("Caffe2 support is not fully enabled in this PyTorch build. "
"Please enable Caffe2 by building PyTorch from source with `BUILD_CAFFE2=1` flag.")
| 274 | 38.285714 | 101 | py |
pytorch | pytorch-main/caffe2/perfkernels/hp_emblookup_codegen.py |
import argparse
import sys
sizeof = {"float": 4, "at::Half": 2, "at::BFloat16": 2, "uint8_t": 1}
def unroll(uf, IndexType, InType, OutType, use_weights, isa, fused, use_offsets):
def compute(regid, InType, use_weights, isa, prefetch):
code = []
if InType == "float":
code.append(
... | 22,013 | 37.285217 | 137 | py |
pytorch | pytorch-main/caffe2/python/benchmark_generator.py | #!/usr/bin/env python3
import string
import argparse
import numpy as np
from caffe2.python.model_helper import ModelHelper
from caffe2.python.predictor import mobile_exporter
from caffe2.python import core, workspace, brew, utils
def parse_kwarg(kwarg_str):
key, value = map(string.strip, kwarg_str.split("... | 4,910 | 34.586957 | 79 | py |
pytorch | pytorch-main/caffe2/python/scope_test.py |
from caffe2.python import scope, core, workspace
import unittest
import threading
import time
SUCCESS_COUNT = 0
def thread_runner(idx, testobj):
global SUCCESS_COUNT
testobj.assertEquals(scope.CurrentNameScope(), "")
testobj.assertEquals(scope.CurrentDeviceScope(), None)
namescope = "namescope_... | 5,215 | 33.091503 | 87 | py |
pytorch | pytorch-main/caffe2/python/pipeline_test.py |
from caffe2.python.schema import (
Struct, FetchRecord, NewRecord, FeedRecord, InitEmptyRecord)
from caffe2.python import core, workspace
from caffe2.python.session import LocalSession
from caffe2.python.dataset import Dataset
from caffe2.python.pipeline import pipe
from caffe2.python.queue_util import Queue
f... | 2,541 | 31.589744 | 76 | py |
pytorch | pytorch-main/caffe2/python/gradient_checker.py | ## @package gradient_checker
# Module caffe2.python.gradient_checker
import os
import numpy as np
from caffe2.python import core, workspace, net_drawer
from caffe2.proto import caffe2_pb2
def getGradientForOp(op):
return core.GradientRegistry.GetGradientForOp(
op, [s + '_grad' for s in op.output])
... | 15,369 | 38.613402 | 82 | py |
pytorch | pytorch-main/caffe2/python/net_builder_test.py |
from caffe2.python import workspace
from caffe2.python.core import Plan, to_execution_step, Net
from caffe2.python.task import Task, TaskGroup, final_output
from caffe2.python.net_builder import ops, NetBuilder
from caffe2.python.session import LocalSession
import unittest
import threading
class PythonOpStats:
... | 11,358 | 33.111111 | 80 | py |
pytorch | pytorch-main/caffe2/python/control_test.py |
from caffe2.python import control, core, test_util, workspace
import logging
logger = logging.getLogger(__name__)
class TestControl(test_util.TestCase):
def setUp(self):
super().setUp()
self.N_ = 10
self.init_net_ = core.Net("init-net")
cnt = self.init_net_.CreateCounter([],... | 12,259 | 35.927711 | 78 | py |
pytorch | pytorch-main/caffe2/python/session_test.py |
from caffe2.python.schema import (
Struct, FetchRecord, NewRecord, FeedRecord, InitEmptyRecord)
from caffe2.python import core, workspace
from caffe2.python.session import LocalSession
from caffe2.python.dataset import Dataset
from caffe2.python.pipeline import pipe
from caffe2.python.task import TaskGroup
fro... | 2,078 | 31.484375 | 76 | py |
pytorch | pytorch-main/caffe2/python/text_file_reader.py | ## @package text_file_reader
# Module caffe2.python.text_file_reader
from caffe2.python import core
from caffe2.python.dataio import Reader
from caffe2.python.schema import Scalar, Struct, data_type_for_dtype
class TextFileReader(Reader):
"""
Wrapper around operators for reading from text files.
"""
... | 1,990 | 32.745763 | 79 | py |
pytorch | pytorch-main/caffe2/python/muji.py | ## @package muji
# Module caffe2.python.muji
"""muji.py does multi-gpu training for caffe2 with no need to change the c++
side code. Everything is defined on the computation graph level.
We support the following use cases:
- 2 gpus, where peer access is enabled between them.
- 4 gpus, where peer access are enabled... | 8,131 | 29.686792 | 109 | py |
pytorch | pytorch-main/caffe2/python/db_file_reader.py | ## @package db_file_reader
# Module caffe2.python.db_file_reader
from caffe2.python import core, scope, workspace, _import_c_extension as C
from caffe2.python.dataio import Reader
from caffe2.python.dataset import Dataset
from caffe2.python.schema import from_column_list
import os
class DBFileReader(Reader):
... | 6,590 | 35.016393 | 83 | py |
pytorch | pytorch-main/caffe2/python/normalizer_context.py | # @package regularizer_context
# Module caffe2.python.normalizer_context
from caffe2.python import context
from caffe2.python.modifier_context import (
ModifierContext, UseModifierBase)
class NormalizerContext(ModifierContext, context.DefaultManaged):
"""
provide context to allow param_info to have d... | 1,007 | 25.526316 | 70 | py |
pytorch | pytorch-main/caffe2/python/queue_util.py | ## @package queue_util
# Module caffe2.python.queue_util
from caffe2.python import core, dataio
from caffe2.python.task import TaskGroup
import logging
logger = logging.getLogger(__name__)
class _QueueReader(dataio.Reader):
def __init__(self, wrapper, num_dequeue_records=1):
assert wrapper.schema ... | 4,459 | 31.554745 | 81 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.