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.post231121-cp311-cp311-win_amd64.whl (99.1 kB view details)

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.9 Windows x86-64

cudacanvas-1.0.1.post231121-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.post231121-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 96ddaca119a533a0c2d4674260b4a16017759338ac6aa50d43247d25ec51077d
MD5 3927f5a8e0eec75a34dffc0e17c91ba9
BLAKE2b-256 4d75debf92199d9f919120c62ab88809f6fdb6402ce9f95946571643cb621803

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b68f98433bdfde3ef0f8c45a6735aca43910e49219fc778a3631e47f28b88db8
MD5 6f2b7609f188701bfb62e8b2504fb8f8
BLAKE2b-256 dc15451779844231b6e3e70c80e1372800111f8ed77a650d0cee9fc40577b382

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 79c09706b19b5e719089b6d2864bb6aab274a183ad1a84c32670755809fad4e8
MD5 cee5995c0a32ce815954d691fe61f936
BLAKE2b-256 544b1014fb088032b7ec9a009cb256616f4c4b70f700693b8ce60a82b72f263c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 110f710684523fa756f13cf7d5a142537ca43061c0b2cbd897348a3ea2e24f68
MD5 9d243b6c5df5697f97d8ff482e4da8c3
BLAKE2b-256 4a6f25dc3a5a8f1415a99c6c16341c8bf93ddb52de81dc098de573102a93ba19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 eca692fbafbac923a41e60142282adafbed17bdb90518e9c3305938b6c8a3fa4
MD5 2dbfe72bcb0246a7a5788fd486769e59
BLAKE2b-256 5b310c7134750576051b59e9085e72ca5f29cbad324bdf86dec0d6885cd546c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ba75fffc861bd73cdc588e5c4a64389344c303eb2395c76775709a28a80d508
MD5 7c7a575adf9b7bb13ee0978bf721cd6f
BLAKE2b-256 c47e68542e4726561b334de3fd0378a4db18f1255b0283247f0a1594f61236ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 dff11c2c86c62cced4e8486d8f9b4787db9b47e73c2311f15c7038267a7904a2
MD5 8e8b806913e736ae34a3e70435373306
BLAKE2b-256 ea1564ae879e3d346a7950a7b509b2c33db83c83af81563c0331d596c330e8ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post231121-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a5bb7f0d6fea8beec0f8ae5d4c31111420af585dfb52a958cb4836c280345205
MD5 8da21a38650dc6963bc01e9839669a4c
BLAKE2b-256 f0a09a2161053b2dfc42f7baa355f78a0e93b577fd496f52a9a81541cf9ac975

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