[feature] Modify dsa kernels for dsa function#273
[feature] Modify dsa kernels for dsa function#273stelladuyx wants to merge 33 commits intotile-ai:mainfrom
Conversation
add dsa func test and benchmark
Summary of ChangesHello, 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 significantly enhances the DeepSeek MLA kernels by integrating Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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 introduces significant modifications across multiple components to add support for batching and grouped-query attention (via kv_group) to several DSA (DeepSeek Attention) kernels. The changes are extensive, affecting kernels, functions, layers, benchmarks, and tests. While the overall implementation direction is correct, I have identified several issues, including bugs in benchmark metric calculations, autotuning configurations, and tensor initializations within the kernels. Additionally, there are some code quality concerns, such as duplicated test code and debugging artifacts left in the kernel code. Addressing these points will improve the correctness and maintainability of the new features.
| def per_custom_dims_cast_to_fp8(self, x: torch.Tensor, dims: Tuple[int], | ||
| use_ue8m0: bool) -> Tuple[torch.Tensor, torch.Tensor]: | ||
| excluded_dims = tuple([i for i in range(x.dim()) if i not in set(dims)]) | ||
| x_amax = x.to(torch.float32).abs().float().amax(dim=excluded_dims, keepdim=True).clamp(1e-4) | ||
| sf = x_amax / 448.0 | ||
| x_absmax = x.to(torch.float32).abs().amax(dim=-1, keepdim=True).clamp(1e-4) | ||
| sf = x_absmax / 448.0 | ||
| if use_ue8m0: | ||
| assert sf.view(-1).amax().item() > 0 | ||
| sf = torch.pow(2.0, torch.ceil(torch.log2(x.abs()))) | ||
| sf = torch.pow(2.0, torch.ceil(torch.log2(x_absmax))) | ||
| x_scaled = (x * (1.0 / sf)).to(torch.float8_e4m3fn) | ||
| return x_scaled, sf.squeeze() | ||
| return x_scaled, sf.squeeze(-1) |
There was a problem hiding this comment.
The implementation of per_custom_dims_cast_to_fp8 has been changed to compute amax over the last dimension (dim=-1) instead of a more generic set of excluded dimensions. This aligns it with per-token quantization, which is what's needed here. The logic for calculating the scale factor and applying it seems correct for this purpose.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Description
Type of Change
Checklist
pre-commit run --all-filesand fixed all linting issues.Benchmarkclass inbenchmarks/.