mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[GH-ISSUE #102] [Help] Starter script for nn.Linear for fwd,bwd #56
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#56
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @heuristicoder on GitHub (May 17, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepGEMM/issues/102
It would be great to show an example that implements simple nn.Linear with both forward and backward pass. A small starter script would be helpful.
@LyricZhao commented on GitHub (May 22, 2025):
We currectly don't encourage users to this, as we are not open-sourcing some fast util kernels (e.g. casting/scaling factor transposing), so if you don't have such things in this Linear, the performance will be bad.
We will open-source them later, with example Linear module as well.
If you don't care about performance, here is a pseduo code (this is somehow basic, you could also search on the Internet for some general tutorials):
@heuristicoder commented on GitHub (May 22, 2025):
@LyricZhao Thanks,
Also another question would be deep_gemm.gemm_fp8_fp8_bf16_nt, transposes matrix RHS internally. Hence the shape of RHS is set as:
However I observed that scales of RHS are not transposed internally when computing C scales. We are computing it as LHS_scale * RHS_scale. But intuitively, shouldn't it be LHS_scales * RHS_scales.T since we wanna do x @ W.T ?
Am I missing something here?
@LyricZhao commented on GitHub (May 23, 2025):
auto local_scales_b = scales_b + (num_previous_lines + ((n_block_idx * BLOCK_N) / BLOCK_K)) * SHAPE_K_SCALES;reads a whole row of(ceil_div(n, 128), ceil_div(k, 128)), the row shape is(1, ceil_div(k, 128)), which is used for later all K blocks.@heuristicoder commented on GitHub (May 28, 2025):
Got it, thanks. Is there any update on when all the kernels for a full Linear layer will be released?
@LyricZhao commented on GitHub (May 28, 2025):
Maybe by the end of the year :)
@goldhuang commented on GitHub (Jul 26, 2025):
@LyricZhao Is it a good idea to fuse casting and scaling to the gemm kernel? (per token for a and per block for b). Seems feasible. I'm looking into it and find that it will increase the pressure either on shared memory or register usage, as we need extra array for b16 input a and b, beside the fp8 a and b.
I see you mentioned fast util kernels. Did you keep these kernels separate or did you try to fuse them together?
Thanks a lot in advance if you could share some experiences on your side so that I would not waste my time to fuse the kernels but later find it becomes slower!
@heuristicoder commented on GitHub (Jul 27, 2025):
That would be a great addition, and makes the library much more useful for a lot of use cases then just inference
@LyricZhao commented on GitHub (Jul 30, 2025):
No, we should fuse cast/scaling into the previous kernels' output, HBM bandwidth could also be saved.
Fuse as much as you can.