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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 86ebb10093eedeede5ac525f9e26e8a042d248a58616fe85776e7724f82d95ed
MD5 9021aa494935785d0db294191a25b7ec
BLAKE2b-256 8e9945b2481363fc510f41e5154a0edf24563590e136192d6f33648cc0296f2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0644098050d81e4344bd3cf087bc79607a9d510c3b7e9bf7f9fadfe77f5b6d30
MD5 25c13152b765bdebe2e61b92c623afbd
BLAKE2b-256 0f53b946681afb4fdb24f5f896c2126d34734f545c90786f46bcb8437eec8d1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 38ec73cf3f02b8cc0504bc4ed234ec8e5b44ee848d86fea633938da7164418a5
MD5 967e1d9a2bbef073f0a50d55b93113db
BLAKE2b-256 36c6b55f45694baa8e8d2f07172c125c4b990ff954246def7a5f672d736e941c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5bf005b76ea61d27784ea5a9c963f1bfa73f0551247b20962672dbe9cee62ce
MD5 cf8e42586a0db052a043ce20559da95a
BLAKE2b-256 ef15e7debd70c4929b63545769399b36ff32cbf4790b8fb172e5fe83720cf865

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 377f2c169ac9ca713f6489f0dffa3fed7fe074d567ca920a68d0c6e900137e6c
MD5 cc7a601fe145fbaf604a16bee46a0531
BLAKE2b-256 89fd04491debf56226257824629e8b731acb6c6d8b88019cf34b63cf23cd2212

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c7a745f0eb17c0ac8864726d0dd888cb40e357074f7d3a5d4407d21474a33a1
MD5 ff2a571d687c483b768758920d4d0d95
BLAKE2b-256 81dd1e91b0ab2ff5770d4db1d5758d539c9441848522381a4838c9fc152c6ec1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 da16525ce351ba046c532fc7d748a9d4aa73d11d810f0f16e07a4534dac6d608
MD5 5b5bc1391597fcee1a069f68a88a4f40
BLAKE2b-256 15ab1c824aa78406b3dddeca73d8e2a3b4620fcc0a5ef62b597db9d90c88aa99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cudacanvas-1.0.1.post240121-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86b2c4ee98dbdaee97e05d0281f2cd287a15bd7b212e6b332ce98ac32e031880
MD5 d5b3910102232d84c13ffb6c1bd2cdbd
BLAKE2b-256 bbef9053b6ec8a0e416f729fa04646bd1385f5db386138068266409578c7c4bd

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