Skip to main content

Python bindings for TBLIS, a high performance library for tensor operations

Project description

pytblis: Python bindings for TBLIS

Actions Status GitHub Discussion

Are your einsums too slow?

Need FP64 tensor contractions and can't buy a datacenter GPU because you already maxed out your home equity line of credit?

Set your CPU on fire with TBLIS!

Usage

pytblis.einsum and pytblis.tensordot are drop-in replacements for numpy.einsum and numpy.tensordot.

In addition, low level wrappers are provided for tblis_tensor_add, tblis_tensor_mult, tblis_tensor_reduce, tblis_tensor_shift, and tblis_tensor_dot. These are named pytblis.add, pytblis.mult, et cetera.

Finally, there are mid-level convenience wrappers for tblis_tensor_mult and tblis_tensor_add:

def contract(
    subscripts: str,
    a: ArrayLike,
    b: ArrayLike,
    alpha: scalar = 1.0,
    beta: scalar = 0.0,
    out: Optional[npt.ArrayLike] = None,
    conja: bool = False,
    conjb: bool = False,
) -> ArrayLike

and

def transpose_add(
    subscripts: str,
    a: ArrayLike,
    alpha: scalar = 1.0,
    beta: scalar = 0.0,
    out: Optional[ArrayLike] = None,
    conja: bool = False,
    conjout: bool = False,
) -> ArrayLike

These are used as follows:

C = pytblis.contract("ij,jk->ik", A, B, alpha=1.0, beta=0.5, out=C, conja=True, conjb=False)

does

$$C \gets \overline{A} B + \frac{1}{2} C.$$

B = pytblis.tensor_add("iklj->ijkl", A, alpha=-1.0, beta=1.0, out=B)

does

$$B_{ijkl} \gets B_{ijkl} - A_{iklj}.$$

Some additional documentation (work in progress) is available at pytblis.readthedocs.io.

Limitations

Supported datatypes: np.float32, np.float64, np.complex64, np.complex128. Mixing arrays of different precisions isn't yet supported.

Arrays with negative or zero stride are not supported and will cause pytblis to fall back to NumPy (for einsum and contract) or raise an error (all other functions).

New features

Mixed-complex/real contractions

New in version v0.0.11: pytblis.contract fully supports contractions between complex and/or real tensors of the same floating point precision, provided that alpha and beta are both real. This just contracts the real and imaginary parts separately with TBLIS. As of v0.0.14, this feature is enabled by default. It can be turned off in pytblis.contract and pytblis.einsum by passing complex_real_contractions=False.

Installation

I will try to get this package added to conda-forge. In the meantime, conda packages may be downloaded from my personal channel.

conda install pytblis -c conda-forge -c chillenb

The pre-built wheels on PyPI use pthreads for multithreading. To reduce the overhead due to creating and joining threads, compile pytblis yourself and configure it to use OpenMP, or use the conda packages.

pip install pytblis (not as performant)

About OpenBLAS

Don't use OpenBLAS configured with pthreads. It causes oversubscription when used with other multithreaded libraries, in particular anything that uses OpenMP. Instead, use MKL (libblas=*=*mkl) or the OpenMP variant of OpenBLAS (libopenblas=*=*openmp*).

Installation from source

the easy way:

pip install --no-binary pytblis pytblis

The default compile options will give good performance. OpenMP is the default thread model when building from source. You can pass additional options to CMake via CMAKE_ARGS, change the thread model, compile for other CPU microarchitectures, etc.

the hard way:

  1. Install TBLIS.
  2. Run CMAKE_ARGS="-DTBLIS_ROOT=wherever_tblis_is_installed" pip install .

See dev_install.sh for an example. This script installs TBLIS in ./local_tblis_prefix and then links pytblis against it.

Research

If you use TBLIS in your academic work, it's a good idea to cite:

TBLIS is not my work, and its developers are not responsible for flaws in these Python bindings.

Acknowledgements

The implementation of einsum and the tests are modified versions of those from opt_einsum.

pytblis was developed in the Zhu Group, Department of Chemistry, Yale University.

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

