lovely-tensors is a Python library that provides "syntax sugar" for PyTorch tensors, enhancing their default `repr` for better readability, debugging, and development. It adds features like rich, colored, and pretty-printed output, automatic batching, and shape inference. As of version 0.1.22, it is actively maintained with frequent minor releases focusing on new features and improvements.
pip install lovely-tensorsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import `lovely-tensors`, enable its global monkey-patching for `torch.Tensor`'s `__repr__`, and then print PyTorch tensors to see the enhanced, colored output. It also shows how to use `lt.lovely()` for explicit pretty-printing.
Ensure you have `import lovely_tensors as lt` followed by `lt.monkey_patch()` in your initialization code, typically at the start of your script or notebook.
If conflicts arise, try to import `lovely-tensors` before other potentially conflicting libraries. Alternatively, avoid `lt.monkey_patch()` and use `lt.lovely(tensor_instance)` for explicit pretty-printing when needed, giving you more control.
Update your code to use `lt.monkey_patch()` instead of `lt.init()` for global activation.
Run `pip install lovely-tensors` to install the library.
After `import lovely_tensors as lt`, add `lt.monkey_patch()` to activate the desired behavior.
Instead of `my_tensor.lovely()`, use `lt.lovely(my_tensor)` to explicitly pretty-print the tensor.