ramtorch: percentage-based offload fix for text encoder moving to CPU and back inadvertently causing device mismatch error #2525
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 makes targeted improvements to how text encoders and linear layers are managed when using RamTorch, particularly around device placement and partial replacement scenarios. The changes ensure better compatibility and correctness when RamTorch is enabled, especially in mixed-device and percentage-based replacement cases.
Device management and RamTorch integration:
move_text_encoders(infactory.py) to always skip moving text encoders when RamTorch is enabled, regardless of the target device, to support both partial and full RamTorch setups.Partial RamTorch replacement handling:
replace_linear_layers_with_ramtorch(inramtorch.py), added logic to track remaining eligible layers when using percentage-based replacement, ensuring only the correct subset is replaced.nn.Linearlayers (or those matching specific patterns) are moved to the resolved device if they are still on CPU, maintaining device consistency.