Skip to main content

print_torch

It is often overwhelming to print(tensor) which may flash your screen and you just don't get any information useful.

Instead, use pt(tensor) and it will give you the size, dtype, device, min, max, std, mean, whether has nan, etc. in one line.

>>> import torch
>>> from print_torch import pt
>>> tensor = torch.randn((2,3,4,5))
>>> pt(tensor)
tensor(shape=(2, 3, 4, 5), dtype=float32, min=-2.803, max=2.49, std=1.019, mean=-0.06855, data=[-0.8246, -1.135, 0.1368, 1.56, ... ], device="cpu")                                  >>>

It also works for list of numbers and numpy tensors.

If you have a nested dict/list of pytorch/numpy tensors, you can also pt it, and it will list each element which may be again a tensor in one line.

For example, you can just pt(locals()) in your forward() function in the breakpoint to know all the stats of your local variables.

Don't hesitate to add this tool to your arsenal!

pip install print_torch

Metadata

Release files for print-torch 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for print-torch 1.3
File Size Uploaded
print_torch-1.3.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for print-torch 1.3
File Interpreter ABI Platform
print_torch-1.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release history Release notifications | RSS feed

This release

1.3 This release

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page