Skip to content

activation: add metal implemenation#352

Merged
drbh merged 1 commit intomainfrom
metal-activation
Feb 6, 2026
Merged

activation: add metal implemenation#352
drbh merged 1 commit intomainfrom
metal-activation

Conversation

@drbh
Copy link
Collaborator

@drbh drbh commented Feb 5, 2026

This PR adds a metal implementation of various activation functions that are comparable with the cuda version.

This should helps make the current basic usage example work on osx https://huggingface.co/docs/kernels/en/basic-usage and in general enable osx users to use activation kernels

@drbh
Copy link
Collaborator Author

drbh commented Feb 5, 2026

update to include the bench output

tested with the changes to the kernels benchmark command in this pr huggingface/kernels#265

kernels benchmark path:/Users/drbh/Projects/kernels-community/activation
Downloading path:/Users/drbh/Projects/kernels-community/activation@local...
Running benchmark.py...
Kernels library path: /Users/drbh/Projects/kernels/kernels/src/kernels/__init__.py

  GPU      Apple M3 Max (30 cores)
  CPU      Apple M3 Max
  OS       Darwin 25.2.0
  PyTorch  2.10.0

  Running SiluWorkloads on mps

┌───────────────┬────────────┬─────┬───────────┬────────────┬───────────┬───────────┬───────────┬───────────┬────────────┬───────────┬─────────┐
│ Benchmark     │ Workload   │   N │ Speedup   │   Mean(ms) │   Std(ms) │   Min(ms) │   Max(ms) │   IQR(ms) │   Outliers │   Ref(ms) │ Match   │
├───────────────┼────────────┼─────┼───────────┼────────────┼───────────┼───────────┼───────────┼───────────┼────────────┼───────────┼─────────┤
│ SiluWorkloads │ large      │ 100 │ 1.72x     │     6.6684 │    0.6442 │    6.2739 │   10.6387 │    0.2859 │         11 │   11.4963 │ ✓       │
│ SiluWorkloads │ medium     │ 100 │ 2.67x     │     1.213  │    0.4494 │    1.027  │    4.0239 │    0.0895 │          7 │    3.2332 │ ✓       │
│ SiluWorkloads │ small      │ 100 │ 1.87x     │     0.5019 │    0.2439 │    0.4133 │    2.8096 │    0.0258 │         11 │    0.9388 │ ✓       │
└───────────────┴────────────┴─────┴───────────┴────────────┴───────────┴───────────┴───────────┴───────────┴────────────┴───────────┴─────────┘

  large: 1.72x faster (95% CI: 6.5421-6.7947ms vs ref 11.4963ms) ✓ significant
  medium: 2.67x faster (95% CI: 1.1249-1.3011ms vs ref 3.2332ms) ✓ significant
  small: 1.87x faster (95% CI: 0.4541-0.5497ms vs ref 0.9388ms) ✓ significant

Kernel: 5f9348f  Benchmark: 760b882

Copy link
Collaborator

@MekkCyber MekkCyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thank you

@drbh drbh merged commit 63b875f into main Feb 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants