MPS CARAFE
CARAFE (Content-Aware ReAssembly of FEatures) for Apple Silicon (M1/M2/M3/M4).
Drop-in replacement for mmcv's CARAFE op.
Why?
CARAFE is a learnable upsampling operator used in:
- Mask R-CNN: Instance segmentation
- FPN: Feature Pyramid Networks
- YOLACT: Real-time instance segmentation
But mmcv's implementation is CUDA-only. On Mac you get:
NotImplementedError: carafe not implemented for MPS
This package provides a native Metal implementation.
Installation
pip install mps-carafe
Or from source:
git clone https://github.com/mpsops/mps-carafe
cd mps-carafe
pip install -e .
Quick Start
Basic CARAFE Operation
import torch
from mps_carafe import carafe
# Input features (N, C, H, W)
features = torch.randn(1, 64, 32, 32, device='mps')
# Reassembly masks (N, group_size * k^2, H*scale, W*scale)
kernel_size = 5
group_size = 1
scale_factor = 2
masks = torch.softmax(
torch.randn(1, group_size * kernel_size**2, 64, 64, device='mps'),
dim=1
)
# Upsample with CARAFE
output = carafe(features, masks, kernel_size, group_size, scale_factor)
# Output: (1, 64, 64, 64)
CARAFE Module
from mps_carafe import CARAFE
carafe_layer = CARAFE(kernel_size=5, group_size=1, scale_factor=2)
output = carafe_layer(features, masks)
CARAFEPack (with mask predictor)
from mps_carafe import CARAFEPack
# Complete upsampling block with built-in mask predictor
upsample = CARAFEPack(
channels=64,
kernel_size=5,
group_size=1,
scale_factor=2
).to('mps')
output = upsample(features) # No need to provide masks
API Reference
carafe(features, masks, kernel_size, group_size, scale_factor)
| Parameter | Type | Description |
|---|---|---|
features |
Tensor | Input features (N, C, H, W) |
masks |
Tensor | Reassembly kernels (N, group_size * k^2, Hscale, Wscale) |
kernel_size |
int | Size of reassembly kernel (typically 5) |
group_size |
int | Number of channel groups (typically 1) |
scale_factor |
int | Upsampling factor (typically 2) |
CARAFEPack
Complete CARAFE block with mask prediction convolutions.
How It Works
CARAFE upsamples by:
- For each output pixel, identify the corresponding input neighborhood
- Use learned reassembly kernels (masks) to weight input pixels
- Sum the weighted inputs to produce the output
Unlike bilinear upsampling which uses fixed weights, CARAFE learns content-aware weights that adapt to the image content.
Compatibility
- PyTorch: 2.0+
- macOS: 12.0+ (Monterey)
- Hardware: Apple Silicon (M1/M2/M3/M4)
Features
- Full forward and backward pass (training supported)
- fp32 and fp16 supported
- Compatible with mmcv CARAFE API
Credits
- CARAFE Paper - Original research
- mmcv - Reference implementation
License
MIT
Metadata
Release files for mps-carafe 0.2.1
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 | Actions |
|---|---|---|---|---|
| mps_carafe-0.2.1.tar.gz | 12.8 kB | Without provenance | Details for mps_carafe-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mps_carafe-0.2.1-cp314-cp314-macosx_15_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 15.0+ ARM64 | Details for mps_carafe-0.2.1-cp314-cp314-macosx_15_0_arm64.whl |
Total release size: 100.4 kB
Release files / mps_carafe-0.2.1.tar.gz
| Download URL | mps_carafe-0.2.1.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
230bacc67f911389f7a453494edbe93255c1c1da244f241cf4ad335154a43917
|
|
BLAKE2b-256 checksum How to use checksums |
07bba1dc034a438a7a4efe2da764162cd941e48e2c7850f90172e1cf6926d2cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / mps_carafe-0.2.1-cp314-cp314-macosx_15_0_arm64.whl
| Download URL | mps_carafe-0.2.1-cp314-cp314-macosx_15_0_arm64.whl |
|---|---|
| Size | 87.5 kB |
| Tags | CPython 3.14 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e639f9a251d75d21e4ee6321fb06b3e7cae89af91a11f0e51b286de81d5f711c
|
|
BLAKE2b-256 checksum How to use checksums |
befdf6d39f64884e69dca8f3017fa53d2ddc5e1c58fb450dd090313eca8d9691
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for mps-carafe 0.2.1
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.