Skip to content

Conversation

jcaip
Copy link
Contributor

@jcaip jcaip commented Apr 3, 2025

This PR is meant to give users the ability to accelerate LLMs with 2:4 activation sparsity, using the approach outlined in our ICLR workshop paper: https://arxiv.org/abs/2503.16672

The main contribution is a cutlass 24_fp8_pack kernel that is able to relatively efficiently calculate the packed data and metadata given a normal dense tensor, which I've copied over from xFormers.

Performance Benchmarks

python benchmarks/benchmark_e2e_fp8_sparse_linear.py 

|   num_tokens |   bf16_latency (us) |   bf16_c_latency (us) |   fp8_c_time (us) |   fp8_c_sparse_time (us) |   fp8_c_activation_sparse_time (us) |   speedup |
|-------------:|--------------------:|----------------------:|------------------:|-------------------------:|------------------------------------:|----------:|
|           64 |             166.816 |               163.04  |           103.008 |                   74.304 |                             102.816 |  1.00187  |
|          128 |             156.256 |               151.52  |            99.936 |                   75.456 |                             102.048 |  0.979304 |
|          256 |             172.288 |               159.584 |           114.08  |                   82.432 |                             111.072 |  1.02708  |
|          512 |             218.88  |               204.608 |           144.096 |                  114.56  |                             139.488 |  1.03304  |
|         1024 |             394.4   |               392.544 |           251.104 |                  196.416 |                             227.904 |  1.1018   |
|         2048 |             764.608 |               734.816 |           480.704 |                  381.152 |                             426.688 |  1.12659  |
|         4096 |            1658.82  |              1623.58  |           901.344 |                  779.008 |                             843.392 |  1.06871  |

Tests

pytest tests/sparsity/test_activation24.py

Copy link

pytorch-bot bot commented Apr 3, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2012

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit 126166f with merge base 66eb801 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 3, 2025
@jcaip jcaip changed the title Jcaip/actiation24 [WIP] 2:4 activation sparsity Apr 3, 2025
@jcaip jcaip marked this pull request as ready for review April 29, 2025 03:58
@jcaip jcaip changed the title [WIP] 2:4 activation sparsity 2:4 activation sparsity packing kernels Apr 29, 2025
@jcaip jcaip added sparsity topic: new feature Use this tag if this PR adds a new feature labels Apr 29, 2025
@jcaip jcaip merged commit 9b1256f into main May 12, 2025
33 of 34 checks passed
@jcaip jcaip deleted the jcaip/actiation24 branch May 21, 2025 22:03
liangel-02 pushed a commit that referenced this pull request Aug 25, 2025
This PR is meant to give users the ability to accelerate LLMs with 2:4 activation sparsity, using the approach outlined in our ICLR workshop paper: https://arxiv.org/abs/2503.16672

The main contribution is a cutlass 24_fp8_pack kernel that is able to relatively efficiently calculate the packed data and metadata given a normal dense tensor, which I've copied over from xFormers. 
### Performance Benchmarks

```
python benchmarks/benchmark_e2e_fp8_sparse_linear.py 

|   num_tokens |   bf16_latency (us) |   bf16_c_latency (us) |   fp8_c_time (us) |   fp8_c_sparse_time (us) |   fp8_c_activation_sparse_time (us) |   speedup |
|-------------:|--------------------:|----------------------:|------------------:|-------------------------:|------------------------------------:|----------:|
|           64 |             166.816 |               163.04  |           103.008 |                   74.304 |                             102.816 |  1.00187  |
|          128 |             156.256 |               151.52  |            99.936 |                   75.456 |                             102.048 |  0.979304 |
|          256 |             172.288 |               159.584 |           114.08  |                   82.432 |                             111.072 |  1.02708  |
|          512 |             218.88  |               204.608 |           144.096 |                  114.56  |                             139.488 |  1.03304  |
|         1024 |             394.4   |               392.544 |           251.104 |                  196.416 |                             227.904 |  1.1018   |
|         2048 |             764.608 |               734.816 |           480.704 |                  381.152 |                             426.688 |  1.12659  |
|         4096 |            1658.82  |              1623.58  |           901.344 |                  779.008 |                             843.392 |  1.06871  |

```

### Tests

```
pytest tests/sparsity/test_activation24.py
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. sparsity topic: new feature Use this tag if this PR adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants