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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 746c6410d1a93e9395b31ca42ee75691b4ebb86890b05675e128fdc2480be94c
MD5 717eba3a3aca1f14297a859d23e3ddb6
BLAKE2b-256 288538b904411875ff95b5e3eb79ebf937ffbf38df19af2287fb852b06ec61ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d126dd05c0ef185a0d29d166929108aff5efe6588df22dae07c897597aee5ea
MD5 2b4429054540bb64048c2aac499653ff
BLAKE2b-256 b36386250c73f3eeed4229a0260ad8d5fd2cbecde06d4c1a60a1274369f72b59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3844df6bcb3d1578f4758c2f7d0f00404ea891a01a182193e1e9484ec3e063cf
MD5 4c23caeb3dc865f6778917d80da8b430
BLAKE2b-256 9ed342c10b96b105858fb5076f3926ce770e2cb680c220fbc413ea717b759b17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 12e5fa3b534e3d939e5ae51e5e81167785ec7310337c26a34f84afaec0e076e9
MD5 b9d86aa26e3cbb68dd79ebfdcb97aadd
BLAKE2b-256 9bbc6cbd11382377567fd9026b24a49b60401c6fd4b7199bb8adcf0cafc5241b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3c15cc0e5808f44b37740a1bb6b858d286120f24f332bd282f722dbb957aa424
MD5 c5c534f148bc90a9f94deb94416a85c2
BLAKE2b-256 943b3fea8ae202b176c786e5e605a788eb5562981e2782d4d63fe4a76177b056

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80c04750f1a1ead89a5805df254ce0d9d9ae7e300f4837a3a47aba29721df842
MD5 d505a1bfcd802dcfb9465b49f2528f86
BLAKE2b-256 8a1351e8b66228e38a435bdc6f96f4cbe26e86ae97fe89ff07ffe902a9d8af5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ba9188b1c690ad6a258f932f8678d326403238b54a45377c436b125b55889639
MD5 8d7c69f55b6f138fb8726f7c90b1ce7f
BLAKE2b-256 04f72bd76de1160619ba2c9e5e1a9ce5fe127a51ba77afb6e8f39c88537defe4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post241118-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 472a65e1b5299c5baed5782ce17cfdd6a856c4dfb4fef3132f7c9fbb25be8a7a
MD5 a480865327caa4b885e7d521bce54310
BLAKE2b-256 1391dae2b545484edb4b55945644a32ef99d6a95d8caaf945c7efe4dbf8a3a1b

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