-
Notifications
You must be signed in to change notification settings - Fork 81
feat: Implement bitwise weight correctness checker for Miles-SGLang sync #415
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Ratish1, 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 reliability of model deployment by introducing a robust bitwise weight correctness checker. This system ensures that model weights transferred from the Miles training framework to the SGLang inference engine maintain their exact bit-level representation, crucial for preventing subtle performance degradations or errors due to weight discrepancies in distributed environments. The implementation covers both the generation of ground-truth hashes on the training side and a sophisticated multi-stage verification process on the inference side, including handling of sharded parameters. 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.
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 introduces a bitwise weight correctness checker, which is a valuable feature for ensuring model state synchronization between the training and inference engines. The implementation is comprehensive, covering both the training (Miles) and inference (SGLang) sides, along with integration tests. My review focuses on ensuring the correctness and robustness of this new checker. I've identified a few high-severity issues, including a potential data type mismatch during checksum calculation, an inconsistent condition for checksum generation, and a missing None check that could lead to a runtime error. I have also provided several medium-severity suggestions to improve code clarity, maintainability, and adherence to best practices. Addressing these points will enhance the reliability and quality of this new feature.
| if self.args.enable_weight_checker or self.args.check_weight_update_equal: | ||
| for name, tensor in converted_named_tensors: | ||
| t_cpu = tensor.detach().cpu().contiguous() | ||
| self._last_checksums[name] = hashlib.sha256(t_cpu.view(torch.uint8).numpy()).hexdigest() |
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.
The checksum is calculated here using the tensor's original data type. However, the corresponding verification logic on the SGLang side hardcodes a cast to torch.bfloat16 before hashing. This discrepancy will cause checksum validation to fail if the tensor's dtype is not already bfloat16. To ensure a correct bitwise comparison, you should cast the tensor to bfloat16 here as well before computing the hash.
| if self.args.enable_weight_checker or self.args.check_weight_update_equal: | |
| for name, tensor in converted_named_tensors: | |
| t_cpu = tensor.detach().cpu().contiguous() | |
| self._last_checksums[name] = hashlib.sha256(t_cpu.view(torch.uint8).numpy()).hexdigest() | |
| if self.args.enable_weight_checker or self.args.check_weight_update_equal: | |
| for name, tensor in converted_named_tensors: | |
| t_cpu = tensor.to(torch.bfloat16).detach().cpu().contiguous() | |
| self._last_checksums[name] = hashlib.sha256(t_cpu.view(torch.uint8).numpy()).hexdigest() |
miles/backends/megatron_utils/update_weight/update_weight_from_tensor.py
Outdated
Show resolved
Hide resolved
|
Great work so far. I strongly suggest that we shall first submit the patch of SGLang to SGLang directly. Then come back to use it in Miles. Could we do it as I described. Thanks! |
Yes, I will open a PR in SGlang today itself. Thanks. |
Description
This PR implements a Bitwise Weight Correctness Checker to verify that model weights synced from the Miles training engine (Megatron-LM) to the SGLang inference engine are bit-for-bit identical. #405
Key Changes