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.4.tar.gz (62.0 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.4-cp312-cp312-macosx_11_0_arm64.whl (155.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

thinc_apple_ops-0.1.4-cp312-cp312-macosx_10_9_x86_64.whl (162.8 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

thinc_apple_ops-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (154.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

thinc_apple_ops-0.1.4-cp311-cp311-macosx_10_9_x86_64.whl (161.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

thinc_apple_ops-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (154.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

thinc_apple_ops-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl (161.7 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

thinc_apple_ops-0.1.4-cp39-cp39-macosx_11_0_arm64.whl (155.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

thinc_apple_ops-0.1.4-cp39-cp39-macosx_10_9_x86_64.whl (162.2 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

thinc_apple_ops-0.1.4-cp38-cp38-macosx_11_0_arm64.whl (155.3 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

thinc_apple_ops-0.1.4-cp38-cp38-macosx_10_9_x86_64.whl (161.8 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

thinc_apple_ops-0.1.4-cp37-cp37m-macosx_10_9_x86_64.whl (162.4 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for thinc_apple_ops-0.1.4.tar.gz
Algorithm Hash digest
SHA256 992dfc4805ab964131c9d9c71bcc4330becabe41916665ec424c035311347d05
MD5 c1371eb2c9213ca64c3f629bbafd81ad
BLAKE2b-256 ac9bbd3bc0bda5696adf82192cf6dfbebcdc99eaa83c7fda866579e489f86bde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 30ebe3deecf0fb156b74ba4f600d52ec3fa96fb6efb8a00ca14d01e712a85cc4
MD5 2c009c01ff50044949e3e3fa658578f6
BLAKE2b-256 4368ce186496eef8a07ce1702eb20ebf95345fd9df4c57d35663f31ff0805853

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 16cf0bd28a640177c62b1652915e225aa04458682bf698d9a51351654d206907
MD5 4ba5049baa03227a8895ee509d2d60a8
BLAKE2b-256 d3a362faa090ae7a5648be8850317b758353ee84bf000f9f5c1c75a00d617beb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd098f13733e11f74444e6bd882068c35d7e9d15f40535526e420eb7a2ef56c9
MD5 bc9768df135d633804ba5b985011599e
BLAKE2b-256 fc5dda84b107dc3f67713b58efbc323001f0c391e65be28529eceae773f4435a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6935883f055a040a41d6af8f8597044de570c8229361886727d9b6b85bb18788
MD5 a56aa647b71092891d8f932e2726c227
BLAKE2b-256 97dff0e9a44aa1741310bac4fa9b254f1aec65782b61505974eae1a61ed390fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec3bd84e0c5ef5d9ee1a10de07c5bfd477f936029ebc698b3b418f82963dbd0b
MD5 e2bb40470fc661689221207e65958969
BLAKE2b-256 35dc38fc5d39b3e16e43b7f2eb976e3f64c9b9413fd7dd46660a2606327afcf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ad03f4247f8243164d4faba79aa157899d2a3ab22e2964f01be93a9a889895ee
MD5 c055b7801e7e9a3b7a7b3818e11f7c56
BLAKE2b-256 cdf086d6e02bb0a20c666c3c4601cd62bbb5556c14106e3c4372d657e8a467a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60cd002ceb2406991dda5adedc79e4494e19ba45a72d01c53124ecc86a00861f
MD5 fc3a5f094be6e941e28704a58f99d243
BLAKE2b-256 3e1e15cfb9e470b6de158d20b195cba515e4513f72aa6ab054c5195055688fca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 31533f28e1af497edb246afa88cd7287ff49a365a1a21dfab2c6d2b19aea3990
MD5 a8ad4dc8ff6004d15641cbe399aacccf
BLAKE2b-256 e37eabf5eb5eb8108dc1345dd30beb3debeaed876fc8496d7483850c880de557

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f203451c5c0dead351cd7fdc495afab6f7b6f40e27651e9f1d5f8839be127210
MD5 299a31f0d8c98c2b964f8aa5a643823c
BLAKE2b-256 a395840bf38872860836fba5c8ee0ba65835c0384a8a4fb535ac59e833ced48a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9d7864bbee3e13a6c91ec59634810378d2dd11b808380ee40c11b3eb11aae1c6
MD5 bac3c5761d64bbbbb8554681b7c2e4e9
BLAKE2b-256 3eb6a3c6efa23b1dc5468cc10b2ec3451ddef16ded59837fdf49fb2e4f558846

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fa9c53717b00f49de091046100e69c03556e209902c07eb50d0d4bbd26ba0f5d
MD5 9c067602da9a30918e35111df2b6b3c3
BLAKE2b-256 296c9802c46d1cfc10f498d84518de951a67c259d42d05c7e4e7455b9c9e02fa

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