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 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


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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.10 Windows x86-64

cudacanvas-1.0.1.post241121-cp39-cp39-win_amd64.whl (98.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

cudacanvas-1.0.1.post241121-cp38-cp38-win_amd64.whl (99.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0a145ba6dc99adbd7b8c1edd4ad9cca805722e3265555f358e5f12ad5ab97d20
MD5 a18348b5488328ed00d376c4e22c09cb
BLAKE2b-256 553f85a19d0d11027d7d2bc56fb323212165c94eba1b066f1b3295cb6476ac3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7205f6e50ecac1291f67978e9d38b868be74edf280b438ba5e0b063a4e344e4b
MD5 277aa2318ffb5126681f5494c6d49c23
BLAKE2b-256 d770c681b7fa09903fec1dd5477e5c486bcb3a0b9cf55f2b607fe94507ebc851

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 12abc81e2be761532fa710e1410c0605452e79495e4981e0326f45b4f06ba0af
MD5 c06a9b9166e8875e7f5544fc2e04f4b7
BLAKE2b-256 78fd9365051b5f30a5f7fbcf4bc18b2b47682176e8e18f25cd2275aedc08ff79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc29890c4cd278e0fd3fe9eefc31f325a568623e82402832eeb323576d09bb75
MD5 5c633b61f99752714c826abbd8a8f6e9
BLAKE2b-256 51f72911a6136176f611ac389b20f0e2a70cd163ed9e15d988c4f14093bdbadf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6d9252898fa266699a5dfca226bb571239b2349b21d8731815bf3162be294f7c
MD5 ba58ee53bd7bba981a05fb0b73d182d0
BLAKE2b-256 a025ca30a0d5377d8a066aebd8915981b7f100533b04d7f5d5aa7c5b73a55bc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8645d0abfcc68d7a2e47acfbfa0c58001d90c32defa3b137711fcaeb17f10a8e
MD5 360bd40b3a6dd26bef6d5f3ba9ab7b5f
BLAKE2b-256 5298989812a6c30be393f0af53262ceff6022605a29b05853134d53b42df03b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 4fafdbfc95392d61952d17d4da30795e4223392302f591b52aef06be5f083119
MD5 b85b2faca56ac6271f2b27f1bf1862e9
BLAKE2b-256 df40b2fd9954b3909da068d737e7eff36e1af1e38c33b40672380dc2247fce33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241121-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89b3bf9a1eaf4d69ef6e9a90f82bf5853bb2603abd33a7f42d1a623a7a1047f6
MD5 925121ca035a69d5f3a692dddc99eb1f
BLAKE2b-256 27b4a07f85f0cb59577655f2e39929c7abc70c1ccd64b9732911e2d4e466340d

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