Visualize PyTorch tensors directly in neovim while debugging with nvim-dap. Powered by image.nvim and lovely-tensors.
dispynvim_demo_720p.mov
While you're debugging your Python code, dispy.nvim lets you
- View PyTorch tensors as images directly in your terminal
- Sample and plot multiple images from a batch
- Visualize statistical plots of tensor values
- and more!
- Neovim 0.10.x
- nvim-dap - Debug Adapter Protocol client for Neovim
- image.nvim - used to display images in Kitty
- PyTorch - tensor package
- lovely-tensors - takes care of some of the plotting / statistical functionality automatically
Install like you would any other neovim plugin.
Using lazy.nvim:
{
"cmmcirvin/dispy.nvim",
dependencies = {
"mfussenegger/nvim-dap",
"3rd/image.nvim"
}
}
Default setup:
require("dispynvim").setup({
n_images = 4, -- Number of images to extract from batched tensors
cell_aspect_ratio = 18/40, -- Cell aspect ratio (18/40 on MacOS)
scale = 0.5, -- Scale of the images to be displayed
})
It is also recommended to define several keymaps.
vim.keymap.set({'n', 'v'}, '<leader>pi', ':lua require("dispynvim").display_single_image()<CR>')
vim.keymap.set({'n', 'v'}, '<leader>pl', ':lua require("dispynvim").display_random_images()<CR>')
vim.keymap.set({'n', 'v'}, '<leader>ps', ':lua require("dispynvim").plot_statistics()<CR>')
vim.keymap.set({'n', 'v'}, '<leader>pt', ':lua require("dispynvim").print_statistics()<CR>')
dispy.nvim also uses the luafilesystem
library, which can be installed via luarocks
.
You should also ensure torch
, matplotlib
and lovely-tensors
are installed and accessible by your running Python program.
- Currently, the plugin has been tested on MacOS only.
- Extend support to numpy arrays / pandas dataframes
- Add additional plotting capabilities
- The current method for executing code (by directly calling the nvim-dap repl) is a bit hacky and can impact the state of the currently running program