Skip to content

ramtorch + quanto + PEFT: fixes for moving between devices#2884

Merged
bghira merged 1 commit into
mainfrom
bugfix/ramtorch-quanto-activations
Jul 23, 2026
Merged

ramtorch + quanto + PEFT: fixes for moving between devices#2884
bghira merged 1 commit into
mainfrom
bugfix/ramtorch-quanto-activations

Conversation

@bghira

@bghira bghira commented Jul 23, 2026

Copy link
Copy Markdown
Owner

This pull request introduces improvements to device management for LoRA adapters in both quantized and standard PEFT Linear layers. The main focus is to ensure LoRA adapter weights are always moved to the correct device (e.g., GPU or CPU) during forward passes, preventing device mismatch errors, especially when quantization or offloading is in use. The logic for handling this device movement is now centralized and shared across custom and patched PEFT layers.

Device management improvements:

  • Added _move_peft_lora_adapters_to_device utility to centralize logic for moving LoRA adapter weights to the correct device, handling both single and multiple active adapters. (simpletuner/helpers/utils/ramtorch.py)
  • Updated RamTorchPeftLinear._ensure_lora_on_device to use the new centralized device movement logic, reducing code duplication and improving reliability. (simpletuner/helpers/utils/ramtorch.py) [1] [2]

PEFT Linear patching:

  • Introduced _maybe_patch_peft_lora_forward to monkey-patch the forward method of PEFT's stock Linear layer, ensuring device movement logic is applied even when the standard PEFT wrapper is used. (simpletuner/helpers/utils/ramtorch.py)
  • Ensured that ensure_available calls the new patching function to activate the forward patch when RamTorch is in use. (simpletuner/helpers/utils/ramtorch.py)

Quantized LoRA support:

  • Added _ensure_lora_adapter_on_device helper and integrated it into the forward passes of quantized LoRA layers to keep adapter weights on the correct device. (simpletuner/helpers/training/quantisation/peft_workarounds.py) [1] [2] [3]

These changes make device handling for LoRA adapters more robust and consistent across quantized and non-quantized workflows, reducing the risk of runtime errors due to device mismatches.

@bghira
bghira merged commit 7a04013 into main Jul 23, 2026
2 checks passed
@bghira
bghira deleted the bugfix/ramtorch-quanto-activations branch July 23, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant