Skip to main content

Real-time PyTorch Tensor Visualisation in CUDA, Eliminating CPU Transfer

Project description

Buy Me A Coffee Twitter Twitter PyPI version Downloads

image

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 2.2.2+cu121 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

cudacanvas-1.0.1.post231118-cp311-cp311-win_amd64.whl (99.1 kB view details)

Uploaded CPython 3.11 Windows x86-64

cudacanvas-1.0.1.post231118-cp310-cp310-win_amd64.whl (98.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

cudacanvas-1.0.1.post231118-cp39-cp39-win_amd64.whl (99.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

cudacanvas-1.0.1.post231118-cp38-cp38-win_amd64.whl (100.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

Details for the file cudacanvas-1.0.1.post231118-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2af8492216d6df8fcde000c2a925385ed08ca57f3789acc18377547a1064a512
MD5 e665e91078fc970212e7c2ba1aa1524e
BLAKE2b-256 6588731dc119d9532dd60020d2545767b0f4dbf487031f019c18756a0abdf516

See more details on using hashes here.

File details

Details for the file cudacanvas-1.0.1.post231118-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b14acfb02e5cf33d7e7cf71b6c378ec30b58c2a9143ffd5b9d823ebac2886d2d
MD5 45f2cf8cae8fd4236c147a9520c56c49
BLAKE2b-256 5ebe3e16c0febd14e20b2cdaa30a1fd4974f7da658b02ab4d21b63ff7478358d

See more details on using hashes here.

File details

Details for the file cudacanvas-1.0.1.post231118-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 62ca1813b1263e298cebd9d0a1bb5d130fd8346b09e648796a6bfa553a97beb3
MD5 d69dc7f8696af07f0bf2d1fbb4cc97e1
BLAKE2b-256 3135c0660cd15de6e552c54a4d4ab4633816b41adb2ce4a55eaf9dd9f2c4123f

See more details on using hashes here.

File details

Details for the file cudacanvas-1.0.1.post231118-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7cd7dffc0b34491eed7e52934291b96ab32496bee9b4f0d446c0c9236a3a7142
MD5 18e271381114ac24e5428810f29380ae
BLAKE2b-256 5370c2f303e06a920c06266a8fbc589f4d5bed565a589fa72502828fc348f06b

See more details on using hashes here.

File details

Details for the file cudacanvas-1.0.1.post231118-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4790b8f0189d12e753b99971c0cc593cea65c335dfd58527941d86bc71ba6f2e
MD5 ef433414258c37b992307602df800415
BLAKE2b-256 e08e479d13b7c6d5e029075951260e119a3219e0d484e2d597c8f5fdd91a7026

See more details on using hashes here.

File details

Details for the file cudacanvas-1.0.1.post231118-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2eb94735aa58476a08b56d5d7658c869f8bdf56573ad6c9a8ca2a8dda6110ced
MD5 19d38c124a09cdce6650007275a33818
BLAKE2b-256 2928723777bd5e6cfa492ee4bf17fb1e51589aa50e8125c7a793aaa608faec39

See more details on using hashes here.

File details

Details for the file cudacanvas-1.0.1.post231118-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a66cb966fc7ff23cea53b7f9bee561e8d912f87949f9acd2332f1dce02f0d25c
MD5 599250d1d4c95aca98e930dc1da63312
BLAKE2b-256 479f18312199cc95a7b6aa2ccb9d52ba375da9baebab2e9de7a024a2d2fdfc3c

See more details on using hashes here.

File details

Details for the file cudacanvas-1.0.1.post231118-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231118-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9b1b187350c0d85bf4405003866cfb1c8efdf31af58079bf9d2cd57dad23284
MD5 3ace34726851650573065fad3f72741f
BLAKE2b-256 bff8f76aa8083db8fee72b36711db471adab01a2fa8d8c887e17287fd3ff314e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page