Python Customized Tracebacks
Project description
Python Customized Tracebacks
Synopsis
import torch
import pyctb
# show custom render functions for types
pyctb.inventory()
tf: Render a tf.Tensor, tf.Variable, or EagerTensor
torch: Render a torch.Tensor or torch.nn.parameter.Parameter
# add the torch render function
pyctb.add('torch')
conv = torch.nn.Conv1d(5, 5, 10)
inp = torch.zeros([5, 100])
# This will produce an exception and traceback (see below)
conv(inp)
# Turn on the custom traceback
pyctb.on()
# This will produce an exception and a custom traceback
# showing argument values
conv(inp)
pyctb.off()
Currently, the render inventory consists of renderers for PyTorch and Tensorflow tensors and some of their derived types.
# The default traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/henry/miniconda3/envs/pytorch181/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/henry/miniconda3/envs/pytorch181/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 263, in forward
return self._conv_forward(input, self.weight, self.bias)
File "/home/henry/miniconda3/envs/pytorch181/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 259, in _conv_forward
return F.conv1d(input, weight, bias, self.stride,
RuntimeError: Expected 3-dimensional input for 3-dimensional weight [5, 5, 10], but got 2-dimensional input of size [5, 100] instead
# The custom traceback:
Custom Traceback (most recent call last):
<module>()
File "<stdin>", line 1, in <module>
torch.nn.modules.module._call_impl(self=Conv1d(5, 5, kernel_size=(10,), stride=(1,)), input[0]=[5,100]:float32:cpu)
File "/home/henry/miniconda3/envs/pytorch181/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
torch.nn.modules.conv.forward(self=Conv1d(5, 5, kernel_size=(10,), stride=(1,)), input=[5,100]:float32:cpu)
File "/home/henry/miniconda3/envs/pytorch181/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 263, in forward
return self._conv_forward(input, self.weight, self.bias)
torch.nn.modules.conv._conv_forward(self=Conv1d(5, 5, kernel_size=(10,), stride=(1,)), input=[5,100]:float32:cpu, weight=[5,5,10]:float32:cpu, bias=[5]:float32:cpu)
File "/home/henry/miniconda3/envs/pytorch181/lib/python3.9/site-packages/torch/nn/modules/conv.py", line 259, in _conv_forward
return F.conv1d(input, weight, bias, self.stride,
RuntimeError: Expected 3-dimensional input for 3-dimensional weight [5, 5, 10], but got 2-dimensional input of size [5, 100] instead
See https://github.com/hrbigelow/pyctb for more.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyctb-0.0.2.tar.gz
(4.1 kB
view hashes)
Built Distribution
pyctb-0.0.2-py3-none-any.whl
(4.8 kB
view hashes)