Skip to content

Support DeepGEMM for deterministic inference#12142

Merged
fzyzcjy merged 5 commits intosgl-project:mainfrom
fzyzcjy:feat/deepgemm_det
Oct 26, 2025
Merged

Support DeepGEMM for deterministic inference#12142
fzyzcjy merged 5 commits intosgl-project:mainfrom
fzyzcjy:feat/deepgemm_det

Conversation

@fzyzcjy
Copy link
Copy Markdown
Collaborator

@fzyzcjy fzyzcjy commented Oct 26, 2025

Motivation

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @fzyzcjy, 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 enhances the matmul_persistent operation by integrating DeepGEMM, a specialized library for optimized matrix multiplication. The change introduces conditional logic to dynamically select between DeepGEMM and the existing Triton implementation based on configuration and tensor properties, aiming to improve performance or leverage specific hardware capabilities. An optional comparison test is included to ensure the numerical accuracy and deterministic nature of the DeepGEMM implementation.

Highlights

  • DeepGEMM Integration: Integrated DeepGEMM for matmul_persistent operations, providing an alternative to the existing Triton implementation for specific data types and tensor contiguity.
  • Conditional DeepGEMM Usage: Implemented conditional logic to leverage DeepGEMM when ENABLE_JIT_DEEPGEMM is enabled and input tensors are bfloat16 and contiguous, otherwise falling back to Triton.
  • Accuracy Verification: Added an optional comparison test (_ENABLE_MM_COMPARISON_TEST) to verify the numerical accuracy of DeepGEMM's output against the Triton implementation, ensuring deterministic inference.
  • Utility Function for Difference Calculation: Introduced a calc_diff utility function, copied from DeepGEMM's repository, to quantify the difference between two tensors for accuracy comparison.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for DeepGEMM for deterministic matrix multiplication, which is a good performance enhancement. The changes include a dispatcher to select between a new DeepGEMM implementation and the existing Triton kernel, along with a comparison test feature. My review focuses on improving correctness and maintainability. I've identified a critical issue where a dimension compatibility check is missing in the new DeepGEMM wrapper, and a medium-severity issue regarding a hardcoded value that should be a constant.

Comment thread python/sglang/srt/batch_invariant_ops/batch_invariant_ops.py
Comment thread python/sglang/srt/batch_invariant_ops/batch_invariant_ops.py
Comment thread python/sglang/srt/batch_invariant_ops/batch_invariant_ops.py
@fzyzcjy
Copy link
Copy Markdown
Collaborator Author

fzyzcjy commented Oct 26, 2025

seems unrelated

image image

@fzyzcjy fzyzcjy merged commit 0103f37 into sgl-project:main Oct 26, 2025
93 of 107 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants