Skip to main content

Improve Thinc's performance on Apple devices with native libraries

Project description

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).

⏱ Benchmarks

Using thinc-apple-ops leads to large speedups in prediction and training on Apple Silicon Macs, as shown by the benchmarks below.

Prediction

This first benchmark compares prediction speed of the de_core_news_lg spaCy model between the M1 with and without thinc-apple-ops. Results for an Intel Mac Mini and AMD Ryzen 5900X are also provided for comparison. Results are in words per second. In this prediction benchmark, using thinc-apple-ops improves performance by 4.3 times.

CPU BLIS thinc-apple-ops Package power (Watt)
Mac Mini (M1) 6492 27676 5
MacBook Air Core i5 2020 9790 10983 9
Mac Mini Core i7 Late 2018 16364 14858 31
AMD Ryzen 5900X 22568 N/A 52

Training

In the second benchmark, we compare the training speed of the de_core_news_lg spaCy model (without NER). The results are in training iterations per second. Using thinc-apple-ops improves training time by 3.0 times.

CPU BLIS thinc-apple-ops Package power (Watt)
Mac Mini M1 2020 3.34 10.07 5
MacBook Air Core i5 2020 3.10 3.27 10
Mac Mini Core i7 Late 2018 4.71 4.93 32
AMD Ryzen 5900X 6.53 N/A 53

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

thinc_apple_ops-1.0.0.tar.gz (63.2 kB view details)

Uploaded Source

Built Distributions

thinc_apple_ops-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (157.7 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

thinc_apple_ops-1.0.0-cp312-cp312-macosx_10_9_x86_64.whl (163.0 kB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

thinc_apple_ops-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (156.6 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

thinc_apple_ops-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl (161.5 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

thinc_apple_ops-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (156.9 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

thinc_apple_ops-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl (161.9 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

thinc_apple_ops-1.0.0-cp39-cp39-macosx_11_0_arm64.whl (157.5 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

thinc_apple_ops-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl (162.5 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file thinc_apple_ops-1.0.0.tar.gz.

File metadata

  • Download URL: thinc_apple_ops-1.0.0.tar.gz
  • Upload date:
  • Size: 63.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for thinc_apple_ops-1.0.0.tar.gz
Algorithm Hash digest
SHA256 97238eb6693e758bfdcf1ac8e92c064bbe893ab74a6a3a4237c5bdf17318e502
MD5 aee5aa5df47b706f3e9d26a8d8f6e113
BLAKE2b-256 0d4415fa7fd8c4f3011f29393a1aed7616b3991fb7562ef044a31a818c25558f

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1594f897f7dd03212d5b1ae1e4054be02526da530201a09c32d7bb557d274902
MD5 5c972cfa9e91d8caa000c144879fc9b9
BLAKE2b-256 c95dcacc702a8c7d6b5f19181819104b3d7d534598551d75a08d1c99ae96c869

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b2a9d2d3e8b86c9ce4750affc1b6c7350ef92fff3d33249302aeafee20f3e09e
MD5 270e345418ec5a64b87a33b3280711d7
BLAKE2b-256 9c08c223217366308b794105b3269a5de183e898d0eb7d316143c33ca0d44d13

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 257aa6fcaac764fc72285bf1fb93d1986ed9de17192c2c7090a785ee999188f8
MD5 9ccb935f936887aeb8a3464a60ce4410
BLAKE2b-256 f3831717527eaebed4b71fd7e260deb7c8e2c33b35b9ac75a6bda6a1e7158e1b

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 24083c6f74869a3b92bb398f610271687e269c290deda124075b3577a0873445
MD5 2c1d827e3684894e8d3092142c733054
BLAKE2b-256 a2c5fe79f5aff1731a80104c7366023b71b42948a6da3dad7383cbe779bdb6db

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2f641448bfcefc5c5204484a62baac7c040741fa8d8ecb86574a0357f390e373
MD5 f9213daf4c9e612b20b90c01cbd3c8c9
BLAKE2b-256 f41cb2727569fadd5299c11f3eecc8d2016cbb433b7b7d12da345295b2794693

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cef314b216ace57dddf403caabd12b8af9d5519b7c679b8a24871c28c7588845
MD5 3a6329979bf203fb41fd9af5ef4a96cb
BLAKE2b-256 84b50e006fd7a0bf0a0a153ddf3134a47854e731af231bc865413188ec5c84a3

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25d16b4518642b394cc7c4cf6a6477720f35fb22e6d91dca633bff4102c59763
MD5 9c9eab2e4b241e1f034a9a08264e411f
BLAKE2b-256 e0a638816c30c865584ebd4ac80c21ae72d4f24518d726e755e3ff803ec47f89

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cd04a7cd379a629498f964f5c589150a885ce834228dc060967806ee32196fab
MD5 98b887f266382800ba365552e459d589
BLAKE2b-256 93ec8f2aa7e1171343e456145fe47596d053b61d55cdadd3f04b46c99133d34b

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