Instantly share code, notes, and snippets.

View gist:85ee59c0a99c669f83c5a4498884dd27
x tensor([[-0.0052, 0.0273, -0.0487, -0.0387, -0.0410]], dtype=torch.float32)
w tensor([[ -95, -11, -36, 60, -30],
[ 83, 127, -109, 46, -54],
[-128, -91, -12, 101, -98],
[ -83, -29, -6, -105, 95],
[ 99, -6, 48, 29, -87]], dtype=torch.int8)
zero_point -2
scale 0.003393471473827958
calc w tensor([[-0.3156, -0.0305, -0.1154, 0.2104, -0.0950],
[ 0.2884, 0.4378, -0.3631, 0.1629, -0.1765],
View gist:66e7130b28fcf8dda02ce7d98fe20c5b
import torch
class SomeMod(torch.jit.ScriptModule):
@torch.jit.script_method
def _unpack(self):
return torch.zeros(3, 4)
@torch.jit.script_method
def forward(self):
return torch.zeros(3, 4)
View gist:cbe2ec25bcdc0975b3019a5de07af41e
Overwriting already registered item for key CPU
Overwriting already registered item for key CUDA
Overwriting already registered item for key HIP
I1204 09:59:24.175752 2085676 NmtBenchmark.cpp:160] Benchmarking language_technology.translation.nmt.model.en_XX-ms_MY:4091e69
I1204 09:59:35.191941 2085676 DecoderLib.cpp:88] C2 NMT Decoder is initialized
I1204 09:59:35.227789 2085676 Loader.cpp:222] Warming up RawTranslationService for en_XX-ms_MY
terminate called after throwing an instance of 'torch::jit::script::ErrorReport'
what():
arguments for call are not valid:
View gist:0c26ce67c2718fabf7f3e3b7b7dad13c
Traceback (most recent call last):
File "test/test_jit.py", line 5888, in test_module_pack_unpack
imported = self.getExportImportCopy(tm)
File "test/test_jit.py", line 281, in getExportImportCopy
torch.jit.save(imported, buffer)
File "/Users/jamesreed/onnx-fairseq/pytorch/torch/jit/__init__.py", line 143, in save
ret = m.save_to_buffer()
RuntimeError:
a leaf Variable that requires grad has been used in an in-place operation. (check_inplace at ../torch/csrc/autograd/VariableTypeUtils.h:49)
frame #0: c10::Error::Error(c10::SourceLocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 64 (0x107d861f0 in libc10.dylib)
View tup.py
import torch
class FooMod(torch.nn.Module):
def forward(self, x, tup):
return x + tup[0]
traced = torch.jit.trace(FooMod(), (torch.rand(3, 4), (torch.rand(3, 4), torch.rand(4))))
print(traced.graph)
===
View gist:0e663fc73ab363444ba5cfe2b9ec514a
RuntimeError:
expand(CPUDoubleType{[3, 4]}, size=[]): the number of sizes provided (0) must be greater or equal to the number of dimensions in the tensor (2) (expand at ../aten/src/ATen/native/TensorShape.cpp:280)
View gist:24c2a2af171907b02d13c4ae333774fe
import torch
def foo(x):
return x.new_tensor([3]).cpu()
traced = torch.jit.trace(foo, (torch.LongTensor([3, 4, 5])))
print(traced.graph)
View gist:d3fcf1b1defd8913e9f7d4b5d8a866ce
======================================================================
ERROR: test_ge (__main__.TestJit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test_jit.py", line 1443, in test_ge
ge = torch._C.GraphExecutor(foo, (a, b))
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. torch._C.GraphExecutor(func: function, inputs: tuple, var_name_lookup_fn: function, optimize: bool = True)
2. torch._C.GraphExecutor(graph: torch::jit::Graph, optimize: bool = True)
View gist:a5834221595d928cbd3c619ac46b8b6c
======================================================================
ERROR: test_trace_records_names (__main__.TestJit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/jamesreed/onnx-fairseq/pytorch/test/common_utils.py", line 559, in assertExpected
with open(expected_file) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/jamesreed/onnx-fairseq/pytorch/test/expect/TestJit.test_trace_records_names.expect'
During handling of the above exception, another exception occurred:
View gist:f5b76352bc60a9ac91a4b6b2b515fac6
.................................................s.ss.s.s.s.s..sFsFssssss........s.ss...F.s.....test/test_jit.py:1922: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than tensor.new_tensor(sourceTensor).
return x.new_tensor(x[0]).cpu() + x
.s.ssss.sclang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
warning: pytorch jit fuser failed to compile with openmp, trying without it...
.........x.sss.Fx.s......s.....F...s...............s....s.s...............................................................................................................................................................................................................................................................................................................................................................................................................................................