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.3.tar.gz (44.9 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.3-cp311-cp311-macosx_11_0_arm64.whl (119.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

thinc_apple_ops-0.1.3-cp311-cp311-macosx_10_9_x86_64.whl (128.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

thinc_apple_ops-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (120.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

thinc_apple_ops-0.1.3-cp310-cp310-macosx_10_9_x86_64.whl (129.0 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

thinc_apple_ops-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl (130.0 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

thinc_apple_ops-0.1.3-cp38-cp38-macosx_11_0_arm64.whl (119.8 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

thinc_apple_ops-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl (128.1 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

thinc_apple_ops-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl (128.7 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: thinc_apple_ops-0.1.3.tar.gz
  • Upload date:
  • Size: 44.9 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.3.tar.gz
Algorithm Hash digest
SHA256 c4a5ca13db386b9581334894c267c01addbe69f4b537023576d9169da8363633
MD5 94d6ea9539b797bb50cae1a3cbedce20
BLAKE2b-256 d9c286228718efde9717378b1f9b3c49b0a9af3f3bbd9918cf5e3a1bd9f7c033

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dcd7fe399b3f01cda5a6ecd5949bd410d4508d280a36c7732f50dcc02878851f
MD5 e6a2b845550a504a492d7a7195f5c7c3
BLAKE2b-256 b6007a96d9f3380fb2c8d1e1a9aee11ea0911f07ccb0bf46c710fb16b1870681

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 464e10ef3630f6571934ef62785a72153e92fc88dbf856a753de37cb676cc907
MD5 6714355a9e2766b35b7bd2264ed5f4ed
BLAKE2b-256 1ea14a2053bde0d9e969a6f1c2cd7e30d2949b97f4e378ba85eb750d8e551197

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f43a7cde5de2e9a6e8641771a4a3e0f36c708e904c72f22e90546e7d9aee031
MD5 79f27562328260b63909ba490d09dfa2
BLAKE2b-256 79a0301caa6ef5a18f3622ff668d0aec8c09030f889a3249f280d5724fade108

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 61a2aa818b07f462f49e718fb5178a18075e45782293a041555e98b77b148091
MD5 8855ba47fc710e82d451f0dc4221c757
BLAKE2b-256 3e9961ac6f3176773e8ff474c935f48be32a865094adfac7ce501688ffa24afb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0af2881d9c17b2db8cc75682acc90fa2fbf4b79c53fb4fab91832d3ba1682c8e
MD5 cf3d89e64246c93a27c5c5faac049b8b
BLAKE2b-256 d7c8c3b8525f28ed7ae76001a804c4f20226e041b80f9bff6f39b68af56ce0a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7712b8647591d4afc2eae0720df08f676201b1b34db7e1d68415267846391127
MD5 c415f017225f4a9bfd75261040e3e124
BLAKE2b-256 1012ee3fecd1d822af4e93447ec3f0635a11e2274fefb48bef810e177daf5acc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0c71afa68ed8d27f2150d70d9185d02cf783ebe3142edfd34a6bdad6ad05a714
MD5 0976ce5cb86e71b7d396a81786b8a6bb
BLAKE2b-256 8d95403fbe5f10bb35b8072e5430ef36d6e2c2ba75e1ae59aa4a0364aadd9927

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 161cec4c9169ff17d59d731b23c49f91df196629a20a9d46176d7759c8e68de5
MD5 dc1b4cf4d0204162cb83f5450728e5f7
BLAKE2b-256 44aab270a5bb8fe392657fa942f2283338003bd03fded407f7ad782fe5c9c2a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for thinc_apple_ops-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e853d72820fe8d42c229f520a5d92f53f77b363b608e5bc2b898462cdbe34889
MD5 aac45c465ce2e72b4b4b4e47fad69ecb
BLAKE2b-256 f5dcb3a7c854044fc07d2aa7bdb7952a981bbc563846794ccf17c9fa03f0f5c2

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