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 |
|---|---|---|---|---|---|---|
torch2trt | torch2trt-master/torch2trt/converters/identity.py | from torch2trt.torch2trt import *
@tensorrt_converter('torch.Tensor.contiguous')
@tensorrt_converter('torch.nn.functional.dropout')
@tensorrt_converter('torch.nn.functional.dropout2d')
@tensorrt_converter('torch.nn.functional.dropout3d')
def convert_functional_identity(ctx):
input = ctx.method_args[0]
if not ... | 865 | 31.074074 | 64 | py |
torch2trt | torch2trt-master/torch2trt/converters/softmax.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.Tensor.softmax')
@tensorrt_converter('torch.nn.functional.softmax')
def convert_softmax(ctx):
input = ctx.method_args[0]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.... | 1,426 | 27.54 | 69 | py |
torch2trt | torch2trt-master/torch2trt/converters/split.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.split')
@tensorrt_converter('torch.Tensor.split')
def convert_split(ctx):
input = get_arg(ctx, 'input', 0, None)
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
# we don't need to pa... | 2,791 | 32.238095 | 89 | py |
torch2trt | torch2trt-master/torch2trt/converters/adaptive_max_pool3d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.nn.functional.adaptive_max_pool3d")
def convert_adaptive_max_pool3d(ctx):
input = ctx.method_args[0]
output = ctx.method_return
output_size = ctx.method_args[1]
if isinstance(output_size, in... | 1,255 | 28.904762 | 77 | py |
torch2trt | torch2trt-master/torch2trt/converters/ConvTranspose2d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.nn.ConvTranspose2d.forward", enabled=trt_version() < '7.0')
def convert_ConvTranspose2d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
input_trt = add_missing_trt_tensors(ctx.network... | 2,617 | 36.942029 | 189 | py |
torch2trt | torch2trt-master/torch2trt/converters/mul.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.mul')
@tensorrt_converter('torch.Tensor.mul_')
@tensorrt_converter('torch.Tensor.__imul__')
@tensorrt_converter('torch.Tensor.__mul__')
@tensorrt_converter('torch.Tensor.__rmul__')
def convert_mul(ctx):
... | 2,891 | 25.290909 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/example_plugin.py | import torch
import torch.nn as nn
from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
import numpy as np
import ctypes
try:
ctypes.CDLL('libtorch2trt_plugins.so')
def create_example_plugin(scale):
registry = trt.get_plugin_registry()
creator = registry.get_pl... | 1,597 | 27.535714 | 73 | py |
torch2trt | torch2trt-master/torch2trt/converters/getitem.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
def slice_to_trt(ctx, dim_size, dim_slice):
start = 0 if dim_slice.start is None else dim_slice.start
stop = dim_size if dim_slice.stop is None else dim_slice.stop
stride = 1 if dim_slice.step is None else dim_slice.s... | 5,696 | 28.671875 | 110 | py |
torch2trt | torch2trt-master/torch2trt/converters/activation.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
from .unary import UnaryModule
# | RELU : Rectified Linear activation (impl in relu.py)
# | SIGMOID : Sigmoid activation (impl in sigmoid.py)
# | TANH : Hyperbolic Tangent activation (impl in tanh.py)
# | LEAKY_RELU... | 4,328 | 34.77686 | 141 | py |
torch2trt | torch2trt-master/torch2trt/converters/roll.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.roll')
@tensorrt_converter('torch.Tensor.roll')
def convert_roll(ctx):
input = get_arg(ctx, 'input', 0, None)
shifts = get_arg(ctx, 'shifts', 1, None)
dims = get_arg(ctx, 'dims', 2, None)
... | 2,301 | 28.512821 | 87 | py |
torch2trt | torch2trt-master/torch2trt/converters/BatchNorm2d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.nn.BatchNorm2d.forward", enabled=trt_version() < '7.0')
def convert_BatchNorm2d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
input_trt = add_missing_trt_tensors(ctx.network, [inpu... | 771 | 31.166667 | 87 | py |
torch2trt | torch2trt-master/torch2trt/converters/instance_norm.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
def _add_scale_1d2d3d(network, x_trt, mode, offset, scale, power):
ndim = len(x_trt.shape)
y_trt = x_trt
# shape to 2D
if ndim != 4:
layer = network.add_shuffle(y_trt)
layer.reshape_dims = (x_... | 5,909 | 38.139073 | 158 | py |
torch2trt | torch2trt-master/torch2trt/converters/mean.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.mean')
@tensorrt_converter('torch.Tensor.mean')
def convert_mean(ctx):
input = ctx.method_args[0]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.method_return
... | 2,066 | 30.318182 | 87 | py |
torch2trt | torch2trt-master/torch2trt/converters/min.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
from .unary import UnaryModule
def __convert_min_elementwise(ctx):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
output = ctx.method_return
input_a_trt, input_b_trt = add_missing_trt_tensors(ctx.network, [i... | 2,813 | 37.027027 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/floordiv.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.Tensor.__floordiv__')
@tensorrt_converter('torch.Tensor.__ifloordiv__')
@tensorrt_converter('torch.floor_divide')
def convert_floordiv(ctx):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
... | 2,918 | 34.597561 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/add.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.add')
@tensorrt_converter('torch.Tensor.__iadd__')
@tensorrt_converter('torch.Tensor.__add__')
@tensorrt_converter('torch.Tensor.__radd__')
def convert_add(ctx):
input_a = ctx.method_args[0]
input_b ... | 2,864 | 25.045455 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/mod.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.fmod')
def convert_mod(ctx):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
output = ctx.method_return
input_a_trt, input_b_trt = add_missing_trt_tensors(ctx.network, [input_a, inp... | 4,033 | 38.940594 | 118 | py |
torch2trt | torch2trt-master/torch2trt/converters/AdaptiveAvgPool3d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter(
"torch.nn.AdaptiveAvgPool3d.forward", enabled=trt_version() >= "7.0"
)
def convert_AdaptiveAvgPool3d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
output = ctx.method_return
inp... | 1,397 | 27.530612 | 77 | py |
torch2trt | torch2trt-master/torch2trt/converters/gelu.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
import math
@tensorrt_converter('torch.nn.functional.gelu')
def convert_gelu_v1(ctx):
# approximate equation 1 from paper
input = get_arg(ctx, 'input', 0, None)
output = ctx.method_return
x, c05, c1, cs2pi, c044, ... | 2,309 | 35.666667 | 92 | py |
torch2trt | torch2trt-master/torch2trt/converters/pow.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.pow')
@tensorrt_converter('torch.Tensor.__ipow__')
@tensorrt_converter('torch.Tensor.__pow__')
def convert_pow(ctx):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
output = ctx.method_... | 2,643 | 27.430108 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/getitem_test.py | import pytest
import torch
import torch.nn as nn
from torch2trt import torch2trt, trt
class YOLOXFocusTestModule(nn.Module):
def forward(self, x):
patch_top_left = x[..., ::2, ::2]
patch_top_right = x[..., ::2, 1::2]
patch_bot_left = x[..., 1::2, ::2]
patch_bot_right = x[..., 1::... | 4,595 | 26.854545 | 90 | py |
torch2trt | torch2trt-master/torch2trt/converters/Linear.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.linear')
def convert_Linear(ctx):
input = ctx.method_args[0]
weight = get_arg(ctx, 'weight', 1, None)
bias = get_arg(ctx, 'bias', 2, None)
input_trt = add_missing_trt_tensors(ct... | 1,674 | 33.895833 | 88 | py |
torch2trt | torch2trt-master/torch2trt/converters/chunk.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
from .split import convert_split
@tensorrt_converter('torch.chunk')
@tensorrt_converter('torch.Tensor.chunk')
def convert_chunk(ctx):
convert_split(ctx)
class TorchChunk(torch.nn.Module):
def __init__(self, *arg... | 2,155 | 32.169231 | 87 | py |
torch2trt | torch2trt-master/torch2trt/converters/BatchNorm1d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.BatchNorm1d.forward')
def convert_BatchNorm1d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.method_... | 1,409 | 34.25 | 114 | py |
torch2trt | torch2trt-master/torch2trt/converters/max_pool1d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.max_pool1d')
def convert_max_pool1d(ctx):
# At the time of this implementation, TensorRT 8.x does not yet support max pooling in 1D using `add_pooling_nd(...)`.
# As such, we use a work... | 3,777 | 36.405941 | 134 | py |
torch2trt | torch2trt-master/torch2trt/converters/Conv2d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.nn.Conv2d.forward", enabled=trt_version() < '7.0')
def convert_Conv2d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
... | 2,199 | 30.884058 | 105 | py |
torch2trt | torch2trt-master/torch2trt/converters/sum.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
from .unary import UnaryModule
from torch import nn
@tensorrt_converter('torch.sum')
@tensorrt_converter('torch.Tensor.sum')
def convert_sum(ctx):
input = ctx.method_args[0]
dim = get_arg(ctx, 'dim', pos=1, default=tuple(range(... | 1,970 | 36.188679 | 108 | py |
torch2trt | torch2trt-master/torch2trt/converters/clamp.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
def _add_clamp_val(network, trt_input, val, op):
# create TensorRT constant for minimum value
val_shape = (1, ) * len(trt_input.shape) # broadcast all dimensions
val_tensor = val * torch.ones(val_shape, dtype=torch_dtype_... | 7,705 | 30.453061 | 133 | py |
torch2trt | torch2trt-master/torch2trt/converters/expand.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.Tensor.expand')
def convert_expand(ctx):
input = ctx.method_args[0]
if not hasattr(input, '_trt'):
return
sizes = ctx.method_args[1:]
output = ctx.method_return
ins... | 1,691 | 31.538462 | 113 | py |
torch2trt | torch2trt-master/torch2trt/converters/cat.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.cat')
def convert_cat(ctx):
inputs = get_arg(ctx, 'input', pos=0, default=None)
dim = get_arg(ctx, 'dim', pos=1, default=0)
# Reverse negative dims.
if dim < 0:
dim = len(inputs[0].s... | 1,547 | 31.25 | 107 | py |
torch2trt | torch2trt-master/torch2trt/converters/dummy_converters.py | from torch2trt.torch2trt import *
def is_private(method):
method = method.split('.')[-1] # remove prefix
return method[0] == '_' and method[1] != '_'
def is_function_type(method):
fntype = eval(method + '.__class__.__name__')
return fntype == 'function' or fntype == 'builtin_function_or_method' or ... | 1,114 | 28.342105 | 106 | py |
torch2trt | torch2trt-master/torch2trt/converters/AdaptiveAvgPool2d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.AdaptiveAvgPool2d.forward')
def convert_AdaptiveAvgPool2d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
output = ctx.method_return
input_trt = add_missing_trt_tensors(c... | 1,238 | 29.975 | 93 | py |
torch2trt | torch2trt-master/torch2trt/converters/compare.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
def convert_elementwise(ctx, op):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
output = ctx.method_return
input_a_trt, input_b_trt = add_missing_trt_tensors(ctx.network, [input_a, input_b])
input_a_trt,... | 4,293 | 28.613793 | 146 | py |
torch2trt | torch2trt-master/torch2trt/converters/reflection_pad_2d.py | import torch
import torch.nn as nn
from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
import numpy as np
import ctypes
try:
ctypes.CDLL('libtorch2trt_plugins.so')
def create_reflection_pad_2d_plugin(paddingLeft, paddingRight, paddingTop, paddingBottom):
registry = tr... | 2,494 | 32.716216 | 94 | py |
torch2trt | torch2trt-master/torch2trt/converters/flatten.py | import tensorrt as trt
import numpy as np
from torch2trt.torch2trt import tensorrt_converter, get_arg, torch_dim_resolve_negative, add_missing_trt_tensors, torch_dim_to_trt_axes
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.flatten')
@tensorrt_converter('torch.Tensor.flatten')
def conve... | 1,630 | 36.068182 | 135 | py |
torch2trt | torch2trt-master/torch2trt/converters/transpose.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.Tensor.transpose", enabled=trt_version() < '7.0')
@tensorrt_converter("torch.transpose", enabled=trt_version() < '7.0')
def convert_transpose(ctx):
input = ctx.method_args[0]
input_trt = add_missing_... | 2,707 | 34.631579 | 77 | py |
torch2trt | torch2trt-master/torch2trt/converters/max_pool2d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.max_pool2d')
def convert_max_pool2d(ctx):
# parse args
input = get_arg(ctx, 'input', pos=0, default=None)
kernel_size = get_arg(ctx, 'kernel_size', pos=1, default=None)
stride =... | 1,836 | 33.660377 | 82 | py |
torch2trt | torch2trt-master/torch2trt/converters/max.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
from .unary import UnaryModule
def __convert_max_elementwise(ctx):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
output = ctx.method_return
input_a_trt, input_b_trt = add_missing_trt_tensors(ctx.network, [i... | 2,813 | 37.027027 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/BatchNorm3d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.nn.BatchNorm3d.forward", enabled=trt_version() < "7.0")
def convert_BatchNorm3d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
input_trt = add_missing_trt_tensors(ctx.network, [inpu... | 1,007 | 33.758621 | 93 | py |
torch2trt | torch2trt-master/torch2trt/converters/clone.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.clone')
@tensorrt_converter('torch.Tensor.clone')
def convert_clone(ctx):
input = ctx.method_args[0]
input_trt = trt_(ctx.network, input)
# Clone by making identity layer.
layer = ctx.networ... | 1,529 | 23.285714 | 84 | py |
torch2trt | torch2trt-master/torch2trt/converters/view.py | from torch2trt.torch2trt import *
# from torch2trt.shape_conversion import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.Tensor.view')
@tensorrt_converter('torch.Tensor.reshape')
def convert_view(ctx):
input = ctx.method_args[0]
if not hasattr(input, '_trt'):
return
... | 1,791 | 29.896552 | 93 | py |
torch2trt | torch2trt-master/torch2trt/converters/relu6.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.relu6')
def convert_functional_relu6(ctx):
ctx.method_args = (torch.nn.ReLU6(),) + ctx.method_args
convert_relu6(ctx)
@tensorrt_converter('torch.nn.ReLU6.forward')
def convert_relu6(c... | 1,212 | 28.585366 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/conv_functional.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.conv2d', enabled=trt_version() >= '7.0')
@tensorrt_converter('torch.nn.functional.conv3d', enabled=trt_version() >= '7.0')
def convert_Conv_trt7_functional(ctx):
input = get_arg(ctx, 'input... | 4,453 | 33.796875 | 108 | py |
torch2trt | torch2trt-master/torch2trt/converters/matmul.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.matmul")
@tensorrt_converter("torch.Tensor.__matmul__")
def convert_matmul(ctx):
x = ctx.method_args[0]
y = ctx.method_args[1]
z = ctx.method_return
x_trt, y_trt = add_missing_trt_tensors(ct... | 723 | 22.354839 | 71 | py |
torch2trt | torch2trt-master/torch2trt/converters/prod.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
from .unary import UnaryModule
@tensorrt_converter('torch.prod')
@tensorrt_converter('torch.Tensor.prod')
def convert_prod(ctx):
input = ctx.method_args[0]
dim = get_arg(ctx, 'dim', pos=1, default=tuple(range(1, len(input.... | 1,462 | 36.512821 | 109 | py |
torch2trt | torch2trt-master/torch2trt/converters/adaptive_max_pool2d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.adaptive_max_pool2d')
def convert_adaptive_max_pool2d(ctx):
input = ctx.method_args[0]
output = ctx.method_return
output_size = ctx.method_args[1]
if isinstance(output_size, in... | 1,146 | 30 | 95 | py |
torch2trt | torch2trt-master/torch2trt/converters/permute.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.Tensor.permute')
def convert_permute(ctx):
input = ctx.method_args[0]
if not hasattr(input, '_trt'):
return
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
out... | 2,379 | 35.060606 | 90 | py |
torch2trt | torch2trt-master/torch2trt/converters/silu.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.silu')
def convert_silu(ctx):
input = get_arg(ctx, 'input', pos=0, default=None)
output = ctx.method_return
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
lay... | 791 | 36.714286 | 102 | py |
torch2trt | torch2trt-master/torch2trt/converters/div.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.div')
@tensorrt_converter('torch.Tensor.__div__') # py2
@tensorrt_converter('torch.Tensor.__idiv__') # py2
@tensorrt_converter('torch.Tensor.__truediv__') # py3
@tensorrt_converter('torch.Tensor.__itruediv__... | 3,524 | 27.427419 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/sub.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.sub')
@tensorrt_converter('torch.Tensor.__isub__')
@tensorrt_converter('torch.Tensor.__sub__')
def convert_sub(ctx):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
output = ctx.method_... | 3,332 | 27.008403 | 112 | py |
torch2trt | torch2trt-master/torch2trt/converters/unary.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
def __convert_unary(ctx, op):
input = get_arg(ctx, 'input', pos=0, default=None)
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.method_return
layer = ctx.network.add_unary(input_trt, ... | 6,929 | 23.661922 | 66 | py |
torch2trt | torch2trt-master/torch2trt/converters/max_pool3d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.nn.functional.max_pool3d")
@tensorrt_converter("torch.max_pool3d")
def convert_max_pool3d(ctx):
# parse args
input = get_arg(ctx, "input", pos=0, default=None)
kernel_size = get_arg(ctx, "kernel_... | 1,876 | 32.517857 | 82 | py |
torch2trt | torch2trt-master/torch2trt/converters/tanh.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.tanh')
@tensorrt_converter('torch.tanh')
def convert_tanh(ctx):
input = ctx.method_args[0]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.method_return
... | 561 | 30.222222 | 74 | py |
torch2trt | torch2trt-master/torch2trt/converters/stack.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
def unsqueeze(ctx, input, dim):
layer = ctx.network.add_shuffle(trt_(ctx.network, input))
shape = input.shape[:dim] + (1,) + input.shape[dim:]
layer.reshape_dims = tuple(shape)
return layer.get_output(0)
@tensorrt_... | 1,882 | 28.888889 | 120 | py |
torch2trt | torch2trt-master/torch2trt/converters/adaptive_avg_pool3d.py | from torch2trt.torch2trt import *
from .AdaptiveAvgPool3d import *
@tensorrt_converter("torch.nn.functional.adaptive_avg_pool3d")
def convert_adaptive_avg_pool3d(ctx):
ctx.method_args = (
torch.nn.AdaptiveAvgPool3d(ctx.method_args[1]),
ctx.method_args[0],
)
convert_AdaptiveAvgPool3d(ctx)
| 319 | 25.666667 | 62 | py |
torch2trt | torch2trt-master/torch2trt/converters/layer_norm.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.layer_norm')
def convert_layernorm(ctx):
input = get_arg(ctx, 'input', 0, None)
shape = get_arg(ctx, 'normalized_shape', 1, None)
weight = get_arg(ctx, 'weight', 2, None)
bias =... | 3,767 | 35.582524 | 105 | py |
torch2trt | torch2trt-master/torch2trt/converters/Conv1d.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.Conv1d.forward')
def convert_Conv1d(ctx):
module = ctx.method_args[0]
input = ctx.method_args[1]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.method_return
... | 2,370 | 33.362319 | 87 | py |
torch2trt | torch2trt-master/torch2trt/converters/adaptive_avg_pool2d.py | from torch2trt.torch2trt import *
from .AdaptiveAvgPool2d import *
@tensorrt_converter('torch.nn.functional.adaptive_avg_pool2d')
def convert_adaptive_avg_pool2d(ctx):
ctx.method_args = (torch.nn.AdaptiveAvgPool2d(ctx.method_args[1]), ctx.method_args[0])
convert_AdaptiveAvgPool2d(ctx)
| 296 | 32 | 90 | py |
torch2trt | torch2trt-master/torch2trt/converters/group_norm.py | import torch.nn as nn
from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.group_norm')
def convert_group_norm(ctx):
input = get_arg(ctx, 'input', pos=0, default=None)
num_groups = get_arg(ctx, 'num_group... | 3,179 | 33.193548 | 103 | py |
torch2trt | torch2trt-master/torch2trt/converters/relu.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.relu')
@tensorrt_converter('torch.relu_')
@tensorrt_converter('torch.nn.functional.relu')
@tensorrt_converter('torch.nn.functional.relu_')
@tensorrt_converter('torch.Tensor.relu')
def convert_functional_relu... | 1,388 | 26.78 | 71 | py |
torch2trt | torch2trt-master/torch2trt/converters/avg_pool.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter("torch.nn.functional.avg_pool2d", enabled=trt_version() < '7.0')
def convert_avg_pool2d(ctx):
# parse args
input = get_arg(ctx, "input", pos=0, default=None)
kernel_size = get_arg(ctx, "kernel_size", po... | 4,301 | 37.410714 | 170 | py |
torch2trt | torch2trt-master/torch2trt/converters/ConvTranspose.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.ConvTranspose2d.forward', enabled=trt_version() >= '7.0')
@tensorrt_converter('torch.nn.ConvTranspose3d.forward', enabled=trt_version() >= '7.0')
def convert_ConvTranspose2d_trt7(ctx):
module = ctx.me... | 2,927 | 35.6 | 105 | py |
torch2trt | torch2trt-master/torch2trt/converters/normalize.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.normalize')
def convert_normalize(ctx):
# get args
input = get_arg(ctx, 'input', pos=0, default=None)
p = get_arg(ctx, 'p', pos=1, default=2)
dim = get_arg(ctx, 'dim', pos=2, de... | 2,756 | 40.149254 | 139 | py |
torch2trt | torch2trt-master/torch2trt/converters/narrow.py | import tensorrt as trt
from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.Tensor.narrow')
@tensorrt_converter('torch.narrow')
def convert_narrow(ctx):
inputs = get_arg(ctx, 'input', pos=0, default=None)
start = get_arg(ctx, 'start', pos=2, default=... | 1,369 | 32.414634 | 127 | py |
torch2trt | torch2trt-master/torch2trt/converters/pad.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.pad')
def convert_pad(ctx):
input = ctx.method_args[0]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.method_return
pad = ctx.method_args[1]
... | 920 | 26.909091 | 73 | py |
torch2trt | torch2trt-master/torch2trt/converters/tensor.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.tensor')
def convert_mod(ctx):
output = ctx.method_return
layer = ctx.network.add_constant(tuple(output.shape), output.detach().cpu().numpy() )
output._trt = layer.get_output(0)
class TorchTens... | 649 | 27.26087 | 90 | py |
torch2trt | torch2trt-master/torch2trt/converters/prelu.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.prelu')
def convert_prelu(ctx):
input = get_arg(ctx, 'input', pos=0, default=None)
weight = get_arg(ctx, 'weight', pos=1, default=None)
output = ctx.method_return
weight_sh... | 1,779 | 36.87234 | 148 | py |
torch2trt | torch2trt-master/torch2trt/converters/LogSoftmax.py | from torch2trt.torch2trt import *
@tensorrt_converter('torch.nn.LogSoftmax.forward')
def convert_LogSoftmax(ctx):
input = ctx.method_args[1]
input_trt = add_missing_trt_tensors(ctx.network, [input])[0]
output = ctx.method_return
layer = ctx.network.add_softmax(input=input_trt)
layer = ctx.network.... | 433 | 35.166667 | 64 | py |
torch2trt | torch2trt-master/torch2trt/converters/Conv.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.Conv2d.forward', enabled=trt_version() >= '7.0')
@tensorrt_converter('torch.nn.Conv3d.forward', enabled=trt_version() >= '7.0')
def convert_Conv_trt7(ctx):
module = ctx.method_args[0]
input = ctx.... | 3,256 | 34.402174 | 108 | py |
torch2trt | torch2trt-master/torch2trt/converters/interpolate.py | import torch.nn.functional as F
import torch.nn as nn
from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
import collections
def has_interpolate_plugin():
try:
from torch2trt.torch_plugins import InterpolatePlugin
return True
exc... | 8,404 | 42.549223 | 134 | py |
torch2trt | torch2trt-master/torch2trt/converters/sigmoid.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.nn.functional.sigmoid')
@tensorrt_converter('torch.sigmoid')
@tensorrt_converter('torch.Tensor.sigmoid')
def convert_sigmoid(ctx):
input = ctx.method_args[0]
input_trt = add_missing_trt_tensors(ctx.n... | 916 | 26.787879 | 77 | py |
torch2trt | torch2trt-master/torch2trt/converters/ne.py | from torch2trt.torch2trt import *
from torch2trt.module_test import add_module_test
@tensorrt_converter('torch.ne')
@tensorrt_converter('torch.Tensor.__ne__')
def convert_ne(ctx):
input_a = ctx.method_args[0]
input_b = ctx.method_args[1]
output = ctx.method_return
input_a_trt, input_b_trt = add_missin... | 1,579 | 27.727273 | 112 | py |
dct_vae | dct_vae-main/run_experiment.py | import os
import torch
import numpy as np
import os.path as osp
import wandb
import copy
from pprint import pprint
import hydra.utils
from hydra.utils import instantiate
import omegaconf
from torch.nn.parallel.distributed import DistributedDataParallel
import torch.distributed as dist
import utils.trainer as trainer
i... | 9,117 | 36.065041 | 113 | py |
dct_vae | dct_vae-main/datasets/mnists.py | import numpy as np
import torch
from torch.utils.data import random_split, DataLoader, Dataset
from torch.utils.data.distributed import DistributedSampler
from torchvision import transforms
from torchvision import datasets
import hydra
import os
from utils.distributed_training import get_rank, mpi_size, is_main_process... | 4,715 | 37.032258 | 118 | py |
dct_vae | dct_vae-main/datasets/omniglot.py | import torch
from torchvision import datasets
from torchvision.datasets.mnist import read_image_file, read_label_file
from torch.utils.data import random_split, TensorDataset, Dataset
from PIL import Image
import os
from torchvision import transforms
import urllib
from scipy.io import loadmat
from datasets.mnists impo... | 3,674 | 33.669811 | 118 | py |
dct_vae | dct_vae-main/datasets/cifar10.py | import numpy as np
import torch
from torch.utils.data import random_split
from torchvision import transforms
from torchvision import datasets
import hydra
import os
from datasets.mnists import MNIST
from datasets.dct import DCT_dataset
from datasets.svhn import Normalize
class CIFAR10(MNIST):
def __init__(self, b... | 1,765 | 39.136364 | 118 | py |
dct_vae | dct_vae-main/datasets/svhn.py | import numpy as np
import torch
from torch.utils.data import random_split
from torchvision import transforms
from torchvision import datasets
import os
from datasets.mnists import MNIST
from datasets.dct import DCT_dataset
from PIL import Image
class Normalize:
def __init__(self, dequant=False, num_bits=8):
... | 2,508 | 32.453333 | 118 | py |
dct_vae | dct_vae-main/datasets/dct.py | import math
import os
import torch
import torch.nn as nn
import numpy as np
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms
import torch.nn.functional as F
def RGB_to_YCBCR(x):
# [-1, 1] to [0, 1]
x = (x+1)/2
# PIL image
x_pil = transforms.ToPILImage(mode='RGB')(x)
... | 7,236 | 36.497409 | 111 | py |
dct_vae | dct_vae-main/utils/tester.py | import torch
import numpy as np
import wandb
from tqdm import tqdm
def test(args, loader, model):
model.eval()
history = {}
with torch.no_grad():
for batch_idx, batch in tqdm(enumerate(loader)):
for i in range(len(batch)):
# batch[i] = batch[i].to(args.device)
... | 1,662 | 29.796296 | 76 | py |
dct_vae | dct_vae-main/utils/notebook_helpers.py | import os
import wandb
import torch
import numpy as np
from torchvision import transforms
from torchvision.transforms.functional import to_pil_image
from PIL import Image
from utils.wandb import api, get_checkpoint
nice_fonts = {
"text.usetex": True,
"font.family": "serif",
"font.serif" : "Times New Roma... | 2,185 | 25.337349 | 90 | py |
dct_vae | dct_vae-main/utils/distribution.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import math
import numpy as np
# from utils.flow_layers import AffineCoupling1d, AffineCoupling2d
from utils.nn import Siren
# from utils.arm_layers import CausalConv1d, GatedResidualLayer
class Distribution(nn.Module):
def __init__(self):
... | 9,955 | 32.521886 | 139 | py |
dct_vae | dct_vae-main/utils/nn.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from utils.thirdparty.blurpool import BlurPool
class Siren(nn.Module):
def __init__(self):
super(Siren, self).__init__()
self.w_0 = nn.Parameter(torch.ones(1), requires_grad=True)
def forward(self, x):
return torch.sin(... | 4,520 | 33.25 | 105 | py |
dct_vae | dct_vae-main/utils/wandb.py | import wandb
import os
import torch
import omegaconf
from hydra.utils import instantiate
api = wandb.Api()
def get_checkpoint(wandb_args, idx, device='cpu'):
# download the checkpoint from wandb to the local machine.
file = wandb.restore('last_chpt.pth',
run_path=os.path.join(wandb_... | 1,704 | 31.169811 | 72 | py |
dct_vae | dct_vae-main/utils/vae_layers.py | import torch.nn as nn
from utils.nn import _ResBlock, ConvBlock
class EncoderResBlock(_ResBlock):
def __init__(self, in_channels, hid_channels, out_channels, activation,
weight_norm, batch_norm, stride=1, num_blocks=2, use_res=True):
super(EncoderResBlock, self).__init__(in_channels, out... | 2,972 | 35.703704 | 95 | py |
dct_vae | dct_vae-main/utils/distributed_training.py | # """
# Code from https://github.com/openai/vdvae/blob/ea35b490313bc33e7f8ac63dd8132f3cc1a729b4/utils.py#L117
# """
import os
import socket
import torch
import torch.distributed as dist
import omegaconf
#
# # Change this to reflect your cluster layout.
# # The GPU for a given rank is (rank % GPUS_PER_NODE).
GPUS_PER_N... | 2,343 | 24.758242 | 103 | py |
dct_vae | dct_vae-main/utils/trainer.py | import torch
import math
import time
import os
import numpy as np
import datasets.dct
import wandb
import torch
from torch.optim import Adamax, AdamW
from torch.optim.lr_scheduler import ReduceLROnPlateau, CosineAnnealingLR, CyclicLR
import torch.nn.functional as F
import torch.distributed as dist
from hydra.utils imp... | 8,569 | 38.675926 | 102 | py |
dct_vae | dct_vae-main/utils/thirdparty/blurpool.py | # source: https://github.com/adobe/antialiased-cnns/blob/master/antialiased_cnns/blurpool.py
# Copyright (c) 2019, Adobe Inc. All rights reserved.
#
# This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike
# 4.0 International Public License. To view a copy of this license, visit
# https:/... | 4,496 | 37.110169 | 143 | py |
dct_vae | dct_vae-main/utils/thirdparty/pytorch_msssim.py | # https://github.com/AKuzina/defend_vae_mcmc/tree/main/thirdparty/pytorch_msssim
import torch
import torch.nn.functional as F
from math import exp
import numpy as np
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size//2)**2/float(2*sigma**2)) for x in range(window_size)])
return gau... | 5,005 | 32.597315 | 118 | py |
dct_vae | dct_vae-main/utils/thirdparty/unet.py | from abc import abstractmethod
import math
import numpy as np
import torch as th
import torch.nn as nn
import torch.nn.functional as F
from utils.nn import conv_nd
# UNet implemenatation from https://github.com/openai/guided-diffusion
def timestep_embedding(timesteps, dim, max_period=10000):
"""
Create sin... | 25,741 | 35.154494 | 124 | py |
dct_vae | dct_vae-main/model/context_ladder_vae.py | import math
import matplotlib.pyplot as plt
import numpy as np
import torch
import torchvision
import wandb
import torch.nn as nn
import torch.nn.functional as F
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.cm as cm
from matplotlib.colors import Normalize
from model.vae import LADDER_VAE, ... | 1,645 | 28.927273 | 64 | py |
dct_vae | dct_vae-main/model/context_decoder.py | import math
from typing import Optional, Union
import torch.nn as nn
import torch
import torch.nn.functional as F
import numpy as np
from utils.vae_layers import DecoderResBlock
from datasets.dct import DCT
from utils.distribution import Normal, Delta
from model.ddgm import DiffusionPrior, DiffusionDCTPrior
from utils... | 12,805 | 37.806061 | 105 | py |
dct_vae | dct_vae-main/model/encoder.py | import torch.nn as nn
import torch
from utils.vae_layers import EncoderResBlock
from utils.thirdparty.blurpool import BlurPool
class _Encoder(nn.Module):
def __init__(self):
super(_Encoder, self).__init__()
def init(self) -> None:
for m in self.modules():
if isinstance(m, nn.Batch... | 9,663 | 34.399267 | 84 | py |
dct_vae | dct_vae-main/model/vae.py | import math
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchmetrics
import torchvision
import wandb
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.cm as cm
from matplotlib.colors import Normalize
from utils.dis... | 17,187 | 38.512644 | 119 | py |
dct_vae | dct_vae-main/model/decoder.py | import math
from typing import Optional, Union
import torch.nn as nn
import torch
import torch.nn.functional as F
import numpy as np
from hydra.utils import instantiate
from utils.vae_layers import DecoderResBlock
from datasets.dct import DCT, YCBCR_to_RGB
from utils.distribution import Normal, Delta
from model.ddgm i... | 19,209 | 39.527426 | 122 | py |
dct_vae | dct_vae-main/model/plain_decoder.py | import math
from typing import Optional, Union
import torch.nn as nn
import torch
from utils.vae_layers import DecoderResBlock
class _Decoder(nn.Module):
def __init__(self):
super(_Decoder, self).__init__()
def init(self) -> None:
for m in self.modules():
if isinstance(m, nn.Batch... | 3,274 | 29.045872 | 77 | py |
dct_vae | dct_vae-main/model/ddgm.py | import torch
import torch.nn as nn
import numpy as np
import math
from utils.distribution import Normal
def _extract_into_tensor(arr, timesteps, broadcast_shape):
"""
Extract values from a 1-D numpy array for a batch of indices.
:param arr: the 1-D numpy array.
:param timesteps: a tensor of indices ... | 18,457 | 40.478652 | 148 | py |
ATISE | ATISE-master/model.py | # -*- coding: utf-8 -*-
"""
Created on Fri Mar 1 13:27:48 2019
@author: 86187
"""
import torch
import numpy as np
import torch.nn as nn
from torch.nn.init import xavier_normal_
from torch.nn import functional as F
from torch.autograd import Variable
from numpy.random import RandomState
class TeRo(n... | 26,618 | 44.580479 | 146 | py |
ATISE | ATISE-master/Train.py | # -*- coding: utf-8 -*-
"""
Created on Fri Mar 1 16:11:52 2019
@author: 86187
"""
import model as KGE
from Dataset import KnowledgeGraph
from Dataset_YG import KnowledgeGraphYG
import torch
import numpy as np
from time import time
from sklearn.utils import shuffle as skshuffle
import os
def mean_rank(rank):
m... | 12,810 | 31.35101 | 143 | py |
pyslam | pyslam-master/feature_superpoint.py | """
* This file is part of PYSLAM
*
* Copyright (C) 2016-present Luigi Freda <luigi dot freda at gmail dot com>
*
* PYSLAM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
... | 4,782 | 37.572581 | 137 | py |
pyslam | pyslam-master/feature_d2net.py | """
* This file is part of PYSLAM
* Adapted from https://github.com/mihaidusmanu/d2-net/blob/master/extract_features.py, see the license therein.
*
* Copyright (C) 2016-present Luigi Freda <luigi dot freda at gmail dot com>
*
* PYSLAM is free software: you can redistribute it and/or modify
* it under the terms of th... | 7,800 | 38.005 | 144 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.