-
Notifications
You must be signed in to change notification settings - Fork 309
NVfp4 #2408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NVfp4 #2408
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2408
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 PendingAs of commit 4fe3daf with merge base 4e25496 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
c58c5b0
to
3948f5d
Compare
3948f5d
to
1025236
Compare
1025236
to
1c007a4
Compare
1c007a4
to
a3d2874
Compare
a3d2874
to
034f892
Compare
034f892
to
92e0622
Compare
92e0622
to
b2c45a1
Compare
b2c45a1
to
7448f45
Compare
7448f45
to
fad58b5
Compare
fad58b5
to
b5a593d
Compare
b5a593d
to
2b4ba64
Compare
2b4ba64
to
5d50579
Compare
5d50579
to
29fa9ef
Compare
47bcbb8
to
c50c936
Compare
c50c936
to
22ac909
Compare
22ac909
to
e91b055
Compare
e91b055
to
efdd0b1
Compare
efdd0b1
to
b4f3d1d
Compare
@vkuzo updated to use the mm_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some comments
b4f3d1d
to
d5bded3
Compare
|
||
|
||
@implements([torch.nn.functional.linear, aten.linear.default]) | ||
def nvfp4_linear(func, types, args, kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious on why we need both linear
and mm
flavors instead of picking one? I thought linear
was for torch function and mm variants for torch dispatch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need the mm and addmm in most circumstances, however if you run under inference mdoe that is pre-dispatch you end up see these linear ops
|
||
data_scaled = torch.clamp(data_scaled, -F4_E2M1_MAX, F4_E2M1_MAX) | ||
data_scaled = data_scaled.view(orig_shape) | ||
data_lp = f32_to_f4_unpacked(data_scaled.float()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember this function was being pretty slow when we wrote the emulation code, curious how performance is now? There are likely things we can do to make it faster if this is in the hot path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah @gaunerst has a nice triton kernel for doing the cast + pack that I am going to try in a follow up PR
e9d6a04
to
90db2ae
Compare
90db2ae
to
4fe3daf
Compare
Stacked PRs:
Add NVFP4 Inference flow
Details:
I kept this separate for MX but realistically we should probably merge the two. Basic support for blocksize 16 + e4m3 scales.
Double Quant Update
Ignore previous comments, the double quant is actually really similar to NF4 where you just scale the fp32 scales prior to casting to e4m3 to try and reduce
scale quant error
.I have that implemented now in the Nvfp4 code if a tesor_scale is given, just need to figure out how to thread to cublas param
scale_in_d
or how we want to expose this. We currently don't expose the C matrix to the Python API so we could use alpha as @gau-nernst pointed out to me, however we dont expose alpha either 🙃. However if we wanted to use alpha we would need the value on the host, the sync would likely rule out this option. I might keep this double quant on hold until we have the public api, since I am thinking about addingscale
overloads to addmm. However I read the cublas docs many times and it feels as though passing to scale result should work since we don't set the d_mode and its default value should work.Early Perf
No double quant here
which is even worse than mxfp4..., will profile later
Micro Bench
LLama 70B mlp no TP:
Diffusers
Errors
Annoyingly we are getting an error due to the
view as fp4x2
+ packing https://fburl.com/cd92w431 because this is trying to be bitcast iside inside triton kernel which is very annoying. Not sure how this didn't show up until vllm / w/ mxfp4^ similar to this: triton-lang/triton#6054 but make the same changes in _inductor/utils.py as we did for float8em0
Numerics
Script: https://gist.github.com/drisspg/4024ed055a6db911495102614c674c4c -> still emulating till we fix this bug in cublaslt bindings

Double quant really helps w/ tensor that have very small amax values, likely by reducing the amount of underflows will verify:
Flow