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

Uploaded CPython 3.11 Windows x86-64

cudacanvas-1.0.1.post240118-cp310-cp310-win_amd64.whl (98.0 kB view details)

Uploaded CPython 3.10 Windows x86-64

cudacanvas-1.0.1.post240118-cp39-cp39-win_amd64.whl (98.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

cudacanvas-1.0.1.post240118-cp38-cp38-win_amd64.whl (99.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4f2636010d97601e123300632d331c61980996443262c72c4ac66d892d98a4a3
MD5 216b66eaef51550570cf6d485432f9e1
BLAKE2b-256 21f1b3f7eb64c1ebc400b790aad04fa9b95670db8f42d31d421cdf310e90175a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d623d9854c64006551a988b4850451e580310589d9e8491b1ebcfddef25e8563
MD5 855c370285cb65cf954f18224a1442f8
BLAKE2b-256 6a8a70836ee6c726aa82df79c669106fc7203a45fd01bfc75c80e0463a2a9afa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 406b7df0f0d1972e8fd2a8961d0120e082c8307740de52bd2ae6e7c3a31c72fb
MD5 ad5a4c1a3f7d190bdb98ebff02436d2c
BLAKE2b-256 881f162eccefdd027a9e6f0fa04374fb7f82e03e34c19a287c2effadcaaf1405

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 810b83341281fdfd3f3e79066250fda3379b4827c6fb346b8d4821148d4ab4a2
MD5 23df3c434f175f22df2ac0d708b0a70a
BLAKE2b-256 eb6e94b0293acd40ce031cae059659c80b3ca465be43227dfd3b1404d84308e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7f0184434cd9ad18843d603d6f700a1dc7eb25d5b7c38ab0f8ffb05e4ddb1d45
MD5 41e51199e8574f7823f3c91062c215f6
BLAKE2b-256 c9f0e1ef9f0bf921573a278b9ab2206649a3239b8f462e8118cb26c8b0c43d93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3dcb97851eaf67468bd857ce98055a047a25e9a93dc6cafc7bc3d2cb3a856114
MD5 6a6a0b0067a3918dbb8bc3f3001c32ba
BLAKE2b-256 738137811c66c70e36644fbebfb5ecb7fa557c8be0df28c0d0bd14d03435dcb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3b97efb1bf79bfe543f0f437ad4dcc0d890371e1874d8db933ea056f020b4472
MD5 dcbf51f70d3e97bd9f0f4c0bf4d9a584
BLAKE2b-256 b8f40237cda4b6be800fcafb1842cf3438128679b5803ea9ef8fa56d6e2eeb47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240118-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb05efe7a77c891818f49fa4e054d0d72e94dcf8a2e1eb253c01c8193c365891
MD5 6af4617a442c1ab5d7ab9a312b62325d
BLAKE2b-256 74f5e2871d06a6ed25859a7a8a47faa7b4c2e1ee57a6d67f5d48cf9143656407

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