{"id":9907,"library":"lovely-tensors","title":"Lovely Tensors","description":"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.","status":"active","version":"0.1.22","language":"en","source_language":"en","source_url":"https://github.com/xl0/lovely-tensors","tags":["pytorch","tensor","debugging","developer-tool","pretty-printing","visualization"],"install":[{"cmd":"pip install lovely-tensors","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"lovely-tensors extends PyTorch's tensor functionality and requires a compatible PyTorch version to operate.","package":"torch","optional":false}],"imports":[{"note":"The common alias `lt` is widely used in examples and makes the code more concise.","symbol":"lovely_tensors","correct":"import lovely_tensors as lt"},{"note":"Calling `lt.monkey_patch()` directly is necessary to enable the enhanced `__repr__` for PyTorch tensors globally.","wrong":"import lovely_tensors.monkey_patch # This doesn't activate it","symbol":"monkey_patch","correct":"import lovely_tensors as lt\nlt.monkey_patch()"},{"note":"Use `lt.lovely()` for explicit, controlled pretty-printing of a tensor, or when monkey-patching is not desired.","symbol":"lovely","correct":"import lovely_tensors as lt\nlt.lovely(my_tensor)"}],"quickstart":{"code":"import torch\nimport lovely_tensors as lt\n\n# Enable beautiful tensor repr globally\nlt.monkey_patch()\n\n# Create some tensors\na = torch.randn(2, 3, 4)\nb = torch.randint(0, 10, (1, 5), dtype=torch.int)\n\nprint(f\"Tensor a:\\n{a}\")\nprint(f\"Tensor b:\\n{b}\")\n\n# You can also explicitly print lovely tensors without monkey-patching\n# For demonstration, let's pretend monkey_patch wasn't called:\n# import lovely_tensors as lt\n# lt.lovely(torch.tensor([1,2,3]))","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"To activate the enhanced `__repr__` for PyTorch tensors automatically, you must explicitly call `lovely_tensors.monkey_patch()` after importing the library. Simply importing `lovely_tensors` is not enough.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"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.","message":"lovely-tensors modifies the `__repr__` method of `torch.Tensor` instances. If you are using other debugging tools or libraries that also monkey-patch `torch.Tensor`'s `__repr__`, this might lead to conflicts or unexpected display behavior.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Update your code to use `lt.monkey_patch()` instead of `lt.init()` for global activation.","message":"Older versions of lovely-tensors used `lovely_tensors.init()` for activation. This method has been replaced by `lovely_tensors.monkey_patch()` for clarity and consistency.","severity":"deprecated","affected_versions":"<0.1.18"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install lovely-tensors` to install the library.","cause":"The `lovely-tensors` library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'lovely_tensors'"},{"fix":"After `import lovely_tensors as lt`, add `lt.monkey_patch()` to activate the desired behavior.","cause":"The `monkey_patch()` function was not called, which is necessary to enable the global `__repr__` enhancement.","error":"PyTorch tensors are not displaying with pretty colors or enhanced information, even after importing lovely_tensors."},{"fix":"Instead of `my_tensor.lovely()`, use `lt.lovely(my_tensor)` to explicitly pretty-print the tensor.","cause":"You are trying to access `lovely` as a method directly on a `torch.Tensor` instance, but `lovely` is a function provided by the `lovely_tensors` module, not a tensor method.","error":"AttributeError: 'Tensor' object has no attribute 'lovely'"}]}