Skip to main content

Buy Me A Coffee 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

Metadata

Release files for cudacanvas 1.0.1.post260126

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for cudacanvas 1.0.1.post260126
File
cudacanvas-1.0.1.post260126-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
cudacanvas-1.0.1.post260126-cp311-cp311-manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
cudacanvas-1.0.1.post260126-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
cudacanvas-1.0.1.post260126-cp310-cp310-manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
cudacanvas-1.0.1.post260126-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
cudacanvas-1.0.1.post260126-cp39-cp39-manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details

Total release size: 571.4 kB

Release files / cudacanvas-1.0.1.post260126-cp311-cp311-win_amd64.whl

Download URL cudacanvas-1.0.1.post260126-cp311-cp311-win_amd64.whl
Size 101.8 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
b68b28e13fbb1957a5e119bac3d7cf5bced6e7abe9c180633e2e7a150eb2f94c
BLAKE2b-256 checksum
How to use checksums
8105afc2751ada3c8f23b798e6437c31ed92cb0fb63daeebba655fc450481217
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post260126-cp311-cp311-manylinux2014_x86_64.whl

Download URL cudacanvas-1.0.1.post260126-cp311-cp311-manylinux2014_x86_64.whl
Size 90.7 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
98c32064358b8a521504f8f47c58e3db5e2768a2162bd7914b31a4cec50a1684
BLAKE2b-256 checksum
How to use checksums
ad28436338254198d44b0f15328d0a77cfec8b489636b4b82108c3409972b1d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post260126-cp310-cp310-win_amd64.whl

Download URL cudacanvas-1.0.1.post260126-cp310-cp310-win_amd64.whl
Size 100.6 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
a988bc720b9d8b3ade47ed05c548182c2d647c74f9dee58258ba5bd5cc5c2911
BLAKE2b-256 checksum
How to use checksums
6f9fd7faa4e7a08d04708743ff750a98948a1a2f8cc2a16a6846d0752c1e949f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post260126-cp310-cp310-manylinux2014_x86_64.whl

Download URL cudacanvas-1.0.1.post260126-cp310-cp310-manylinux2014_x86_64.whl
Size 89.0 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5ceccd1f2b974f52d0bec887b0a7e6d8817db7c7bb0a94e2c45c5f615e99161d
BLAKE2b-256 checksum
How to use checksums
1586aa1436dd89eba94baf2d55d6f2dcc53b0112e32f12f6edc7617851f45e9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post260126-cp39-cp39-win_amd64.whl

Download URL cudacanvas-1.0.1.post260126-cp39-cp39-win_amd64.whl
Size 101.1 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
4eabf742a2def065140abbe82e91f7c5c3d6766c23bee09eba71627291f1dc67
BLAKE2b-256 checksum
How to use checksums
807f285f9605ea0973b91ffaf50cc8f996b93a0b13fba5b971051637d99c073a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / cudacanvas-1.0.1.post260126-cp39-cp39-manylinux2014_x86_64.whl

Download URL cudacanvas-1.0.1.post260126-cp39-cp39-manylinux2014_x86_64.whl
Size 88.3 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
3187d9218b3c93d5246553c30e7225fb9d14137f7c087d65c15886a573ab824d
BLAKE2b-256 checksum
How to use checksums
80165049214f22c7394706315bf51c0096ca93e0b71da7e50568a9b835137971
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page