Real-time PyTorch Tensor Visualisation in CUDA, Eliminating CPU Transfer
Project description
cudacanvas : PyTorch Tensor Image Display in CUDA
(Real-time PyTorch Tensor Image Visualisation in CUDA, Eliminating CPU Transfer)
CudaCanvas is a simple Python module that eliminates CPU transfer for Pytorch tensors for displaying and rendering images in the training or evaluation phase, ideal for machine learning scientists and engineers.
Simplified version that directly displays the image without explicit window creation (cudacanvas >= v1.0.1)
import torch
import cudacanvas
#REPLACE THIS with you training loop
while (True):
#REPLACE THIS with you training code and generation of data
noise_image = torch.rand((4, 500, 500), device="cuda")
#Visualise your data in real-time
cudacanvas.im_show(noise_image)
#OPTIONAL: Terminate training when the window is closed
if cudacanvas.should_close():
cudacanvas.clean_up()
#end process if the window is closed
break
You can visualise the latent of Stable Diffusion during sampling in real-time whilst waiting for the steps to finish
import warnings
warnings.filterwarnings("ignore")
from diffusers import StableDiffusionPipeline
import torch
import cudacanvas
def display_tensors(pipe, step, timestep, callback_kwargs):
latents = callback_kwargs["latents"]
with torch.no_grad():
image = pipe.vae.decode(latents / pipe.vae.config.scaling_factor, return_dict=False)[0]
image = image - image.min()
image = image / image.max()
cudacanvas.im_show(image.squeeze(0))
if cudacanvas.should_close():
cudacanvas.clean_up()
pipe._interrupt = True
return callback_kwargs
pipeline = StableDiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base",
torch_dtype=torch.float16,
variant="fp16"
).to("cuda")
image = pipeline(
prompt="A croissant shaped like a cute bear.",
negative_prompt="Deformed, ugly, bad anatomy",
callback_on_step_end=display_tensors,
callback_on_step_end_tensor_inputs=["latents"],
).images[0]
cudacanvas.clean_up()
Installation
Before instllation make sure you have torch with cuda support already installed on your machine
We aligned pytorch and cuda version with our package the supporting packages are torch (2.0.1, 2.1.2 and 2.2.2) and (11.8 and 12.1)
Identify your current torch and cuda version
import torch
torch.__version__
Depending on your torch and cuda you can install the relevant cudacanvas package, for the latest one matching the latest pytorch package you can simply download the latest package
pip install cudacanvas
For other torch and cuda packages put the torch and cuda version after that cudacanvas version for example for 2.1.2+cu118 the Cudacanvas package you require is 1.0.1.post212118
pip install cudacanvas==1.0.1.post212118 --force-reinstall
Support
Also support my channel ☕ ☕ : https://www.buymeacoffee.com/outofai
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for cudacanvas-1.0.1.post250121-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a07cb59e254977d69fe9bb2b05a744fe705a9ec3519010baa012378234cf8b3 |
|
MD5 | 7dd5db87c7b99f13c26707e1d7b245b2 |
|
BLAKE2b-256 | a9fac6f13e76b0e02bc562692467d9cf3a7a1cd066d8a1edbdce76f50bccd3d6 |
Hashes for cudacanvas-1.0.1.post250121-cp311-cp311-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e455708f0042f471d3a4e7bf7d402e827f014e4788809feffc0aafdfe1972246 |
|
MD5 | 0b8072693d5defc6a9c00f8de76100b6 |
|
BLAKE2b-256 | c1779c639dd0a519db52513846f8dedf24272ae6d4d59f8eb72ec4cc5d7b5cc2 |
Hashes for cudacanvas-1.0.1.post250121-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ca36d64483c045661cf712464bf82a6b7b70cc3a7f62acfbcc8784ed549635a |
|
MD5 | 0edbfb78fedc220639179b5c217ab2ac |
|
BLAKE2b-256 | c146453247b643c0997c0b34c9269f572ebc9f3597dd225eaad1bc51e02c4ec6 |
Hashes for cudacanvas-1.0.1.post250121-cp310-cp310-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26cc0a2113ae01b5631b58a1774448a2c45887c5b65993c21d6bbf51047ee871 |
|
MD5 | 748cbdc2410ca88a04b2ab22b2ef33f9 |
|
BLAKE2b-256 | a6f66ffbe23c58bc58381377a1bc00fa99256b2e3dc02eb75bf14089e1f05c4c |
Hashes for cudacanvas-1.0.1.post250121-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c8a37e7d77b801e053a24a7f583b3358135991edc10db1e58612e74581c239b |
|
MD5 | 3e6868230274b4f8d3dfe1918a897d4f |
|
BLAKE2b-256 | 095ac64894559f6b96682c901fe0980ccae5e85c89f5f5e9fb0906ea1bc439d9 |
Hashes for cudacanvas-1.0.1.post250121-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a15898cdf3050a189ae401616b073d353ef9c44ee6e7d72343927542c0af4382 |
|
MD5 | 044b9f3746878bde07877def743ccc12 |
|
BLAKE2b-256 | 6b51aa886f416d471bda5d1d38409b0dc44ff9476e4f5ff66f66a1a5b1d9d807 |