Skip to main content

Fusing Taichi into PyTorch

Project description

Stannum

Gradient Tests

Fusing Taichi into PyTorch

PRs are always welcomed, please see TODOs and issues.

Why Stannum?

In differentiable rendering including neural rendering, rendering algorithms are transferred to the field of computer vision, but some rendering operations (e.g., ray tracing and direct volume rendering) are not easy to be expressed in tensor operations but in kernels. Differentiable kernels of Taichi enables fast, efficient and differentiable implementation of rendering algorithms while tensor operators provides math expressiveness.

Stannum bridges Taichi and PyTorch to have advantage of both kernel-based and operator-based parallelism.

Documentation and Usage

Please see documentation.

Code sample of Tube:

import taichi as ti
import torch

@ti.kernel
def mul(arr: ti.template(), out: ti.template()):
    for i in arr:
        out[i] = arr[i] * 2.0


if __name__ == "__main__":
    ti.init(ti.cpu)
    a = torch.ones(10, requires_grad=True)
    tube = Tube() \
        .register_input_tensor((10,), torch.float32, "arr") \
        .register_output_tensor((10,), torch.float32, "out", True) \
        .register_kernel(mul, ["arr", "out"]) \
        .finish()
    out = tube(a)
    loss = out.sum()
    loss.backward()
    assert torch.allclose(out, torch.ones_like(out) * 2)
    assert torch.allclose(a.grad, torch.ones_like(a) * 2)

Installation & Dependencies

Install stannum with pip by

python -m pip install stannum

Make sure you have the following installed:

  • PyTorch
  • latest Taichi
    • For performance concerns, we strongly recommend to use Taichi >= 1.1.3 (see Issue #9 for more information)

Bugs & Issues

Please feel free to file issues. If a runtime error occurs from the dependencies of stannum, you may also want to check the upstream breaking change tracker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stannum-0.9.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

stannum-0.9.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file stannum-0.9.1.tar.gz.

File metadata

  • Download URL: stannum-0.9.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for stannum-0.9.1.tar.gz
Algorithm Hash digest
SHA256 2120b99ac8c1897b0ef5b1b56950d6073ee59c69ae0675c38303f66f474ea786
MD5 2813a246aef0722b1ed04cfc4f438185
BLAKE2b-256 f22012aeee7e3c6b0acb5ae40c5f4de9f864fd521b13b8111c98af6f090652b6

See more details on using hashes here.

File details

Details for the file stannum-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: stannum-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for stannum-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb0ab129dc80a6e748f5033e454bbf017c8225951d2e5c136eeaf35af4d0843d
MD5 596dd69261275a53d6ef43dec4541b7b
BLAKE2b-256 d646c6a9fd6513acebf78f55152df19cbcc55eaf84dd6ef14ce0fde7858b630c

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