fp8_gemm def update and workload#79
Conversation
YiyanZhai
left a comment
There was a problem hiding this comment.
WIP: reference impl
Summary of ChangesHello @YiyanZhai, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the definition and implementation of FP8 General Matrix Multiply (GEMM) operations by introducing block-wise scaling factors for inputs Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates several fp8 GEMM definitions to use block-wise scaling and adds corresponding workloads with pre-generated data. While the move to use .safetensors for workloads is a good improvement for deterministic benchmarking, I've found critical issues in the definition files. The Python reference implementation for dequantization is incorrect in all updated definitions, as it hasn't been updated to support the new block-wise scaling scheme. Additionally, one of the definitions (gemm_fp8_n7168_k2304.json) contains an invalid value for K-block-B that will lead to errors. These issues need to be addressed to ensure the correctness of the definitions and allow for successful verification.
| "K-block-A": { | ||
| "type": "const", | ||
| "value": 56, | ||
| "description": "Number of columns in each block of A for scale factors." | ||
| }, | ||
| "K-block-B": { | ||
| "type": "const", | ||
| "value": 14, | ||
| "description": "Number of columns in each block of B for scale factors." | ||
| } |
There was a problem hiding this comment.
The reference implementation on line 73 is now incorrect due to the changes for block-wise scaling. The dequantization logic A_scale.view(-1, 1) is for per-tensor or per-row scaling and will fail with the new 2D A_scale and B_scale tensors. The reference implementation needs to be updated to correctly handle block-wise dequantization.
A correct implementation would be:
"reference": "import torch\n\ndef run(A, B, A_scale, B_scale):\n A_scale_rep = A_scale.repeat_interleave(A.shape[1] // A_scale.shape[1], dim=1)\n A_deq = A.to(torch.float32) * A_scale_rep\n B_scale_rep = B_scale.repeat_interleave(B.shape[1] // B_scale.shape[1], dim=1)\n B_deq = B.to(torch.float32) * B_scale_rep\n C = torch.matmul(A_deq, B_deq.T)\n return C.to(torch.bfloat16)"Since I cannot comment on line 73 directly, I'm adding this comment here. Please update the reference field.
| "K-block-A": { | ||
| "type": "const", | ||
| "value": 12, | ||
| "description": "Number of columns in each block of A for scale factors." | ||
| }, | ||
| "K-block-B": { | ||
| "type": "const", | ||
| "value": 3, | ||
| "description": "Number of columns in each block of B for scale factors." | ||
| } |
There was a problem hiding this comment.
The reference implementation on line 73 is now incorrect due to the changes for block-wise scaling. The dequantization logic A_scale.view(-1, 1) is for per-tensor or per-row scaling and will fail with the new 2D A_scale and B_scale tensors. The reference implementation needs to be updated to correctly handle block-wise dequantization.
A correct implementation would be:
"reference": "import torch\n\ndef run(A, B, A_scale, B_scale):\n A_scale_rep = A_scale.repeat_interleave(A.shape[1] // A_scale.shape[1], dim=1)\n A_deq = A.to(torch.float32) * A_scale_rep\n B_scale_rep = B_scale.repeat_interleave(B.shape[1] // B_scale.shape[1], dim=1)\n B_deq = B.to(torch.float32) * B_scale_rep\n C = torch.matmul(A_deq, B_deq.T)\n return C.to(torch.bfloat16)"Since I cannot comment on line 73 directly, I'm adding this comment here. Please update the reference field.
| "K-block-A": { | ||
| "type": "const", | ||
| "value": 4, | ||
| "description": "Number of columns in each block of A for scale factors." | ||
| }, | ||
| "K-block-B": { | ||
| "type": "const", | ||
| "value": 1, | ||
| "description": "Number of columns in each block of B for scale factors." | ||
| } |
There was a problem hiding this comment.
The reference implementation on line 73 is now incorrect due to the changes for block-wise scaling. The dequantization logic A_scale.view(-1, 1) is for per-tensor or per-row scaling and will fail with the new 2D A_scale and B_scale tensors. The reference implementation needs to be updated to correctly handle block-wise dequantization.
A correct implementation would be:
"reference": "import torch\n\ndef run(A, B, A_scale, B_scale):\n A_scale_rep = A_scale.repeat_interleave(A.shape[1] // A_scale.shape[1], dim=1)\n A_deq = A.to(torch.float32) * A_scale_rep\n B_scale_rep = B_scale.repeat_interleave(B.shape[1] // B_scale.shape[1], dim=1)\n B_deq = B.to(torch.float32) * B_scale_rep\n C = torch.matmul(A_deq, B_deq.T)\n return C.to(torch.bfloat16)"Since I cannot comment on line 73 directly, I'm adding this comment here. Please update the reference field.
| "K-block-A": { | ||
| "type": "const", | ||
| "value": 56, | ||
| "description": "Number of columns in each block of A for scale factors." | ||
| }, | ||
| "K-block-B": { | ||
| "type": "const", | ||
| "value": 14, | ||
| "description": "Number of columns in each block of B for scale factors." | ||
| } |
There was a problem hiding this comment.
The reference implementation on line 73 is now incorrect due to the changes for block-wise scaling. The dequantization logic A_scale.view(-1, 1) is for per-tensor or per-row scaling and will fail with the new 2D A_scale and B_scale tensors. The reference implementation needs to be updated to correctly handle block-wise dequantization.
A correct implementation would be:
"reference": "import torch\n\ndef run(A, B, A_scale, B_scale):\n A_scale_rep = A_scale.repeat_interleave(A.shape[1] // A_scale.shape[1], dim=1)\n A_deq = A.to(torch.float32) * A_scale_rep\n B_scale_rep = B_scale.repeat_interleave(B.shape[1] // B_scale.shape[1], dim=1)\n B_deq = B.to(torch.float32) * B_scale_rep\n C = torch.matmul(A_deq, B_deq.T)\n return C.to(torch.bfloat16)"Since I cannot comment on line 73 directly, I'm adding this comment here. Please update the reference field.
| "K-block-A": { | ||
| "type": "const", | ||
| "value": 16, | ||
| "description": "Number of columns in each block of A for scale factors." | ||
| }, | ||
| "K-block-B": { | ||
| "type": "const", | ||
| "value": 4, | ||
| "description": "Number of columns in each block of B for scale factors." | ||
| } |
There was a problem hiding this comment.
The reference implementation on line 73 is now incorrect due to the changes for block-wise scaling. The dequantization logic A_scale.view(-1, 1) is for per-tensor or per-row scaling and will fail with the new 2D A_scale and B_scale tensors. The reference implementation needs to be updated to correctly handle block-wise dequantization.
A correct implementation would be:
"reference": "import torch\n\ndef run(A, B, A_scale, B_scale):\n A_scale_rep = A_scale.repeat_interleave(A.shape[1] // A_scale.shape[1], dim=1)\n A_deq = A.to(torch.float32) * A_scale_rep\n B_scale_rep = B_scale.repeat_interleave(B.shape[1] // B_scale.shape[1], dim=1)\n B_deq = B.to(torch.float32) * B_scale_rep\n C = torch.matmul(A_deq, B_deq.T)\n return C.to(torch.bfloat16)"Since I cannot comment on line 73 directly, I'm adding this comment here. Please update the reference field.
| }, | ||
| "K-block-B": { | ||
| "type": "const", | ||
| "value": 5, |
There was a problem hiding this comment.
The value of K-block-B is 5, but the K dimension is 2304. For block-wise scaling to work, the K dimension must be divisible by the number of blocks. Since 2304 % 5 != 0, this configuration is invalid and will cause errors during dequantization. Please verify and provide a correct value for K-block-B that is a divisor of 2304. For example, K-block-A is 18, which divides 2304. Perhaps K-block-B should also be 18?
| "K-block-A": { | ||
| "type": "const", | ||
| "value": 18, | ||
| "description": "Number of columns in each block of A for scale factors." | ||
| }, | ||
| "K-block-B": { | ||
| "type": "const", | ||
| "value": 5, | ||
| "description": "Number of columns in each block of B for scale factors." | ||
| } |
There was a problem hiding this comment.
The reference implementation on line 73 is now incorrect due to the changes for block-wise scaling. The dequantization logic A_scale.view(-1, 1) is for per-tensor or per-row scaling and will fail with the new 2D A_scale and B_scale tensors. The reference implementation needs to be updated to correctly handle block-wise dequantization.
A correct implementation would be:
"reference": "import torch\n\ndef run(A, B, A_scale, B_scale):\n A_scale_rep = A_scale.repeat_interleave(A.shape[1] // A_scale.shape[1], dim=1)\n A_deq = A.to(torch.float32) * A_scale_rep\n B_scale_rep = B_scale.repeat_interleave(B.shape[1] // B_scale.shape[1], dim=1)\n B_deq = B.to(torch.float32) * B_scale_rep\n C = torch.matmul(A_deq, B_deq.T)\n return C.to(torch.bfloat16)"Since I cannot comment on line 73 directly, I'm adding this comment here. Please update the reference field.
No description provided.