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-0.1.0.tar.gz (44.7 kB view details)

Uploaded Source

Built Distributions

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

thinc_apple_ops-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (120.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

thinc_apple_ops-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl (127.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

thinc_apple_ops-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (121.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

thinc_apple_ops-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl (128.9 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

thinc_apple_ops-0.1.0-cp38-cp38-macosx_11_0_arm64.whl (119.7 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

thinc_apple_ops-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl (127.0 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

thinc_apple_ops-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl (127.5 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: thinc_apple_ops-0.1.0.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for thinc_apple_ops-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa3328a23b52e599ab963c9d807b06bfaf5b9d529a290c510c41bc21751feed6
MD5 1a8a4c777c526fe39f562662bad7d30e
BLAKE2b-256 1f4a52875e20079298fd99199f9ef197c61371e9fe8c880010d65642504fc976

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7abaaf84db084b336cb2bf5beb7b7b6c38761cd9b6ef0383b461afa3a580061c
MD5 5492933ea33b65bb00aec07946d0257c
BLAKE2b-256 f92630d35f1960c0527f4de5ac7efabd0124caa13eda07cbb4fad88cf8a5aad2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4ec63b690a8219a4e47ae79c981b9fc9d29a7faf2edace311db632aba0a8012e
MD5 37e440ffe47058171aa15702af44fbc8
BLAKE2b-256 d001b1cc111ffe8243a49dfc340f42c1c00f6f39ec45a2f119674a2563f81f52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4415118a22e5dc8e439e99dd73873735612823c8ae0d93824d7e8c11a51e3c92
MD5 c3a29ca0f8ba65d6386fb4a555f1c4ba
BLAKE2b-256 cff42072de52b775c0c3d9f3fa0264c9388c79f67f55e8a7e94d740b0f394107

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fae03d9bed0fb1b320babda564e266178a27c244f6faa679d598edc6961e7bfe
MD5 161f85429e32c0524354d1116b1fa19f
BLAKE2b-256 e7258eba0235a689aec23ed01d8f3b275640f88157f96a6dee4d4b75ec0eaa56

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-0.1.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b2b0b6f6a952e27217519492aa1ae9b3d85a6a2cfd0ea042fb59d7aa18e3d1de
MD5 2902afca2aa89e9c8c24b41de68549ea
BLAKE2b-256 683bde5155a33e5c31d767227f6edd45c998aebf181c1cc1107a601cf32c1665

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9451632a59f3ce133df4b2de8971781f3411ce26c747140fe891f667e16ceda4
MD5 f69615db192343ae202364ef7d8b478c
BLAKE2b-256 45c5a7e0c43855951bcf944c6c869929f4cdeb685b52fb92d5aa39de87949293

See more details on using hashes here.

File details

Details for the file thinc_apple_ops-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4fb4070bc9011240148c544742556f2bba72cac5e7f9b47904df9f460f73dbf5
MD5 0ac75d62cc7f0c82e5b95f849130f38c
BLAKE2b-256 c75d9e61ffb4a0b1e9e4db89dd705da52114ae02db9f1b67c8913d6e368ce9c6

See more details on using hashes here.

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