quanto + musubi block swap compatibility - #2865
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the Musubi block swap helper to correctly detect and move Optimum Quanto quantized tensors (including their internal backing tensors) across devices without relying on Module.to()/_apply, and adds a targeted unit test to validate the behavior with QLinear when _apply is unusable.
Changes:
- Added Quanto-aware device comparison and tensor/module transfer helpers to safely move quantized weights and their internal tensors.
- Updated
MusubiBlockSwapManager._move_module()to use the custom transfer path when Quanto quantized tensors are present, otherwise preserving the existing.to(device)behavior. - Added a new
unittestvalidating block swap streaming for a Quanto-quantized module withQLinear._applyforced to fail.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
simpletuner/helpers/musubi_block_swap.py |
Adds Quanto tensor detection + custom, recursion-safe device transfer and uses it during block streaming when needed. |
tests/test_musubi_block_swap.py |
Introduces a regression test ensuring quantized blocks can stream in/out even when QLinear._apply errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances device management for quantized tensors in the Musubi block swap helper and introduces comprehensive tests for these scenarios. The main improvements are the addition of specialized logic to correctly detect, move, and verify "quanto" quantized tensors within modules, and the introduction of a test suite to ensure correct behavior, especially when standard PyTorch methods cannot be used.
Device management for quantized tensors:
_same_device,_is_quanto_tensor,_tensor_on_device,_module_has_quanto_tensor,_move_quanto_tensor_to_device,_move_module_without_swapping_quanto_params) to detect and recursively move "quanto" quantized tensors and their sub-tensors to the correct device, ensuring all relevant attributes are properly transferred._move_modulemethod to use the custom quanto-aware logic when quantized tensors are present, falling back to the default.to(device)otherwise.Testing improvements:
tests/test_musubi_block_swap.pyto verify correct streaming of quantized modules, including handling ofQLinearlayers and fallback logic when the standard_applymethod fails.These changes ensure robust support for quantized models and improve test coverage for device transfer logic.