Skip to content

Conversation

jagrit06
Copy link
Member

@jagrit06 jagrit06 commented Apr 2, 2025

Proposed changes

  • Add new specialized kernel for small kernel (kernels size <= 7), small strides (strides <= 2) depthwise 2d convolutions
  • Add related tests

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@jagrit06
Copy link
Member Author

jagrit06 commented Apr 2, 2025

Here are some numbers from a M2 Ultra

Before:

 N,   H,   W,    C   kH,  kW,    O, strides, padding, groups,  dtype, time_pt, time_mx, diff%
 1, 512, 512,  128,   3,   3,  128,  (2, 2),  (1, 1),   128, float16,  0.6711,  1.2874, -47.87%
 1, 256, 256,  128,   7,   7,  128,  (1, 1),  (3, 3),   128, float16,  0.2140,  2.4399, -91.23%
ATTENTION ^^^^^^^
 1, 256, 256,  128,   3,   3,  128,  (1, 1),  (1, 1),   128, float16,  0.1640,  1.2861, -87.25%
ATTENTION ^^^^^^^
 1, 128, 128,  256,   7,   7,  256,  (1, 1),  (3, 3),   256, float16,  0.1242,  1.2306, -89.90%
ATTENTION ^^^^^^^
 1, 128, 128,  256,   3,   3,  256,  (1, 1),  (1, 1),   256, float16,  0.1044,  0.6541, -84.04%
ATTENTION ^^^^^^^

After:

 N,   H,   W,    C   kH,  kW,    O, strides, padding, groups,  dtype, time_pt, time_mx, diff%
 1, 512, 512,  128,   3,   3,  128,  (2, 2),  (1, 1),   128, float16,  0.6689,  0.1321, +406.28%
 1, 256, 256,  128,   7,   7,  128,  (1, 1),  (3, 3),   128, float16,  0.2141,  0.1829, +17.11%
 1, 256, 256,  128,   3,   3,  128,  (1, 1),  (1, 1),   128, float16,  0.1647,  0.1077, +52.85%
 1, 128, 128,  256,   7,   7,  256,  (1, 1),  (3, 3),   256, float16,  0.1244,  0.0987, +26.06%
 1, 128, 128,  256,   3,   3,  256,  (1, 1),  (1, 1),   256, float16,  0.1049,  0.0619, +69.41%

@jagrit06 jagrit06 requested review from angeloskath and awni April 2, 2025 22:52
Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

This looks awesome!

@jagrit06 jagrit06 force-pushed the depthwise-conv2d-2 branch from ae75cec to 15abba6 Compare April 3, 2025 16:25
@jagrit06 jagrit06 merged commit 8777fd1 into main Apr 3, 2025
4 checks passed
@jagrit06 jagrit06 deleted the depthwise-conv2d-2 branch April 3, 2025 16:42
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