thinc-apple-ops1.0.0
Published
Improve Thinc's performance on Apple devices with native libraries
pip install thinc-apple-ops
Package Downloads
Authors
Project URLs
Requires Python
>=3.7
Dependencies
thinc-apple-ops
Make spaCy and Thinc up to 8 × faster on macOS by calling into Apple's native libraries.
⏳ Install
Make sure you have Xcode installed and
then install with pip
:
pip install thinc-apple-ops
🏫 Motivation
Matrix multiplication is one of the primary operations in machine learning. Since matrix multiplication is computationally expensive, using a fast matrix multiplication implementation can speed up training and prediction significantly.
Most linear algebra libraries provide matrix multiplication in the form of the
standardized
BLAS gemm
functions. The work behind scences is done by a set of matrix multiplication
kernels that are meticulously tuned for specific architectures. Matrix
multiplication kernels use architecture-specific
SIMD instructions for data-level parallism
and can take factors such as cache sizes and intstruction latency into account.
Thinc uses the
BLIS linear algebra library, which provides
optimized matrix multiplication kernels for most x86_64 and some ARM CPUs.
Recent Apple Silicon CPUs, such as the M-series used in Macs, differ from traditional x86_64 and ARM CPUs in that they have a separate matrix co-processor(s) called AMX. Since AMX is not well-documented, it is unclear how many AMX units Apple M CPUs have. It is certain that the (single) performance cluster of the M1 has an AMX unit and there is empirical evidence that both performance clusters of the M1 Pro/Max have an AMX unit.
Even though AMX units use a set of undocumented
instructions,
the units can be used through Apple's
Accelerate linear
algebra library. Since Accelerate implements the BLAS interface, it can be used
as a replacement of the BLIS library that is used by Thinc. This is where the
thinc-apple-ops
package comes in. thinc-apple-ops
extends the default Thinc
ops, so that gemm
matrix multiplication from Accelerate is used in place of
the BLIS implementation of gemm
. As a result, matrix multiplication in Thinc
is performed on the fast AMX unit(s).