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

Uploaded CPython 3.12+macOS 12.0+ ARM64

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

Uploaded CPython 3.11macOS 12.0+ ARM64

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

Uploaded CPython 3.10macOS 12.0+ ARM64

pytblis-0.0.13-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.13-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.13-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.13.tar.gz.

File metadata

  • Download URL: pytblis-0.0.13.tar.gz
  • Upload date:
  • Size: 476.3 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.13.tar.gz
Algorithm Hash digest
SHA256 4da638015c60e91d3e5972b3ea5691a5bd4b9e6f65e2963667515a587cad961f
MD5 fcc18e3c89979d15334f08cb610751cd
BLAKE2b-256 e80a27482b09113d811a59b6d3bd28b548664390ef91dce5d833f96daf489159

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5ad337f3bcc420c730d88da33f65ba15b50945a9296eeb85891cd8c872143951
MD5 4a3638407090963daa90a23f09d3f5b0
BLAKE2b-256 8451e11730048787f68c262dd6b5b28efe8d3df2d22d15bf362b3df0a3157024

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3733f9028d35ff63aaafa14445d16ee686a96bd577e4915a4292e672200af615
MD5 3a7317763e0c939f9bafc4da05ccf744
BLAKE2b-256 eb34cfd587b80d4185bb31534bb88fdf2daf0c29c7077fb34adf5ad44f50a1f4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp312-abi3-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 85a614f500907bc3656d65099368cc74022514c6ed2b126d71f731df26fe1447
MD5 89cc4155b639985c2cc8e5d4d0f1aff4
BLAKE2b-256 827eec6d271e1476956c43f670bd1a3b1fe65f4ae813974ce51aeaf31a67aa5e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b5cffa16d099db3034c0a343e31f4d49ec754b7a1a2dce93714ba8a4d49551be
MD5 1d3dffce793136c3249f4f8013ffafa0
BLAKE2b-256 7d54192f41fe8ba572f979d5a027f69fe18547a5d058f1bf42e6ea9264de9417

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2f3b37194bb7f4b4319a7b2cb5b44ef0c292d7c3cd9101ae1ff727d7725b64b8
MD5 9ebb0079058469adf90a3d69fd34e5c6
BLAKE2b-256 d6e034a4922e745c0a508bfeeab07f9c9545aadfc07c7db6ad6b6abd153b25c6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 df750a5639e72eca8f44b473b4610073fbb884d0479aa5e28db26ed8ebb208a2
MD5 e70195de9c854d67c18d87bc9dc2314d
BLAKE2b-256 ba77c6785e9977f2ceafd43a7e24d3ad26790a52970936e10b7c354274a8a824

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9c780ae44a7308f92b133613c2ad61da62454fde0d13daecaee38fb6dbefd838
MD5 97bf03cce6a491ccbc3b5a652f8a2362
BLAKE2b-256 857571b3d9399e7b87a8a5eb4e501b7905fc5d2e75aae69bb07378fec7b91280

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b5cac1f546ccb1bf3860b136becc62e72512b4ccad4727064de013ffd8656c22
MD5 7df8adab8de3ad4cad838f75d88eac2c
BLAKE2b-256 cfd7b6aab2340d29096eba2e23d34ba370846f328b6106fc3b6125b1a4613c84

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 e579b9f15eec60b2c330d2350940572889822851be1791b109663649f916d819
MD5 b33c24834178fcab32b6e9199d78d8da
BLAKE2b-256 d1d02beca9e0dec17ae8f3d807f36f71fda704740e5c8429952d7f4d69a824a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e86e6d0bd57f89ad0cd69470fb60134f12d9ecfc83a32a65d2768f9eed02e13b
MD5 68a3f785ad2980453c7cae8b9272c044
BLAKE2b-256 7c0f58d61fe43d1772808a97ebdca1ca29d03d54ef663e5bfad8df71f1e1db0f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ce3918ce71d3574df0ad42af580b88aa965c820a5cd17a7e5611b077fbb585b5
MD5 f43c0c915af5994a881da7c9ae7945f1
BLAKE2b-256 13fed701d47eb10da378d01770645f2d8dd1f6114ba3a63700b5fe4fa0a9bf89

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytblis-0.0.13-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 ed97609b7c831528630e8d10ecc6f4a87130820c5cf634daa8c4f0d44fe092ac
MD5 86bcd6a260325133449247025bd70a0f
BLAKE2b-256 6705d19c4b8d4d2d5d91be6eef4c49818dce6992e15f1059dda0b925cb04a84d

See more details on using hashes here.

Provenance

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