pytblis-0.0.14.tar.gz (487.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pytblis-0.0.14-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pytblis-0.0.14-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

pytblis-0.0.14-cp312-abi3-macosx_12_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12+macOS 12.0+ ARM64

pytblis-0.0.14-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pytblis-0.0.14-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

pytblis-0.0.14-cp311-cp311-macosx_12_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

pytblis-0.0.14-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pytblis-0.0.14-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

pytblis-0.0.14-cp310-cp310-macosx_12_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

pytblis-0.0.14-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pytblis-0.0.14-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

pytblis-0.0.14-cp39-cp39-macosx_12_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.9macOS 12.0+ ARM64

File details

Details for the file pytblis-0.0.14.tar.gz.

File metadata

  • Download URL: pytblis-0.0.14.tar.gz
  • Upload date:
  • Size: 487.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytblis-0.0.14.tar.gz
Algorithm Hash digest
SHA256 514306273bf2d52f50cc55424e0595d329dce23f0fea340dda30f51bde354c9d
MD5 fc381a628407a9d82d8cf187e194a5c3
BLAKE2b-256 ccbacbed9d8e76d3f98f21d7b4c4dfd2b7d8dfe81202fb0020dbeab37b7aeb87

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14.tar.gz:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f7cdb5268c3f68a9c884aa57c2a08024e8a100fd5e1898cb63049f00641a0dd6
MD5 a82666445e5867794c7ccc31c7d01de7
BLAKE2b-256 7ee3bdf9763f93b356d59bbb3d7c5a1cc291d6334a2b20169c3aaffbe1ec830f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e06c8c1fd7db7360c9beee0d68140ea21cc3fa7ea7247d71c367b3b9d164053d
MD5 07f02319e320b8ce7e76d92f48830dd7
BLAKE2b-256 0df5876f9b917dc7f6b40a6330c368efc37c994afb426a833c68e047d235ceb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp312-abi3-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp312-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 d387cbfb6989f57abb92aa73e2e59630456d3c8a66c20c0d0eb5a33503ff1be2
MD5 97b753b3a71745d9fb42e7dce81c006c
BLAKE2b-256 c3501debfbbe77c99e943b412569072ffe769f1c228d2efe76a25a2d65801f65

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp312-abi3-macosx_12_0_arm64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 340a083258198126f4439c57b03bd3bdfaea89771c09eaacb0a5ab11899eec45
MD5 72a044fab4925a53792f08f95549d40e
BLAKE2b-256 965cd414273d05a1c48391c62790b3f070db3ca2838a737b472c97d3ecfe1630

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 88d73d6e14153a3b250481aebee29f094de92aac2ab33a2de799caea80e54153
MD5 b7f471feebb0ab9de43115f72bb2a659
BLAKE2b-256 d6cc7b441de19a71da103262c4606457034f0c32779b84b511b1b2541b6ce0b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 95a28f509ea83d7e602127e7f39bad0afabcdcfc2ab208ed06192faefc3ebd70
MD5 7986b2aa529756712ba36583aaacac36
BLAKE2b-256 604c037ac39d5490855173ec4b16a3b60f53d98e8679ae3ad3187414eaaa4053

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp311-cp311-macosx_12_0_arm64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6b71b4b0aaae903fbf1cf379b7867453f45b6bbda245e77be013da996e21ec42
MD5 2422887c9ccc8f867aa938882ffea6b3
BLAKE2b-256 5f3bd4ec04ed49f1cb4be250922e0abb3f27999b94a0a5ad027d6d9c3db465f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dbaa173bdb791244c5932612e20437d31b8b6b3c2fbe592eb7267621b7697dfa
MD5 007bf9589fa8538e7239fc27c442bddc
BLAKE2b-256 aaed60fcb032b51bb514644825e5832c85068a1773d8f1b7866c9988643449dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 16d86d7db817aab7ace22dac8418d623ee54f1650619f46fae965e710ae249b1
MD5 a5f43f3b91c80314fc0b9c59710aa319
BLAKE2b-256 98474ef9b9fc24034105b9ad814952c5ac637c3ced804256015dd6206a3789be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp310-cp310-macosx_12_0_arm64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1664585bf71f96955981f9215da36d34eccc2204ef1ddec3287012eb0a33f96e
MD5 7aa79d12c4b43852645729ef2d815f46
BLAKE2b-256 d3a6fe5d0bb1c90ddcf8dd2054db0fb83e6bdb0aabb51050eaa94f9e6d77f9a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89f1119b916ced0992e84675d299ab0715e1c8f94db3913e65a6cd1a4a417db0
MD5 7be3218732813664ac29981990189c4d
BLAKE2b-256 0252a348bdf9ccc4e59b23a6ba49bd2109602a9f1b0187e599e3780bb140506a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytblis-0.0.14-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.14-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 1304f5fd92c74f0f44cf1e232711b0d0a848b1bb90888ce2052d3dfaa1537776
MD5 2fad533e345ea75c631de27d3edacedb
BLAKE2b-256 3113f67ae66aed415bfbdf20d53f56413b7b7872d6d3a3dfb960c7360351c4ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.14-cp39-cp39-macosx_12_0_arm64.whl:

Publisher: release.yml on chillenb/pytblis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page