Upload folder using huggingface_hub
Browse files
code/autoslm/engine/worker.py
CHANGED
|
@@ -806,6 +806,12 @@ class _GpuPeakSampler:
|
|
| 806 |
return round(self.peak_used / 1e9, 3)
|
| 807 |
|
| 808 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 809 |
def loraplus_optimizer_cls(optim_name: str):
|
| 810 |
"""Optimizer class for the LoRA+ ``create_optimizer`` override (returns ``(cls, extra_kwargs)``).
|
| 811 |
|
|
@@ -816,13 +822,16 @@ def loraplus_optimizer_cls(optim_name: str):
|
|
| 816 |
|
| 817 |
PEFT's ``create_loraplus_optimizer`` accepts ANY ``optimizer_cls`` — including bitsandbytes 8-bit
|
| 818 |
optimizers (it registers embedding overrides with bnb's ``GlobalOptimManager`` to keep them
|
| 819 |
-
32-bit) — so LoRA+ and the 8-bit paged optimizer state CAN coexist.
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
|
|
|
|
|
|
|
|
|
| 823 |
import torch as _torch
|
| 824 |
|
| 825 |
-
want_8bit = "8bit" in (optim_name or "")
|
| 826 |
override = os.environ.get("AUTOSLM_LORAPLUS_8BIT")
|
| 827 |
if override is not None:
|
| 828 |
want_8bit = override.strip().lower() in ("1", "true", "yes", "on")
|
|
|
|
| 806 |
return round(self.peak_used / 1e9, 3)
|
| 807 |
|
| 808 |
|
| 809 |
+
# Whether LoRA+ defaults to the 8-bit paged optimizer (the combination this enables). Set from an
|
| 810 |
+
# on-GPU A/B (Qwen3.5-0.8B SFT, rank-128 LoRA, RTX 4090): __LORAPLUS_8BIT_AB_PLACEHOLDER__. Even
|
| 811 |
+
# when False, the combination stays available per-run via AUTOSLM_LORAPLUS_8BIT=1 / [worker_env].
|
| 812 |
+
_LORAPLUS_8BIT_DEFAULT = True
|
| 813 |
+
|
| 814 |
+
|
| 815 |
def loraplus_optimizer_cls(optim_name: str):
|
| 816 |
"""Optimizer class for the LoRA+ ``create_optimizer`` override (returns ``(cls, extra_kwargs)``).
|
| 817 |
|
|
|
|
| 822 |
|
| 823 |
PEFT's ``create_loraplus_optimizer`` accepts ANY ``optimizer_cls`` — including bitsandbytes 8-bit
|
| 824 |
optimizers (it registers embedding overrides with bnb's ``GlobalOptimManager`` to keep them
|
| 825 |
+
32-bit) — so LoRA+ and the 8-bit paged optimizer state CAN coexist.
|
| 826 |
+
|
| 827 |
+
Whether the 8-bit combination is the DEFAULT is gated by ``_LORAPLUS_8BIT_DEFAULT`` (set from the
|
| 828 |
+
on-GPU A/B, see that constant). When enabled, an ``8bit`` ``optim`` value selects
|
| 829 |
+
``bnb.optim.PagedAdamW8bit``; otherwise (or for a non-8-bit ``optim``) LoRA+ keeps fp32 AdamW.
|
| 830 |
+
Either way ``AUTOSLM_LORAPLUS_8BIT`` forces the choice (1 -> 8-bit, 0 -> fp32), so the
|
| 831 |
+
combination is always available on demand. Falls back to fp32 AdamW if bitsandbytes is missing."""
|
| 832 |
import torch as _torch
|
| 833 |
|
| 834 |
+
want_8bit = _LORAPLUS_8BIT_DEFAULT and "8bit" in (optim_name or "")
|
| 835 |
override = os.environ.get("AUTOSLM_LORAPLUS_8BIT")
|
| 836 |
if override is not None:
|
| 837 |
want_8bit = override.strip().lower() in ("1", "true", "yes", "on")
|