metalcore
High-performance Metal-accelerated linear algebra and training operations for PyTorch on Apple Silicon.
Overview
metalcore provides optimized custom Metal kernels for PyTorch on macOS, bypassing generic MPS fallbacks for significantly faster computation.
Installation
pip install metalcore
Key Features
Linear Algebra
- SVD: Jacobi algorithm, 25x faster for LLM weight matrices
- QR: Blocked Householder, 20x faster batched
- Eigh: Symmetric eigendecomposition, 3.5x faster
- Cholesky: MAGMA-style, 33x faster batched
- Solve: LU-based, 10x faster batched (fp16/bf16 supported)
Training Ops
- RMSNorm (
MetalRMSNorm): ~1.5x faster than PyTorch - AdamW (
MetalAdamW): 2.4x faster optimizer - SiLU (
metal_silu): 1.1x faster - EmbeddingBag: 6x faster (avoids CPU fallback)
- LayerNorm, Softmax: Fused implementations
RoPE
apply_rotary_pos_emb: Metal-accelerated rotary embeddings (3.4x faster)RotaryEmbedding: Drop-in HuggingFace replacement modulepatch_transformers_rope: Auto-patches Llama/Mistral/Qwen models
INT4 Quantization
- Hybrid approach (recommended):
Int4Linear.from_float(linear, dequant_on_load=True)- Store as INT4 (7x disk compression), dequant to FP16 at load → 0.6ms matmul
- GGML block_q4_0 (llama.cpp compatible):
quantize_ggml_q4_0,matmul_ggml_q4_0- Ported from llama.cpp using
simdgroup_multiply_accumulate - 4-15x overhead vs FP16 (36x faster than naive)
- Enables larger models: 7B→3.5GB, 70B→35GB
- Ported from llama.cpp using
PyTorch Integration
import metalcore
# Automatically accelerate F.silu, F.embedding_bag, torch.linalg.svd/qr
# Also replaces torch.optim.AdamW -> MetalAdamW, torch.nn.RMSNorm -> MetalRMSNorm
metalcore.enable_pytorch_overrides()
# Works seamlessly with HuggingFace models
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("...", device_map="mps")
# Optional: Also patch RMSNorm and RoPE modules
metalcore.patch_transformers_rmsnorm(model)
metalcore.patch_transformers_rope(model)
Quick Start
import torch
import metalcore
device = 'mps'
# SVD
A = torch.randn(100, 50, device=device)
U, S, V = metalcore.svd(A)
# Batched QR
B = torch.randn(100, 16, 16, device=device)
Q, R = metalcore.qr(B)
# Linear Solve (fp16/bf16 supported)
A = torch.randn(100, 32, 32, device=device)
b = torch.randn(100, 32, device=device)
x = metalcore.solve(A, b)
# Training Ops
from metalcore import MetalRMSNorm, MetalAdamW, metal_gelu
norm = MetalRMSNorm(512).to(device)
x = torch.randn(32, 128, 512, device=device)
y = norm(x)
model = torch.nn.Linear(512, 256).to(device)
optimizer = MetalAdamW(model.parameters(), lr=1e-3)
y = metal_gelu(x)
Performance Highlights
| Operation | Speedup |
|---|---|
| RMSNorm | ~1.5x |
| EmbeddingBag | 6x (vs CPU fallback) |
| AdamW | 2.4x |
| RoPE | 3.4x |
| SiLU | 1.1x |
| QR Batched | up to 20x |
| SVD (large) | up to 12x |
| Fused MLP Bwd | 5-6x (vs Autograd) |
| Fused Attn Bwd | Parity with FP16 |
Requirements
- macOS 12.0+ with Apple Silicon (M1/M2/M3/M4)
- Python 3.9 - 3.14
- PyTorch 2.0+
Note: M3/M4 chips recommended for best bf16 performance. The library gracefully falls back to FP32 on older hardware.
Author
License
MIT
Metadata
Release files for metalcore 0.1.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| metalcore-0.1.16.tar.gz | 2.3 MB | Without provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| metalcore-0.1.16-cp314-cp314-macosx_15_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 15.0+ ARM64 | Details |
| metalcore-0.1.16-cp313-cp313-macosx_15_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 15.0+ ARM64 | Details |
| metalcore-0.1.16-cp312-cp312-macosx_15_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 15.0+ ARM64 | Details |
| metalcore-0.1.16-cp311-cp311-macosx_15_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 15.0+ ARM64 | Details |
| metalcore-0.1.16-cp310-cp310-macosx_15_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 15.0+ ARM64 | Details |
| metalcore-0.1.16-cp39-cp39-macosx_15_0_arm64.whl | CPython 3.9 | CPython 3.9 | macOS 15.0+ ARM64 | Details |
Total release size: 9.3 MB
Release files / metalcore-0.1.16.tar.gz
| Download URL | metalcore-0.1.16.tar.gz |
|---|---|
| Size | 2.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86ee276ffc2d47872e7f157f58b95f5e5e70cf1f2b69a7d610692fe629caecab
|
|
BLAKE2b-256 checksum How to use checksums |
c18bf26150e20f208c658829bbcd92001bdcb0cfa5cfb55a561e9dc924d9ce26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / metalcore-0.1.16-cp314-cp314-macosx_15_0_arm64.whl
| Download URL | metalcore-0.1.16-cp314-cp314-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.14 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
412ae0da642d83d6733bd5273e5c3a7b498d81421520cc3d144018265200d3a9
|
|
BLAKE2b-256 checksum How to use checksums |
4c444876b7ef59c7e467c43f76255088bd9175b8c2fc09c253285370104b68bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / metalcore-0.1.16-cp313-cp313-macosx_15_0_arm64.whl
| Download URL | metalcore-0.1.16-cp313-cp313-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.13 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d1aab917c3a1fcc3d8961d2c8683a57595fd9da1fa00e8708fecd199625226e2
|
|
BLAKE2b-256 checksum How to use checksums |
ba255e2ea5a0f78d9ba717e9cee0cd5dd9a6c14252582e7b6cc026eb2463ef78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / metalcore-0.1.16-cp312-cp312-macosx_15_0_arm64.whl
| Download URL | metalcore-0.1.16-cp312-cp312-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6fff1c94f2c5ea9ec72410893fec2bdc5a907384911c1ed22bf16b29348c1d08
|
|
BLAKE2b-256 checksum How to use checksums |
20c23fa58e856d4d6f4a55124403a1f7080376b637ce65f21b9fc19b4a9e3f1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / metalcore-0.1.16-cp311-cp311-macosx_15_0_arm64.whl
| Download URL | metalcore-0.1.16-cp311-cp311-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ca012b74861aa68fdabff372163be12bf4f0d3f7500dbbb913eeb968c9a87c7f
|
|
BLAKE2b-256 checksum How to use checksums |
de101076e55f2793a46091c2e2c85d4ecafc918d46101214169125dac8ccea80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / metalcore-0.1.16-cp310-cp310-macosx_15_0_arm64.whl
| Download URL | metalcore-0.1.16-cp310-cp310-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5a608e8783cf16fde8bc6231adebce1552991c807a2dfcd8d0d72b20bde76b4e
|
|
BLAKE2b-256 checksum How to use checksums |
4362148e34fafb6c93afbc6bb00c24f6ae8b9eb6079aaaede2be0c27f0ac6e6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / metalcore-0.1.16-cp39-cp39-macosx_15_0_arm64.whl
| Download URL | metalcore-0.1.16-cp39-cp39-macosx_15_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.9 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
be2e7b43d3190cc6ec9f78031e2b58736afc554153021f0df3ce30f2bbb83e2c
|
|
BLAKE2b-256 checksum How to use checksums |
4802f872a429dbde9f881cf0dbe9211d1c6884edc5e2612f62b5d095ce7c1e6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for metalcore 0.1.16
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.