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. It's turned off by default because it's still experimental, but you can enable it in pytblis.contract and pytblis.einsum by passing complex_real_contractions=True. Otherwise, all mixed-type contractions use NumPy.

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.12.tar.gz (476.2 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.12-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.12-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.12-cp312-abi3-macosx_12_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12+macOS 12.0+ ARM64

pytblis-0.0.12-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.12-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.12-cp311-cp311-macosx_12_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

pytblis-0.0.12-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.12-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.12-cp310-cp310-macosx_12_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

pytblis-0.0.12-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.12-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.12-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.12.tar.gz.

File metadata

  • Download URL: pytblis-0.0.12.tar.gz
  • Upload date:
  • Size: 476.2 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.12.tar.gz
Algorithm Hash digest
SHA256 27a6269e6bb8aa3dc2c7a232d4ba85d2b6baddfcf4aa756066088cb42e2ad78f
MD5 121e11c06c9f5f3fdee3aebedf5595e4
BLAKE2b-256 402af1e4987f2bc46a0fc7692e026e2d413c6e342379bc8f978c4d0a700c7cca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12.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.12-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fd9750207a268f395e4679404f7e5c1c05a55cbcbe9b847c3f840e4882721de4
MD5 d9a34cafefd591f5a335ed45bee26598
BLAKE2b-256 f4cca89a9d48caf70a2ba1b8b4d3c1682420332fe9d1fe47b31a6d9a3a86affe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9cbaee16cf05edb9c04bd37e56063054c633550f9c34be9098b5d5aba690d384
MD5 69ba5a275794fb455d0c76f90c70f726
BLAKE2b-256 dbb4942c42ed350ded969ff156d06ace6f2a4352af91186110c6bc5e1475d2e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp312-abi3-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp312-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 7d1d5267a420d49dc4987589a26e37487ecf1c3c7fcc3187965bc2e54ea3b4e2
MD5 c95c2716b8eb65b701322c2a1605f99f
BLAKE2b-256 5ebd0842a7c003f91226423129cd22963fa5bddff5a4bb7d3ec17261feca6c95

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 847e7060d31deedb4dfe20a7e4390d150fd473504668d999049afdeace51115c
MD5 707daac9f7b94471bc51a035f8f1c22f
BLAKE2b-256 e07f87ffa2db3516f9bcc7ce55676d5d478d1061c7ca6f02e623078b5a82b023

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b390971dfaf5ed2ed64e87a43ddcf69570282c3d2bdfa05677d31f1965c46269
MD5 48fced1af78aa3a7b3b96b31386718b8
BLAKE2b-256 f038cbba06d158bb4490b3b5a8ac6bc796dc35bce5eac8d302999b5f93b034ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 208ebd45ea740bd5e56c895f5a4b02f3d7e0ca82355f9391de8236e642bf85d4
MD5 d66fc92bd6897761794a9602f0b0cb08
BLAKE2b-256 2ee38e5465fbf11a564268a0dffabbe2cf953938eb7e9015b67f5141914c0f4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e35305b13f4b1be96e76ac273395475ff807041443e3b389eaf3adfb1d44f79b
MD5 c8056aa19bf1479aabba93838bfae683
BLAKE2b-256 434dd2454f56204e61d1ae4ee786056044cfed21559038474a26933dfebc7e5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1c8d2b9aefd1be2711c2a74661adcd0cd85f9b6f17f6e0685fc90d8913503ae8
MD5 a1dff1c8750d9288607413e3f264bce5
BLAKE2b-256 50a1da1580a472f0d18f9be3e4c86d6ad085fde2a22ba974cb1ba2c66e5950da

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 492a908de084bffbb791e34e62bb1b9e64a96db9e568c1d35d2a3ecee50a87c5
MD5 8b1ab8179d3b1057a1bc926354a20beb
BLAKE2b-256 56dd8a4cde7d72e64e96e4951ab622a8e44d1ac9c9002ba1d560791fa629c6fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a8c7d15bfb305f8fc65443aa028d824410f5726c3590cac70b0fc91e266f1954
MD5 cce70ab6f0296f95ae183f4cd37d32b0
BLAKE2b-256 505542794b8f3f1607bfc3dc36da946ac7ddc95d92a2816783083437fd5c9b64

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3e0b48a3c4297ec5959e91187ed66a6c9b5b77d18d02d43756a8dba7d7e8df3e
MD5 efb318b28ee40be37b9e10d915179463
BLAKE2b-256 13ccffa945a3cf82b83c162871085ad0b9d68f50c05b4792ef3b40051e585c3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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.12-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pytblis-0.0.12-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 b3195cec0cdace634b31104d7e81bfc3e8d2fea4214b7bd8dc1551e9d7fbcf59
MD5 924676496f7005b6d565de6d06bd4c48
BLAKE2b-256 54e6ebf3cf3693018c4dbef8a38c4951f3cbef1ce84d74d28e4ac49007330d2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytblis-0.0.12-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