Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Unsloth Studio / Desktop: per-GPU Block Swap budget and layer panel for multi-GPU training (#12998)
Leo Borcherding85ae421ee37c
diff --git a/studio/backend/core/training/trainer.py b/studio/backend/core/training/trainer.pyindex 7b3efd16a46..cfb33d0289d 100644--- a/studio/backend/core/training/trainer.py+++ b/studio/backend/core/training/trainer.py@@ -365,6 +365,8 @@ class UnslothTrainer:self._use_gradient_checkpointing = "unsloth"self._offload_layers = 0self._prefetch_depth = 2+ self._gpu_ids = None+ self._offload_layer_devices = Noneself._offload_plan_shape = {}# True until a probe says otherwise, so a path that never probes cannot trip the inconclusive-detection guard.self._audio_type_known = True@@ -615,11 +617,55 @@ class UnslothTrainer:get_fraction = getattr(torch.cuda, "get_per_process_memory_fraction", None)if get_fraction is not None:snap["vram_fraction"] = get_fraction(device)+ snap["vram_devices"] = self._offload_vram_devices()+ snap["layer_device"] = self._offload_layer_device_map(swapper)return snapexcept Exception as exc:logger.debug("offload stats unavailable: %s", exc)return None+ def _offload_vram_devices(self) -> list:+ gpu_ids = getattr(self, "_gpu_ids", None)+ get_fraction = getattr(torch.cuda, "get_per_process_memory_fraction", None)+ devices = []+ for i in range(torch.cuda.device_count()):+ entry = {+ "index": i,+ "gpu_id": gpu_ids[i] if gpu_ids and i < len(gpu_ids) else i,+ "name": torch.cuda.get_device_properties(i).name,+ "allocated_bytes": torch.cuda.memory_allocated(i),+ "peak_bytes": torch.cuda.max_memory_allocated(i),+ "total_bytes": torch.cuda.get_device_properties(i).total_memory,+ }+ if get_fraction is not None:+ entry["fraction"] = get_fraction(i)+ devices.append(entry)+ return devices++ def _offload_layer_device_map(self, swapper) -> dict:+ """Torch ordinal of every decoder layer: an offloaded one's home card, a resident one's weights."""+ key = (id(swapper), tuple(getattr(swapper, "indices", ())))+ cached = getattr(self, "_offload_layer_devices", None)+ if cached is not None and cached[0] == key:+ return cached[1]+ devices = {}+ for li, block in zip(getattr(swapper, "indices", ()), getattr(swapper, "blocks", ())):+ home = getattr(block, "home", None)+ if home is not None and home.type == "cuda" and home.index is not None:+ devices[str(li)] = home.index+ try:+ from unsloth_zoo.block_swap import find_decoder_layers+ for li, layer in enumerate(find_decoder_layers(self.model)):+ if str(li) in devices:+ continue+ p = next(layer.parameters(), None)+ if p is not None and p.device.type == "cuda" and p.device.index is not None:+ devices[str(li)] = p.device.index+ except Exception as exc:+ logger.debug("offload layer devices unavailable: %s", exc)+ self._offload_layer_devices = (key, devices)+ return devices+def _create_progress_callback(self):"""Create a TrainerCallback for progress tracking. Reused by all training branches."""from transformers import TrainerCallback@@ -960,6 +1006,8 @@ class UnslothTrainer:# Offloading streams frozen base weights, so it has nothing to do in a full finetune.self._offload_layers = 0 if full_finetuning else (offload_layers or 0)self._prefetch_depth = prefetch_depth or 2+ # Physical ids behind each torch ordinal, so the panel names cards as the settings do.+ self._gpu_ids = list(gpu_ids) if gpu_ids else Noneself._offload_plan_shape = {k: v for k, v in (offload_plan_shape or {}).items() if v}self.load_in_4bit = load_in_4bitself.trust_remote_code = trust_remote_codediff --git a/studio/backend/core/training/training.py b/studio/backend/core/training/training.pyindex df28984429f..9afce90d38e 100644--- a/studio/backend/core/training/training.py+++ b/studio/backend/core/training/training.py@@ -305,6 +305,7 @@ def _build_training_worker_config(values: dict[str, Any]) -> dict[str, Any]:"gradient_checkpointing": values.get("gradient_checkpointing", "unsloth"),"offload_layers": values.get("offload_layers") or 0,"offload_vram_gb": values.get("offload_vram_gb"),+ "offload_vram_gb_per_device": values.get("offload_vram_gb_per_device"),"prefetch_depth": values.get("prefetch_depth") or 2,"use_rslora": values.get("use_rslora", False),"use_loftq": values.get("use_loftq", False),diff --git a/studio/backend/core/training/worker.py b/studio/backend/core/training/worker.pyindex 8d79e41debd..909daf0c753 100644--- a/studio/backend/core/training/worker.py+++ b/studio/backend/core/training/worker.py@@ -1652,6 +1652,58 @@ def _training_vram_budget_fraction(return min(current, budget * 1024**3 / denominator_bytes)+def _apply_training_vram_budget(+ torch_mod: Any, single_gb: float | None, per_device_gb: list | None, gpu_ids: list | None+) -> dict[int, float]:+ """Cap each visible device at its own budget; returns {ordinal: fraction} for what was set."""+ applied: dict[int, float] = {}+ if not torch_mod.cuda.is_available():+ return applied+ get_fraction = getattr(torch_mod.cuda, "get_per_process_memory_fraction", None)+ divides_by_props = _allocator_divides_by_props_total(getattr(torch_mod, "__version__", ""))+ for index in range(torch_mod.cuda.device_count()):+ budget = _device_budget_gb(single_gb, per_device_gb, index, gpu_ids)+ if not budget:+ continue+ props = torch_mod.cuda.get_device_properties(index)+ denominator = int(getattr(props, "total_memory", 0) or 0)+ if not divides_by_props:+ denominator = int(torch_mod.cuda.mem_get_info(index)[1])+ current = get_fraction(index) if get_fraction is not None else 1.0+ fraction = _training_vram_budget_fraction(budget, denominator, current)+ if fraction is None:+ continue+ torch_mod.cuda.set_per_process_memory_fraction(fraction, index)+ applied[index] = fraction+ logger.info(+ "Training VRAM budget: set_per_process_memory_fraction(%.4f, cuda:%d), "+ "%.1f GiB of %.1f GiB",+ fraction,+ index,+ fraction * denominator / 1024**3,+ denominator / 1024**3,+ )+ return applied+++def _device_budget_gb(+ single_gb: float | None,+ per_device_gb: list | None,+ ordinal: int,+ gpu_ids: list | None = None,+) -> float | None:+ """The budget for torch device ``ordinal``. ``per_device_gb`` is indexed by physical GPU id, so+ the ordinal goes through ``gpu_ids`` (the CUDA_VISIBLE_DEVICES narrowing) first; when it is+ given, a missing or null entry means no cap on that card."""+ if not per_device_gb:+ return single_gb+ physical = gpu_ids[ordinal] if gpu_ids and ordinal < len(gpu_ids) else ordinal+ try:+ return per_device_gb[int(physical)]+ except (IndexError, TypeError, ValueError):+ return None++def _offload_plan_shape(config: dict) -> dict:"""The per-device batch and LoRA rank an Auto offload plan sizes its training reserve for."""return {"batch_size": config.get("batch_size"), "lora_rank": config.get("lora_r")}@@ -1669,11 +1721,19 @@ def _visible_gpu_count() -> int:def _with_vram_budget_hint(config: dict, message: str) -> str:"""Point a run that does not fit at its own VRAM budget, the one cause the generic advice omits."""budget = config.get("offload_vram_gb")+ per_device = [gb for gb in config.get("offload_vram_gb_per_device") or [] if gb]lower = (message or "").lower()- if not budget or not any(k in lower for k in ("out of memory", "out of vram", "does not fit")):+ if not (budget or per_device) or not any(+ k in lower for k in ("out of memory", "out of vram", "does not fit")+ ):return message+ cap = (+ f"a {budget:g} GiB VRAM budget"+ if budget and not per_device+ else "per-GPU VRAM budgets (" + ", ".join(f"{gb:g}" for gb in per_device) + " GiB)"+ )return (- f"{message}\nThis run is capped at a {budget:g} GiB VRAM budget. Raise or clear the "+ f"{message}\nThis run is capped at {cap}. Raise or clear the ""VRAM budget under Training Hyperparameters > Memory.")@@ -4236,10 +4296,9 @@ def run_training_process(*, event_queue: Any, stop_queue: Any, config: dict) -># Offload layers sizes "auto" to what the allocator may use, so a budget makes the run fit in it,# and two runs on one card can each take their share.# ── 2b. Training VRAM budget ──- _budget_gb = config.get("offload_vram_gb")# Only "auto" sizes to a budget, and only LoRA runs outside decision / embedding offload._wants_budget = bool(- _budget_gb+ (config.get("offload_vram_gb") or config.get("offload_vram_gb_per_device"))and config.get("offload_layers") == "auto"and config.get("training_type", "LoRA/QLoRA") in ("LoRA/QLoRA", "Continued Pretraining")and not config.get("is_decision")@@ -4259,35 +4318,16 @@ def run_training_process(*, event_queue: Any, stop_queue: Any, config: dict) ->)# An out-of-memory error then must not blame a cap that was never set.config["offload_vram_gb"] = None+ config["offload_vram_gb_per_device"] = Noneelif _wants_budget:try:import torch as _torch_budget- if _torch_budget.cuda.is_available():- for _b_index in range(_torch_budget.cuda.device_count()):- _b_props = _torch_budget.cuda.get_device_properties(_b_index)- _b_denominator = int(getattr(_b_props, "total_memory", 0) or 0)- if not _allocator_divides_by_props_total(- getattr(_torch_budget, "__version__", "")- ):- _b_denominator = int(_torch_budget.cuda.mem_get_info(_b_index)[1])- _get_fraction = getattr(- _torch_budget.cuda, "get_per_process_memory_fraction", None- )- _b_current = _get_fraction(_b_index) if _get_fraction is not None else 1.0- _b_fraction = _training_vram_budget_fraction(- _budget_gb, _b_denominator, _b_current- )- if _b_fraction is None:- continue- _torch_budget.cuda.set_per_process_memory_fraction(_b_fraction, _b_index)- logger.info(- "Training VRAM budget: set_per_process_memory_fraction(%.4f, cuda:%d), "- "%.1f GiB of %.1f GiB",- _b_fraction,- _b_index,- _b_fraction * _b_denominator / 1024**3,- _b_denominator / 1024**3,- )+ _apply_training_vram_budget(+ _torch_budget,+ config.get("offload_vram_gb"),+ config.get("offload_vram_gb_per_device"),+ gpu_ids,+ )except Exception as _budget_err:logger.warning("Could not apply the training VRAM budget: %s", _budget_err)diff --git a/studio/backend/models/training.py b/studio/backend/models/training.pyindex 5c22722269d..a9ded5d195c 100644--- a/studio/backend/models/training.py+++ b/studio/backend/models/training.py@@ -586,6 +586,14 @@ class TrainingStartRequest(BaseModel):le = 4096,description = "VRAM this run may use, in GiB; offload_layers = 'auto' sizes to it",)+ offload_vram_gb_per_device: Optional[List[Optional[Annotated[float, Field(gt = 0, le = 4096)]]]] = (+ Field(+ None,+ max_length = 64,+ description = "Per-GPU VRAM budget in GiB, entry i for the GPU /api/system lists as index i "+ "(null = no cap); replaces offload_vram_gb when given",+ )+ )prefetch_depth: Union[Literal["auto"], Annotated[int, Field(ge = 1, le = 8)]] = Field(2,description = "Offloaded layers fetched ahead of the one running ('auto' = measured)",diff --git a/studio/backend/routes/training.py b/studio/backend/routes/training.pyindex 1a536959500..a3094969bb4 100644--- a/studio/backend/routes/training.py+++ b/studio/backend/routes/training.py@@ -1987,6 +1987,7 @@ async def start_training(else "unsloth","offload_layers": request.offload_layers,"offload_vram_gb": request.offload_vram_gb,+ "offload_vram_gb_per_device": request.offload_vram_gb_per_device,"prefetch_depth": request.prefetch_depth,"use_rslora": request.use_rslora,"use_loftq": request.use_loftq,diff --git a/studio/backend/tests/test_training_offload_layers.py b/studio/backend/tests/test_training_offload_layers.pyindex 70362db17dd..a5d298555d7 100644--- a/studio/backend/tests/test_training_offload_layers.py+++ b/studio/backend/tests/test_training_offload_layers.py@@ -7,13 +7,18 @@ load and LoRA path receives, and the live snapshot the training view polls."""from __future__ import annotationsimport sys-from types import SimpleNamespace+from types import ModuleType, SimpleNamespaceimport pytestfrom pydantic import ValidationErrorfrom core.training.training import _build_training_worker_config-from core.training.worker import _training_vram_budget_fraction, _with_vram_budget_hint+from core.training.worker import (+ _apply_training_vram_budget,+ _device_budget_gb,+ _training_vram_budget_fraction,+ _with_vram_budget_hint,+)from models.training import TrainingStartRequestGIB = 1024**3@@ -53,6 +58,18 @@ def test_vram_budget_must_be_positive():_request(offload_vram_gb = 0)+def test_per_device_budget_defaults_off_and_takes_nulls():+ assert _request().offload_vram_gb_per_device is None+ r = _request(offload_vram_gb_per_device = [8, None, 12.5])+ assert r.offload_vram_gb_per_device == [8, None, 12.5]++[email protected]("value", [[0], [-1, 8], [5000], [8, "x"], [float("nan")], [1.0] * 65])+def test_per_device_budget_refuses_what_a_single_budget_would(value):+ with pytest.raises(ValidationError):+ _request(offload_vram_gb_per_device = value)++def test_worker_config_carries_the_offload_fields():cfg = _build_training_worker_config({@@ -69,6 +86,11 @@ def test_worker_config_carries_the_offload_fields():)off = _build_training_worker_config({"model_name": "org/model"})assert (off["offload_layers"], off["offload_vram_gb"], off["prefetch_depth"]) == (0, None, 2)+ assert off["offload_vram_gb_per_device"] is None+ per = _build_training_worker_config(+ {"model_name": "org/model", "offload_vram_gb_per_device": [10.0, None]}+ )+ assert per["offload_vram_gb_per_device"] == [10.0, None]def test_budget_fraction_holds_the_run_to_its_gib():@@ -81,6 +103,89 @@ def test_budget_fraction_holds_the_run_to_its_gib():assert _training_vram_budget_fraction(8, 0) is None+def test_device_budget_falls_back_to_the_single_budget():+ assert _device_budget_gb(8, None, 0) == 8 and _device_budget_gb(8, None, 3) == 8+ assert _device_budget_gb(None, None, 0) is None+ assert _device_budget_gb(8, [], 1) == 8+++def test_device_budget_reads_each_cards_own_entry():+ per = [10.0, None, 6.0]+ assert [_device_budget_gb(99, per, i) for i in range(4)] == [10.0, None, 6.0, None]+ # Training narrowed to physical GPUs 2 and 0: ordinal 0 is GPU 2.+ assert _device_budget_gb(None, per, 0, [2, 0]) == 6.0+ assert _device_budget_gb(None, per, 1, [2, 0]) == 10.0+++class _FakeCuda:+ def __init__(+ self,+ totals,+ current = None,+ ):+ self.totals, self.set, self.current = totals, {}, current or {}++ def is_available(self):+ return True++ def device_count(self):+ return len(self.totals)++ def get_device_properties(self, i):+ return SimpleNamespace(total_memory = self.totals[i])++ def mem_get_info(self, i):+ return (0, self.totals[i])++ def get_per_process_memory_fraction(self, i):+ return self.current.get(i, 1.0)++ def set_per_process_memory_fraction(self, fraction, i):+ self.set[i] = fraction+++def _fake_torch(totals, current = None):+ return SimpleNamespace(__version__ = "2.8.0", cuda = _FakeCuda(totals, current))+++def test_per_device_budget_sets_each_cards_own_fraction():+ torch_mod = _fake_torch([32 * GIB, 16 * GIB, 24 * GIB])+ # The list replaces the single budget, and a null entry leaves that card uncapped.+ assert _apply_training_vram_budget(torch_mod, 99, [8, 12, None], None) == pytest.approx(+ {0: 0.25, 1: 0.75}+ )+ assert torch_mod.cuda.set == pytest.approx({0: 0.25, 1: 0.75})+++def test_per_device_budget_keeps_the_tighter_oom_guard_cap_per_card():+ torch_mod = _fake_torch([32 * GIB, 32 * GIB], current = {0: 0.5})+ assert _apply_training_vram_budget(torch_mod, None, [24, 24], None) == pytest.approx(+ {0: 0.5, 1: 0.75}+ )+++def test_single_budget_still_caps_every_card_alike():+ torch_mod = _fake_torch([32 * GIB, 16 * GIB])+ assert _apply_training_vram_budget(torch_mod, 8, None, None) == pytest.approx({0: 0.25, 1: 0.5})+++def test_per_device_budget_follows_the_narrowed_gpu_ids():+ torch_mod = _fake_torch([32 * GIB, 32 * GIB])+ # Physical GPUs 3 and 1 are visible as ordinals 0 and 1.+ assert _apply_training_vram_budget(+ torch_mod, None, [None, 16, None, 8], [3, 1]+ ) == pytest.approx({0: 0.25, 1: 0.5})+++def test_worker_routes_both_budgets_through_the_helper():+ import inspect+ from core.training import worker++ src = inspect.getsource(worker.run_training_process)+ assert 'config.get("offload_vram_gb_per_device")' in src+ assert "_apply_training_vram_budget(" in src++def _trainer(offload_layers = 0,prefetch_depth = 2,@@ -143,6 +248,96 @@ def test_snapshot_keys_layers_as_strings(monkeypatch):assert snap["state"] == {"14": "host", "15": "gpu"} and snap["prefetch_depth"] == 2+def _block(device):+ import torch+ return SimpleNamespace(home = torch.device(device))+++def _layer(device):+ import torch+ return SimpleNamespace(parameters = lambda: iter([SimpleNamespace(device = torch.device(device))]))+++def _zoo_block_swap(monkeypatch):+ # The Studio CPU job runs without unsloth_zoo installed.+ try:+ import unsloth_zoo.block_swap as module+ except ImportError:+ package = ModuleType("unsloth_zoo")+ module = ModuleType("unsloth_zoo.block_swap")+ package.block_swap = module+ monkeypatch.setitem(sys.modules, "unsloth_zoo", package)+ monkeypatch.setitem(sys.modules, "unsloth_zoo.block_swap", module)+ return module+++def test_snapshot_reports_every_card_and_each_layers_card(monkeypatch):+ zoo_block_swap = _zoo_block_swap(monkeypatch)+ from core.training import trainer++ cuda = trainer.torch.cuda+ allocated, peak = {0: 5 * GIB, 1: 3 * GIB}, {0: 6 * GIB, 1: 4 * GIB}+ totals, fractions = {0: 32 * GIB, 1: 16 * GIB}, {0: 1.0, 1: 0.5}+ monkeypatch.setattr(cuda, "is_available", lambda: True)+ monkeypatch.setattr(cuda, "device_count", lambda: 2)+ monkeypatch.setattr(cuda, "memory_allocated", lambda d = 0: allocated[d])+ monkeypatch.setattr(cuda, "max_memory_allocated", lambda d = 0: peak[d])+ monkeypatch.setattr(+ cuda,+ "get_device_properties",+ lambda d = 0: SimpleNamespace(name = f"card{d}", total_memory = totals[d]),+ )+ monkeypatch.setattr(+ cuda, "get_per_process_memory_fraction", lambda d = 0: fractions[d], raising = False+ )+ layers = [_layer("cuda:0"), _layer("cuda:0"), _layer("cuda:1"), _layer("cuda:1")]+ monkeypatch.setattr(zoo_block_swap, "find_decoder_layers", lambda model: layers, raising = False)+ swapper = SimpleNamespace(+ device = 0,+ indices = [1, 3],+ blocks = [_block("cuda:0"), _block("cuda:1")],+ stats = lambda: {"state": {1: "host", 3: "gpu"}, "swapped": [1, 3], "total_layers": 4},+ )+ t = _trainer(model = SimpleNamespace(_unsloth_block_swap = swapper))+ t._gpu_ids = [2, 0]+ snap = t._offload_snapshot()+ # The single-card keys stay for older panels.+ assert snap["vram_total_bytes"] == 32 * GIB and snap["vram_allocated_bytes"] == 5 * GIB+ assert snap["vram_devices"] == [+ {+ "index": 0,+ "gpu_id": 2,+ "name": "card0",+ "allocated_bytes": 5 * GIB,+ "peak_bytes": 6 * GIB,+ "total_bytes": 32 * GIB,+ "fraction": 1.0,+ },+ {+ "index": 1,+ "gpu_id": 0,+ "name": "card1",+ "allocated_bytes": 3 * GIB,+ "peak_bytes": 4 * GIB,+ "total_bytes": 16 * GIB,+ "fraction": 0.5,+ },+ ]+ assert snap["layer_device"] == {"0": 0, "1": 0, "2": 1, "3": 1}+++def test_layer_device_map_survives_a_zoo_without_find_decoder_layers(monkeypatch):+ zoo_block_swap = _zoo_block_swap(monkeypatch)++ def boom(model):+ raise RuntimeError("no layers")++ monkeypatch.setattr(zoo_block_swap, "find_decoder_layers", boom, raising = False)+ swapper = SimpleNamespace(indices = [5], blocks = [_block("cuda:1")])+ # Only the offloaded layer's home is known, which is enough to place it.+ assert _trainer(model = SimpleNamespace())._offload_layer_device_map(swapper) == {"5": 1}++def test_offload_route_reports_inactive_until_a_step_carries_stats(monkeypatch):import asynciofrom routes import training as route@@ -207,6 +402,11 @@ def test_every_worker_failure_path_carries_the_budget_hint():assert src.count("_with_vram_budget_hint(") == 4+def test_per_gpu_budgets_get_the_hint_too():+ hinted = _with_vram_budget_hint({"offload_vram_gb_per_device": [None, 6, 8]}, _INFEASIBLE)+ assert "per-GPU VRAM budgets (6, 8 GiB)" in hinted++@pytest.mark.parametrize("checkpointing", ["none", "False", "off", "no", "0"])@pytest.mark.parametrize("offload", [14, "auto"])def test_offload_without_checkpointing_is_refused_up_front(checkpointing, offload):@@ -255,12 +455,10 @@ def test_multi_gpu_vision_and_audio_runs_skip_the_budget():):assert needle in gateskip = src.index("if _budget_unsupported:")- assert 'config["offload_vram_gb"] = None' in src[skip : src.index("elif _wants_budget:")]- assert (- skip- < src.index("elif _wants_budget:")- < src.index("set_per_process_memory_fraction(_b_fraction")- )+ cleared = src[skip : src.index("elif _wants_budget:")]+ assert 'config["offload_vram_gb"] = None' in cleared+ assert 'config["offload_vram_gb_per_device"] = None' in cleared+ assert skip < src.index("elif _wants_budget:") < src.index("_apply_training_vram_budget(", skip)def test_an_inherited_mask_counts_its_visible_gpus(monkeypatch):diff --git a/studio/frontend/src/config/training.ts b/studio/frontend/src/config/training.tsindex 5900c5b4a20..a01d39e345f 100644--- a/studio/frontend/src/config/training.ts+++ b/studio/frontend/src/config/training.ts@@ -173,6 +173,7 @@ export const DEFAULT_HYPERPARAMS = {gradientCheckpointing: "unsloth" as const,offloadLayers: 0 as number | "auto",offloadVramGb: null as number | null,+ offloadVramGbPerDevice: {} as Record<string, number | null>,prefetchDepth: 2 as number | "auto",randomSeed: 3407,enableWandb: false,diff --git a/studio/frontend/src/features/studio/sections/offload-panel-layout.ts b/studio/frontend/src/features/studio/sections/offload-panel-layout.tsindex 00ee155a06b..ee7554eb74a 100644--- a/studio/frontend/src/features/studio/sections/offload-panel-layout.ts+++ b/studio/frontend/src/features/studio/sections/offload-panel-layout.ts@@ -18,6 +18,50 @@ export function layerPlacement(});}+/** One card in `GET /api/train/offload`'s `vram_devices`. */+export interface OffloadCard {+ index: number;+ gpu_id?: number;+ name?: string;+ allocated_bytes?: number;+ peak_bytes?: number;+ total_bytes?: number;+ fraction?: number;+}++/** What a VRAM bar shows: peak use, the budget line (null when uncapped) and the card's size. */+export function vramUsage(+ total: number | undefined,+ peak: number | undefined,+ allocated: number | undefined,+ fraction: number | undefined,+): { used: number; budget: number | null; total: number } {+ const size = total ?? 0;+ return {+ used: peak ?? allocated ?? 0,+ budget: fraction && fraction < 1 ? fraction * size : null,+ total: size,+ };+}++/** Decoder layers split by the card they run on, in card order; layers on no known card come last. */+export function groupLayersByCard<T extends { index: number }>(+ total: number,+ layerDevice: Record<string, number> | undefined,+ cards: readonly T[],+): { card: T | null; layers: number[] }[] {+ const groups = cards.map((card) => ({ card: card as T | null, layers: [] as number[] }));+ const byIndex = new Map(cards.map((card, k) => [card.index, k]));+ const unplaced: number[] = [];+ for (let layer = 0; layer < total; layer++) {+ const k = byIndex.get(layerDevice?.[String(layer)] ?? -1);+ if (k === undefined) unplaced.push(layer);+ else groups[k].layers.push(layer);+ }+ if (unplaced.length) groups.push({ card: null, layers: unplaced });+ return groups;+}+/** The layer count a Count box edit sets, or null to keep the current one (empty, zero, not a number). */export function offloadCountFromInput(text: string): number | null {const count = Math.floor(Number(text));diff --git a/studio/frontend/src/features/studio/sections/offload-panel.tsx b/studio/frontend/src/features/studio/sections/offload-panel.tsxindex 5c9dd2fd51a..5430c34b220 100644--- a/studio/frontend/src/features/studio/sections/offload-panel.tsx+++ b/studio/frontend/src/features/studio/sections/offload-panel.tsx@@ -9,7 +9,12 @@ import { RamMemoryIcon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import type { ReactElement } from "react";import { useEffect, useState } from "react";-import { layerPlacement } from "./offload-panel-layout";+import {+ type OffloadCard,+ groupLayersByCard,+ layerPlacement,+ vramUsage,+} from "./offload-panel-layout";/** `GET /api/train/offload`: unsloth_zoo BlockSwap.stats() from the last logged step. */export interface OffloadState {@@ -33,6 +38,9 @@ export interface OffloadState {vram_peak_bytes?: number;vram_total_bytes?: number;vram_fraction?: number;+ /** Every visible card, and the torch ordinal each decoder layer runs on. */+ vram_devices?: OffloadCard[];+ layer_device?: Record<string, number>;}const GIB = 1024 ** 3;@@ -99,6 +107,58 @@ function Stat({ label, value }: { label: string; value: string }): ReactElement);}+function VramBar({+ label,+ used,+ budget,+ total,+}: { label: string } & ReturnType<typeof vramUsage>): ReactElement {+ return (+ <div className="flex flex-col gap-1">+ <div className="flex justify-between text-ui-11 text-muted-foreground">+ <span>{label}</span>+ <span className="font-mono">+ {(used / GIB).toFixed(1)} / {((budget ?? total) / GIB).toFixed(1)} GiB+ </span>+ </div>+ <div className="relative h-2 overflow-hidden rounded-full bg-muted">+ <div+ className="h-full rounded-full bg-control-accent"+ style={{ width: `${Math.min(100, (100 * used) / total)}%` }}+ />+ {budget != null && (+ <div+ className="absolute inset-y-0 w-0.5 bg-[color-mix(in_oklab,var(--foreground)_calc(70%*var(--contrast-wash-gain,1)),transparent)]"+ style={{ left: `${(100 * budget) / total}%` }}+ />+ )}+ </div>+ </div>+ );+}++function LayerGrid({+ cells,+ layers,+ label,+}: {+ cells: ReturnType<typeof layerPlacement>;+ layers: number[];+ label: string;+}): ReactElement {+ return (+ <div className="grid w-fit grid-cols-8 gap-1" aria-label={label}>+ {layers.map((layer) => (+ <div+ key={layer}+ title={`${layer}`}+ className={cn("size-4 rounded-[3px] transition-colors", CELL[cells[layer]])}+ />+ ))}+ </div>+ );+}+export function OffloadPanel({ isTrainingRunning }: { isTrainingRunning: boolean }): ReactElement | null {const t = useT();const s = useOffloadState(isTrainingRunning);@@ -114,8 +174,8 @@ export function OffloadPanel({ isTrainingRunning }: { isTrainingRunning: booleanconst busy = (s.compute_ms ?? 0) + (s.stall_ms ?? 0);const waiting = busy > 0 ? (100 * (s.stall_ms ?? 0)) / busy : null;const vramTotal = s.vram_total_bytes ?? 0;- const used = s.vram_peak_bytes ?? s.vram_allocated_bytes ?? 0;- const budget = s.vram_fraction && s.vram_fraction < 1 ? s.vram_fraction * vramTotal : null;+ const cards = s.vram_devices ?? [];+ const multi = cards.length > 1;const ms = (v: number | null) => (v == null ? "--" : `${v.toFixed(1)} ms`);return (@@ -128,16 +188,45 @@ export function OffloadPanel({ isTrainingRunning }: { isTrainingRunning: booleanclassName="shadow-border border border-border/60 bg-card/90 ring-0 backdrop-blur-sm"><div className="flex flex-wrap items-start gap-6">- <div className="grid grid-cols-8 gap-1" aria-label={t("studio.params.offloadPanelTitle")}>- {cells.map((cell, layer) => (- <div- // biome-ignore lint/suspicious/noArrayIndexKey: one cell per decoder layer, fixed order- key={layer}- title={`${layer}`}- className={cn("size-4 rounded-[3px] transition-colors", CELL[cell])}- />- ))}- </div>+ {multi ? (+ <div className="flex flex-col gap-4">+ {groupLayersByCard(total, s.layer_device, cards).map(({ card, layers }) => {+ const name = card+ ? t("studio.params.offloadPanelCard", { index: card.gpu_id ?? card.index })+ : t("studio.params.offloadPanelCardUnknown");+ return (+ <div key={card?.index ?? "unplaced"} className="flex w-44 flex-col gap-2">+ <div className="flex items-baseline gap-1.5 text-ui-11">+ <span className="font-medium">{name}</span>+ {card?.name && (+ <span className="truncate text-muted-foreground" title={card.name}>+ {card.name}+ </span>+ )}+ </div>+ <LayerGrid cells={cells} layers={layers} label={name} />+ {card && (card.total_bytes ?? 0) > 0 && (+ <VramBar+ label={t("studio.params.offloadPanelVram")}+ {...vramUsage(card.total_bytes, card.peak_bytes, card.allocated_bytes, card.fraction)}+ />+ )}+ </div>+ );+ })}+ </div>+ ) : (+ <div className="grid grid-cols-8 gap-1" aria-label={t("studio.params.offloadPanelTitle")}>+ {cells.map((cell, layer) => (+ <div+ // biome-ignore lint/suspicious/noArrayIndexKey: one cell per decoder layer, fixed order+ key={layer}+ title={`${layer}`}+ className={cn("size-4 rounded-[3px] transition-colors", CELL[cell])}+ />+ ))}+ </div>+ )}<div className="flex min-w-48 flex-1 flex-col gap-3"><div className="flex flex-wrap gap-3 text-ui-11 text-muted-foreground"><span className="flex items-center gap-1.5">@@ -153,27 +242,11 @@ export function OffloadPanel({ isTrainingRunning }: { isTrainingRunning: boolean{t("studio.params.offloadPanelHost")}</span></div>- {vramTotal > 0 && (- <div className="flex flex-col gap-1">- <div className="flex justify-between text-ui-11 text-muted-foreground">- <span>{t("studio.params.offloadPanelVram")}</span>- <span className="font-mono">- {(used / GIB).toFixed(1)} / {((budget ?? vramTotal) / GIB).toFixed(1)} GiB- </span>- </div>- <div className="relative h-2 overflow-hidden rounded-full bg-muted">- <div- className="h-full rounded-full bg-control-accent"- style={{ width: `${Math.min(100, (100 * used) / vramTotal)}%` }}- />- {budget != null && (- <div- className="absolute inset-y-0 w-0.5 bg-[color-mix(in_oklab,var(--foreground)_calc(70%*var(--contrast-wash-gain,1)),transparent)]"- style={{ left: `${(100 * budget) / vramTotal}%` }}- />- )}- </div>- </div>+ {!multi && vramTotal > 0 && (+ <VramBar+ label={t("studio.params.offloadPanelVram")}+ {...vramUsage(vramTotal, s.vram_peak_bytes, s.vram_allocated_bytes, s.vram_fraction)}+ />)}<div className="grid grid-cols-2 gap-2 sm:grid-cols-4"><Stat label={t("studio.params.offloadPanelCopy")} value={ms(perCopy)} />diff --git a/studio/frontend/src/features/studio/sections/training-offload-params.tsx b/studio/frontend/src/features/studio/sections/training-offload-params.tsxindex bd19db8d1bf..0f92b3750c1 100644--- a/studio/frontend/src/features/studio/sections/training-offload-params.tsx+++ b/studio/frontend/src/features/studio/sections/training-offload-params.tsx@@ -11,6 +11,7 @@ import {} from "@/components/ui/select";import { useTrainingConfigStore } from "@/features/training";import type { OffloadLayers, PrefetchDepth } from "@/features/training/types/config";+import { useGpuDevices, useGpuInfo } from "@/hooks/use-gpu-info";import { useT } from "@/i18n";import { type ReactElement, useState } from "react";import { useShallow } from "zustand/react/shallow";@@ -32,12 +33,18 @@ export function OffloadLayersParams(): ReactElement {useShallow((state) => ({offloadLayers: state.offloadLayers,offloadVramGb: state.offloadVramGb,+ offloadVramGbPerDevice: state.offloadVramGbPerDevice,prefetchDepth: state.prefetchDepth,setOffloadLayers: state.setOffloadLayers,setOffloadVramGb: state.setOffloadVramGb,+ setOffloadVramGbForDevice: state.setOffloadVramGbForDevice,setPrefetchDepth: state.setPrefetchDepth,})),);+ const gpu = useGpuInfo();+ const devices = useGpuDevices(true);+ // Same rule as the start payload: several training GPUs get one budget each.+ const cards = gpu.available && devices.length > 1 ? devices : [];// The count box's text while it is being edited: clearing it to retype must not read as Off.const [countDraft, setCountDraft] = useState<string | null>(null);const mode = countDraft !== null ? "layers" : modeOf(store.offloadLayers);@@ -88,7 +95,39 @@ export function OffloadLayersParams(): ReactElement {)}</div></ParamsRow>- {mode === "auto" && (+ {mode === "auto" && cards.length > 0 && (+ <ParamsRow+ label={t("studio.params.offloadVramBudget")}+ tooltip={t("studio.params.offloadVramBudgetTooltip")}+ >+ {/* One box per training GPU, four to a line; empty uses the whole card. */}+ <div className="flex max-w-[calc(356px*var(--ui-space-scale,1))] flex-wrap justify-end gap-1.5">+ {cards.map((card) => (+ <Input+ key={card.index}+ type="number"+ inputMode="decimal"+ min={1}+ max={card.memoryTotalGb > 0 ? card.memoryTotalGb : undefined}+ step={0.5}+ title={card.name}+ aria-label={t("studio.params.offloadVramBudgetGpu", { index: card.index })}+ placeholder={t("studio.params.offloadPanelCard", { index: card.index })}+ value={store.offloadVramGbPerDevice[String(card.index)] ?? ""}+ onChange={(e) => {+ const gb = Number(e.target.value);+ store.setOffloadVramGbForDevice(+ card.index,+ e.target.value === "" || !(gb > 0) ? null : gb,+ );+ }}+ className="w-[calc(84px*var(--ui-space-scale,1))] pl-3 pr-7 font-mono placeholder:font-sans"+ />+ ))}+ </div>+ </ParamsRow>+ )}+ {mode === "auto" && cards.length === 0 && (<ParamsRowlabel={t("studio.params.offloadVramBudget")}tooltip={t("studio.params.offloadVramBudgetTooltip")}diff --git a/studio/frontend/src/features/training/api/mappers.ts b/studio/frontend/src/features/training/api/mappers.tsindex 71576c1cc4f..b3bdbbf9310 100644--- a/studio/frontend/src/features/training/api/mappers.ts+++ b/studio/frontend/src/features/training/api/mappers.ts@@ -82,7 +82,8 @@ export function offloadHardwareSupported(return devices.length === 0 || devices.some((device) => device.unified_memory !== true);}-/** The offload fields, sent off wherever the controls are hidden. */+/** The offload fields, sent off wherever the controls are hidden. `gpuIndices` are the GPUs+ * training can see; with more than one, the budget goes out per card. */export function offloadPayload(config: Pick<TrainingConfigState,@@ -93,10 +94,15 @@ export function offloadPayload(| "gradientCheckpointing"| "offloadLayers"| "offloadVramGb"+ | "offloadVramGbPerDevice"| "prefetchDepth">,+ gpuIndices: readonly number[] = [],system: Parameters<typeof offloadHardwareSupported>[0] = null,-): Pick<TrainingStartRequest, "offload_layers" | "offload_vram_gb" | "prefetch_depth"> {+): Pick<+ TrainingStartRequest,+ "offload_layers" | "offload_vram_gb" | "offload_vram_gb_per_device" | "prefetch_depth"+> {const layers = !(offloadSupported(config) && offloadHardwareSupported(system))? 0: config.offloadLayers === "auto"@@ -106,17 +112,52 @@ export function offloadPayload(config.prefetchDepth === "auto"? "auto": Math.min(8, Math.max(1, Math.floor(config.prefetchDepth || 2)));+ const multi = gpuIndices.length > 1;return {offload_layers: layers,// The budget only sizes "auto"; with a fixed count or off it would cap the run for nothing.+ // Several cards hide the single input, so a value left in it from a one-card setup is not sent.offload_vram_gb:- layers === "auto" && config.offloadVramGb && config.offloadVramGb > 0+ !multi && layers === "auto" && config.offloadVramGb && config.offloadVramGb > 0? config.offloadVramGb: null,+ offload_vram_gb_per_device:+ multi && layers === "auto"+ ? perDeviceBudgetPayload(config.offloadVramGbPerDevice, gpuIndices)+ : null,prefetch_depth: depth,};}+/** Entry i is GPU index i's budget, null where a card has none; null when no card has one. */+export function perDeviceBudgetPayload(+ perDevice: Record<string, number | null> | undefined,+ gpuIndices: readonly number[],+): (number | null)[] | null {+ const valid = gpuIndices.filter((i) => Number.isInteger(i) && i >= 0);+ if (!valid.length) return null;+ const out: (number | null)[] = Array.from({ length: Math.max(...valid) + 1 }, () => null);+ let any = false;+ for (const i of valid) {+ const gb = perDevice?.[String(i)];+ if (typeof gb === "number" && gb > 0 && gb <= 4096) {+ out[i] = gb;+ any = true;+ }+ }+ return any ? out : null;+}++/** The GPU indices training sees, from the torch inventory in `/api/system`. */+export function trainingGpuIndices(+ gpu: { available?: boolean; devices?: { index?: number | null }[] } | null | undefined,+): number[] {+ if (!gpu?.available) return [];+ return (gpu.devices ?? [])+ .map((d) => d.index)+ .filter((i): i is number => typeof i === "number");+}+export function buildTrainingStartPayload(config: TrainingConfigState,hfToken: string | null,@@ -239,7 +280,7 @@ export function buildTrainingStartPayload(lora_dropout: config.loraDropout,target_modules: adapterMethod ? config.targetModules : [],gradient_checkpointing: config.gradientCheckpointing,- ...offloadPayload(config, system),+ ...offloadPayload(config, trainingGpuIndices(system?.gpu), system),use_rslora: loraVariants && config.loraVariant === "rslora",use_loftq: loraVariants && config.loraVariant === "loftq",use_dora: loraVariants && config.loraVariant === "dora",diff --git a/studio/frontend/src/features/training/api/models-api.ts b/studio/frontend/src/features/training/api/models-api.tsindex 617f8d0b305..12a41059e99 100644--- a/studio/frontend/src/features/training/api/models-api.ts+++ b/studio/frontend/src/features/training/api/models-api.ts@@ -32,6 +32,7 @@ interface BackendTrainingDefaults {random_seed?: number;offload_layers?: number | "auto";offload_vram_gb?: number | null;+ offload_vram_gb_per_device?: Record<string, number | null> | (number | null)[] | null;prefetch_depth?: number | "auto";vision_image_size?: number | string | null;packing?: boolean;diff --git a/studio/frontend/src/features/training/lib/model-defaults-edit-policy.ts b/studio/frontend/src/features/training/lib/model-defaults-edit-policy.tsindex a89db45ab5e..4a590119c20 100644--- a/studio/frontend/src/features/training/lib/model-defaults-edit-policy.ts+++ b/studio/frontend/src/features/training/lib/model-defaults-edit-policy.ts@@ -27,6 +27,7 @@ export const MODEL_DEFAULT_STATE_KEYS = ["randomSeed","offloadLayers","offloadVramGb",+ "offloadVramGbPerDevice","prefetchDepth","visionImageSize","enableWandb",diff --git a/studio/frontend/src/features/training/lib/model-defaults.ts b/studio/frontend/src/features/training/lib/model-defaults.tsindex d9dd84aa71d..9d30aa09722 100644--- a/studio/frontend/src/features/training/lib/model-defaults.ts+++ b/studio/frontend/src/features/training/lib/model-defaults.ts@@ -160,6 +160,16 @@ export function mapBackendModelConfigToTrainingPatch(const budget = toNumber(training?.offload_vram_gb);patch.offloadVramGb = budget !== undefined && budget > 0 ? budget : null;}+ if (Object.hasOwn(training ?? {}, "offload_vram_gb_per_device")) {+ // Exported keyed by GPU index; the request's list form is indexed the same way.+ const raw = training?.offload_vram_gb_per_device;+ const perDevice: Record<string, number | null> = {};+ for (const [index, value] of Object.entries(raw ?? {})) {+ const gb = toNumber(value);+ if (/^\d+$/.test(index) && gb !== undefined && gb > 0 && gb <= 4096) perDevice[index] = gb;+ }+ patch.offloadVramGbPerDevice = perDevice;+ }if (training?.prefetch_depth === "auto") patch.prefetchDepth = "auto";else {const depth = toNumber(training?.prefetch_depth);diff --git a/studio/frontend/src/features/training/lib/yaml-config.ts b/studio/frontend/src/features/training/lib/yaml-config.tsindex b137e7f534e..834d8537d19 100644--- a/studio/frontend/src/features/training/lib/yaml-config.ts+++ b/studio/frontend/src/features/training/lib/yaml-config.ts@@ -96,6 +96,7 @@ export function serializeConfigToYaml(gradient_checkpointing: state.gradientCheckpointing,offload_layers: state.offloadLayers,offload_vram_gb: state.offloadVramGb,+ offload_vram_gb_per_device: state.offloadVramGbPerDevice,prefetch_depth: state.prefetchDepth,optim: state.optimizerType,lr_scheduler_type: state.lrSchedulerType,diff --git a/studio/frontend/src/features/training/stores/training-config-store.ts b/studio/frontend/src/features/training/stores/training-config-store.tsindex 0c4a75b233b..c67713c3701 100644--- a/studio/frontend/src/features/training/stores/training-config-store.ts+++ b/studio/frontend/src/features/training/stores/training-config-store.ts@@ -1600,6 +1600,13 @@ export const useTrainingConfigStore = create<TrainingConfigStore>()(setUserEdit({ gradientCheckpointing }),setOffloadLayers: (offloadLayers) => setUserEdit({ offloadLayers }),setOffloadVramGb: (offloadVramGb) => setUserEdit({ offloadVramGb }),+ setOffloadVramGbForDevice: (gpuIndex, value) =>+ setUserEdit((state) => ({+ offloadVramGbPerDevice: {+ ...state.offloadVramGbPerDevice,+ [String(gpuIndex)]: value,+ },+ })),setPrefetchDepth: (prefetchDepth) => setUserEdit({ prefetchDepth }),setRandomSeed: (randomSeed) => setUserEdit({ randomSeed }),setEnableWandb: (enableWandb) => setUserEdit({ enableWandb }),diff --git a/studio/frontend/src/features/training/types/api.ts b/studio/frontend/src/features/training/types/api.tsindex 55c279be86c..3b1d2717c58 100644--- a/studio/frontend/src/features/training/types/api.ts+++ b/studio/frontend/src/features/training/types/api.ts@@ -63,6 +63,7 @@ export interface TrainingStartRequest {gradient_checkpointing: string;offload_layers: number | "auto";offload_vram_gb: number | null;+ offload_vram_gb_per_device: (number | null)[] | null;prefetch_depth: number | "auto";use_rslora: boolean;use_loftq: boolean;diff --git a/studio/frontend/src/features/training/types/config.ts b/studio/frontend/src/features/training/types/config.tsindex 2231a4fa3a1..13fb0b28a03 100644--- a/studio/frontend/src/features/training/types/config.ts+++ b/studio/frontend/src/features/training/types/config.ts@@ -128,6 +128,8 @@ export interface TrainingConfigState {gradientCheckpointing: GradientCheckpointing;offloadLayers: OffloadLayers;offloadVramGb: number | null;+ /** Per-GPU budget in GiB keyed by the GPU index /api/system reports; used when several GPUs are visible. */+ offloadVramGbPerDevice: Record<string, number | null>;prefetchDepth: PrefetchDepth;randomSeed: number;enableWandb: boolean;@@ -267,6 +269,7 @@ export interface TrainingConfigActions {setGradientCheckpointing: (value: GradientCheckpointing) => void;setOffloadLayers: (value: OffloadLayers) => void;setOffloadVramGb: (value: number | null) => void;+ setOffloadVramGbForDevice: (gpuIndex: number, value: number | null) => void;setPrefetchDepth: (value: PrefetchDepth) => void;setRandomSeed: (value: number) => void;setEnableWandb: (value: boolean) => void;diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.tsindex 3f0665ff5b2..b37794029a5 100644--- a/studio/frontend/src/i18n/locales/ar.ts+++ b/studio/frontend/src/i18n/locales/ar.ts@@ -3402,6 +3402,7 @@ export const ar = {offloadVramBudget: "حد ذاكرة الفيديو (GiB)",offloadVramBudgetTooltip: "أقصى ذاكرة فيديو يستخدمها هذا التدريب. الوضع التلقائي يفرّغ طبقات كافية للبقاء تحته، ويمكن لتدريبين مشاركة بطاقة واحدة بأخذ كل منهما جزءًا. اتركه فارغًا لاستخدام البطاقة كاملة.",offloadWholeCard: "البطاقة كاملة",+ offloadVramBudgetGpu: "حد ذاكرة الفيديو لـ GPU {index} (GiB)",prefetchDepth: "عمق الجلب المسبق",prefetchDepthTooltip: "عدد الطبقات المفرّغة التي تُنسخ قبل الطبقة الجارية. الوضع التلقائي يبدأ من 1 ولا يحتفظ بعمق أكبر إلا إذا قلّل الانتظار فعلًا.",offloadPanelTitle: "الطبقات المفرّغة",@@ -3416,6 +3417,8 @@ export const ar = {offloadPanelDepth: "عمق الجلب المسبق",offloadPanelPinned: "مثبّتة",offloadPanelSweepNote: "تُظهر النافذة المتحركة ترتيب جلب الطبقات بعد إبطائها لتكون مرئية؛ أما الأرقام فمقاسة في آخر خطوة.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "بطاقة غير معروفة",gradCheckpoint: "نقطة تحقق التدرّج",gradCheckpointTooltip:"مقايضة الحوسبة بالذاكرة عبر إعادة حساب التنشيطات.",diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.tsindex d7952038ac6..fbc37c230d4 100644--- a/studio/frontend/src/i18n/locales/de.ts+++ b/studio/frontend/src/i18n/locales/de.ts@@ -3460,6 +3460,7 @@ export const de = {offloadVramBudget: "VRAM-Budget (GiB)",offloadVramBudgetTooltip: "Der meiste VRAM, den dieser Lauf nutzen darf. Auto lagert genug Schichten aus, um darunter zu bleiben, und zwei Läufe können sich eine Karte teilen. Leer nutzt die ganze Karte.",offloadWholeCard: "ganze Karte",+ offloadVramBudgetGpu: "VRAM-Budget GPU {index} (GiB)",prefetchDepth: "Prefetch-Tiefe",prefetchDepthTooltip: "Wie viele ausgelagerte Schichten vor der laufenden kopiert werden. Auto beginnt bei 1 und behält eine tiefere Reserve nur, solange sie das Warten auf Kopien messbar verkürzt.",offloadPanelTitle: "Ausgelagerte Schichten",@@ -3474,6 +3475,8 @@ export const de = {offloadPanelDepth: "Prefetch-Tiefe",offloadPanelPinned: "gepinnt",offloadPanelSweepNote: "Das wandernde Fenster zeigt, in welcher Reihenfolge Schichten geholt werden, verlangsamt, damit man es sieht; die Zahlen sind am letzten Schritt gemessen.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Unbekannte Karte",gradCheckpoint: "Grad-Checkpoint",gradCheckpointTooltip:"Rechenaufwand gegen Speicher tauschen, indem Aktivierungen neu berechnet werden.",diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex b9fff8e8ce9..621150dad21 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -3464,6 +3464,7 @@ export const en = {offloadVramBudget: "VRAM budget (GiB)",offloadVramBudgetTooltip: "The most VRAM this run may use. Auto offloads enough layers to fit under it, and two runs can share one card by each taking part of it. Empty uses the whole card.",offloadWholeCard: "whole card",+ offloadVramBudgetGpu: "GPU {index} VRAM budget (GiB)",prefetchDepth: "Prefetch depth",prefetchDepthTooltip: "How many offloaded layers are copied ahead of the one running. Auto starts at 1 and keeps a deeper pool only while it measurably cuts waiting on copies.",offloadPanelTitle: "Offloaded layers",@@ -3478,6 +3479,8 @@ export const en = {offloadPanelDepth: "prefetch depth",offloadPanelPinned: "pinned",offloadPanelSweepNote: "The moving window shows the order layers are fetched in, slowed down to be visible; the numbers are measured on the last step.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Unknown card",gradCheckpoint: "Grad Checkpoint",gradCheckpointTooltip:"Trade compute for memory by recomputing activations.",diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.tsindex ab9d40e0658..f6c133a7519 100644--- a/studio/frontend/src/i18n/locales/es.ts+++ b/studio/frontend/src/i18n/locales/es.ts@@ -3455,6 +3455,7 @@ export const es = {offloadVramBudget: "Presupuesto de VRAM (GiB)",offloadVramBudgetTooltip: "La VRAM máxima que puede usar este entrenamiento. Auto descarga las capas necesarias para caber, y dos entrenamientos pueden compartir una tarjeta. Vacío usa toda la tarjeta.",offloadWholeCard: "toda la tarjeta",+ offloadVramBudgetGpu: "Presupuesto de VRAM GPU {index} (GiB)",prefetchDepth: "Profundidad de precarga",prefetchDepthTooltip: "Cuántas capas descargadas se copian antes de la que se ejecuta. Auto empieza en 1 y solo mantiene más si reduce de forma medible la espera de copias.",offloadPanelTitle: "Capas descargadas",@@ -3469,6 +3470,8 @@ export const es = {offloadPanelDepth: "profundidad de precarga",offloadPanelPinned: "fijada",offloadPanelSweepNote: "La ventana móvil muestra el orden en que se traen las capas, ralentizado para que se vea; los números se miden en el último paso.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Tarjeta desconocida",gradCheckpoint: "Checkpoint de gradiente",gradCheckpointTooltip:"Intercambia cómputo por memoria recalculando las activaciones.",diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.tsindex be638a542ec..9a124a7b935 100644--- a/studio/frontend/src/i18n/locales/fr.ts+++ b/studio/frontend/src/i18n/locales/fr.ts@@ -3470,6 +3470,7 @@ export const fr = {offloadVramBudget: "Budget VRAM (Gio)",offloadVramBudgetTooltip: "La VRAM maximale que cet entraînement peut utiliser. Auto décharge assez de couches pour rester en dessous, et deux entraînements peuvent partager une carte. Vide utilise toute la carte.",offloadWholeCard: "toute la carte",+ offloadVramBudgetGpu: "Budget VRAM GPU {index} (Gio)",prefetchDepth: "Profondeur de préchargement",prefetchDepthTooltip: "Nombre de couches déchargées copiées avant celle qui s'exécute. Auto commence à 1 et ne garde une réserve plus profonde que si elle réduit l'attente des copies de façon mesurable.",offloadPanelTitle: "Couches déchargées",@@ -3484,6 +3485,8 @@ export const fr = {offloadPanelDepth: "profondeur de préchargement",offloadPanelPinned: "épinglée",offloadPanelSweepNote: "La fenêtre mobile montre l'ordre de chargement des couches, ralenti pour être visible ; les chiffres sont mesurés sur la dernière étape.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Carte inconnue",gradCheckpoint: "Checkpoint de gradient",gradCheckpointTooltip:"Échanger du calcul contre de la mémoire en recalculant les activations.",diff --git a/studio/frontend/src/i18n/locales/he.ts b/studio/frontend/src/i18n/locales/he.tsindex 44c7dfd31f7..9ded8e8e695 100644--- a/studio/frontend/src/i18n/locales/he.ts+++ b/studio/frontend/src/i18n/locales/he.ts@@ -3499,10 +3499,13 @@ export const he = {offloadCount: "מספר",offloadVramBudget: "תקציב VRAM (GiB)",offloadVramBudgetTooltip: "כמות ה-VRAM המרבית שהריצה הזו רשאית להשתמש בה. אוטומטי מעביר מספיק שכבות כדי להיכנס מתחתיה, ושתי ריצות יכולות לחלוק כרטיס אחד כשכל אחת לוקחת חלק ממנו. שדה ריק משתמש בכרטיס כולו.",+ offloadVramBudgetGpu: "תקציב VRAM של GPU {index} (GiB)",offloadWholeCard: "הכרטיס כולו",prefetchDepth: "עומק טעינה מוקדמת",prefetchDepthTooltip: "כמה שכבות מועברות מועתקות מראש לפני השכבה שרצה. אוטומטי מתחיל ב-1 ושומר מאגר עמוק יותר רק כל עוד הוא מקצר בפועל את ההמתנה להעתקות.",offloadPanelTitle: "שכבות שהועברו",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "כרטיס לא ידוע",offloadPanelGpu: "ב-GPU",offloadPanelHost: "בזיכרון המערכת",offloadPanelCopying: "מועתקת",diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.tsindex eb18b863cf5..e74fa26988e 100644--- a/studio/frontend/src/i18n/locales/hi.ts+++ b/studio/frontend/src/i18n/locales/hi.ts@@ -3409,6 +3409,7 @@ export const hi = {offloadVramBudget: "VRAM बजट (GiB)",offloadVramBudgetTooltip: "यह रन अधिकतम कितना VRAM इस्तेमाल कर सकता है। ऑटो इसके भीतर रहने लायक परतें ऑफ़लोड करता है, और दो रन एक कार्ड बाँट सकते हैं। खाली छोड़ने पर पूरा कार्ड।",offloadWholeCard: "पूरा कार्ड",+ offloadVramBudgetGpu: "GPU {index} VRAM बजट (GiB)",prefetchDepth: "प्रीफ़ेच गहराई",prefetchDepthTooltip: "चल रही परत से पहले कितनी ऑफ़लोड परतें कॉपी हों। ऑटो 1 से शुरू होता है और गहरा पूल तभी रखता है जब वह कॉपी का इंतज़ार सच में घटाए।",offloadPanelTitle: "ऑफ़लोड परतें",@@ -3423,6 +3424,8 @@ export const hi = {offloadPanelDepth: "प्रीफ़ेच गहराई",offloadPanelPinned: "पिन की गई",offloadPanelSweepNote: "चलती खिड़की दिखाती है कि परतें किस क्रम में लाई जाती हैं, दिखने लायक धीमा करके; संख्याएँ पिछले स्टेप पर मापी गई हैं।",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "अज्ञात कार्ड",gradCheckpoint: "ग्रेडिएंट चेकपॉइंट",gradCheckpointTooltip:"एक्टिवेशन की दोबारा गणना करके अतिरिक्त कंप्यूट के बदले मेमोरी बचाएँ।",diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.tsindex c1294d67005..5b703808814 100644--- a/studio/frontend/src/i18n/locales/it.ts+++ b/studio/frontend/src/i18n/locales/it.ts@@ -3463,6 +3463,7 @@ export const it = {offloadVramBudget: "Budget VRAM (GiB)",offloadVramBudgetTooltip: "La VRAM massima che questo addestramento può usare. Auto scarica abbastanza livelli per restare sotto, e due addestramenti possono condividere una scheda. Vuoto usa tutta la scheda.",offloadWholeCard: "tutta la scheda",+ offloadVramBudgetGpu: "Budget VRAM GPU {index} (GiB)",prefetchDepth: "Profondità di prefetch",prefetchDepthTooltip: "Quanti livelli scaricati vengono copiati prima di quello in esecuzione. Auto parte da 1 e tiene una riserva più profonda solo se riduce in modo misurabile l'attesa delle copie.",offloadPanelTitle: "Livelli scaricati",@@ -3477,6 +3478,8 @@ export const it = {offloadPanelDepth: "profondità di prefetch",offloadPanelPinned: "bloccata",offloadPanelSweepNote: "La finestra mobile mostra l'ordine in cui i livelli vengono caricati, rallentato per essere visibile; i numeri sono misurati sull'ultimo passo.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Scheda sconosciuta",gradCheckpoint: "Checkpoint del gradiente",gradCheckpointTooltip:"Riduce l'uso della memoria ricalcolando le attivazioni, al costo di più calcoli.",diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.tsindex 204bdb50161..92753e8de73 100644--- a/studio/frontend/src/i18n/locales/ja.ts+++ b/studio/frontend/src/i18n/locales/ja.ts@@ -3354,6 +3354,7 @@ export const ja = {offloadVramBudget: "VRAM予算 (GiB)",offloadVramBudgetTooltip: "この学習が使えるVRAMの上限です。自動はその範囲に収まるようにオフロードし、2つの学習で1枚のカードを分け合えます。空欄ならカード全体を使います。",offloadWholeCard: "カード全体",+ offloadVramBudgetGpu: "GPU {index} のVRAM予算 (GiB)",prefetchDepth: "プリフェッチ深度",prefetchDepthTooltip: "実行中の層より先にコピーするオフロード層の数です。自動は1から始め、コピー待ちが実際に減る場合だけ深くします。",offloadPanelTitle: "オフロード層",@@ -3368,6 +3369,8 @@ export const ja = {offloadPanelDepth: "プリフェッチ深度",offloadPanelPinned: "ピン留め",offloadPanelSweepNote: "移動するウィンドウは層を取り込む順序を、見えるように遅くして示します。数値は直前のステップの実測値です。",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "不明なカード",gradCheckpoint: "勾配チェックポイント",gradCheckpointTooltip: "アクティベーションを再計算することで、計算量と引き換えにメモリを節約します。",none: "なし",diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.tsindex 425dd25ca02..fdbac527396 100644--- a/studio/frontend/src/i18n/locales/ko.ts+++ b/studio/frontend/src/i18n/locales/ko.ts@@ -3393,6 +3393,7 @@ export const ko = {offloadVramBudget: "VRAM 예산 (GiB)",offloadVramBudgetTooltip: "이 학습이 쓸 수 있는 최대 VRAM입니다. 자동은 그 안에 맞도록 레이어를 오프로드하고, 두 학습이 카드 하나를 나눠 쓸 수 있습니다. 비우면 카드 전체를 씁니다.",offloadWholeCard: "카드 전체",+ offloadVramBudgetGpu: "GPU {index} VRAM 예산 (GiB)",prefetchDepth: "프리페치 깊이",prefetchDepthTooltip: "실행 중인 레이어보다 먼저 복사할 오프로드 레이어 수입니다. 자동은 1에서 시작해 복사 대기가 실제로 줄 때만 깊게 유지합니다.",offloadPanelTitle: "오프로드된 레이어",@@ -3407,6 +3408,8 @@ export const ko = {offloadPanelDepth: "프리페치 깊이",offloadPanelPinned: "고정됨",offloadPanelSweepNote: "움직이는 창은 레이어를 가져오는 순서를 보이도록 느리게 보여 줍니다. 숫자는 마지막 스텝에서 측정한 값입니다.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "알 수 없는 카드",gradCheckpoint: "그래디언트 체크포인팅",gradCheckpointTooltip:"활성화를 재계산해 연산량을 늘리는 대신 메모리 사용량을 줄입니다.",diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.tsindex 3e6bbd51b27..1e26786893d 100644--- a/studio/frontend/src/i18n/locales/pt-br.ts+++ b/studio/frontend/src/i18n/locales/pt-br.ts@@ -3426,6 +3426,7 @@ export const ptBR = {offloadVramBudget: "Orçamento de VRAM (GiB)",offloadVramBudgetTooltip: "A VRAM máxima que este treino pode usar. Auto descarrega camadas suficientes para caber, e dois treinos podem dividir uma placa. Vazio usa a placa inteira.",offloadWholeCard: "placa inteira",+ offloadVramBudgetGpu: "Orçamento de VRAM GPU {index} (GiB)",prefetchDepth: "Profundidade de pré-busca",prefetchDepthTooltip: "Quantas camadas descarregadas são copiadas antes da que está rodando. Auto começa em 1 e só mantém mais se reduzir de forma mensurável a espera por cópias.",offloadPanelTitle: "Camadas descarregadas",@@ -3440,6 +3441,8 @@ export const ptBR = {offloadPanelDepth: "profundidade de pré-busca",offloadPanelPinned: "fixada",offloadPanelSweepNote: "A janela móvel mostra a ordem em que as camadas são buscadas, desacelerada para ficar visível; os números são medidos no último passo.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Placa desconhecida",gradCheckpoint: "Checkpoint de gradiente",gradCheckpointTooltip:"Reduz o uso de memória ao recalcular as ativações, em troca de maior custo computacional.",diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.tsindex 04f335c716d..3ddf1304ff4 100644--- a/studio/frontend/src/i18n/locales/ru.ts+++ b/studio/frontend/src/i18n/locales/ru.ts@@ -3425,6 +3425,7 @@ export const ru = {offloadVramBudget: "Бюджет видеопамяти (ГиБ)",offloadVramBudgetTooltip: "Максимум видеопамяти для этого обучения. Авто выгружает столько слоёв, чтобы уложиться, и два обучения могут делить одну карту. Пусто: вся карта.",offloadWholeCard: "вся карта",+ offloadVramBudgetGpu: "Бюджет видеопамяти GPU {index} (ГиБ)",prefetchDepth: "Глубина предзагрузки",prefetchDepthTooltip: "Сколько выгруженных слоёв копируется заранее. Авто начинает с 1 и держит больший запас, только если он заметно сокращает ожидание копий.",offloadPanelTitle: "Выгруженные слои",@@ -3439,6 +3440,8 @@ export const ru = {offloadPanelDepth: "глубина предзагрузки",offloadPanelPinned: "закреплено",offloadPanelSweepNote: "Движущееся окно показывает порядок загрузки слоёв, замедленно, чтобы его было видно; числа измерены на последнем шаге.",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Неизвестная карта",gradCheckpoint: "Чекпоинт градиента",gradCheckpointTooltip:"Обменять вычисления на память, пересчитывая активации.",diff --git a/studio/frontend/src/i18n/locales/sv.ts b/studio/frontend/src/i18n/locales/sv.tsindex 36bf414e455..e40fef2a450 100644--- a/studio/frontend/src/i18n/locales/sv.ts+++ b/studio/frontend/src/i18n/locales/sv.ts@@ -3620,10 +3620,13 @@ export const sv = {offloadCount: "Antal",offloadVramBudget: "VRAM-budget (GiB)",offloadVramBudgetTooltip: "Det mesta VRAM den här körningen får använda. Auto avlastar tillräckligt många lager för att hålla sig under det, och två körningar kan dela ett kort genom att ta varsin del. Tomt använder hela kortet.",+ offloadVramBudgetGpu: "VRAM-budget för GPU {index} (GiB)",offloadWholeCard: "hela kortet",prefetchDepth: "Förhämtningsdjup",prefetchDepthTooltip: "Hur många avlastade lager som kopieras i förväg före det som körs. Auto börjar på 1 och behåller en djupare pool bara så länge den mätbart minskar väntan på kopior.",offloadPanelTitle: "Avlastade lager",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "Okänt kort",offloadPanelGpu: "På GPU",offloadPanelHost: "I systemminnet",offloadPanelCopying: "Kopieras",diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.tsindex ccd30b60aaa..b772667e636 100644--- a/studio/frontend/src/i18n/locales/zh-CN.ts+++ b/studio/frontend/src/i18n/locales/zh-CN.ts@@ -3319,6 +3319,7 @@ export const zhCN = {offloadVramBudget: "显存预算 (GiB)",offloadVramBudgetTooltip: "本次训练最多可使用的显存。自动会卸载足够的层以保持在此之下,两次训练也可以分享同一张显卡。留空则使用整张显卡。",offloadWholeCard: "整张显卡",+ offloadVramBudgetGpu: "GPU {index} 显存预算 (GiB)",prefetchDepth: "预取深度",prefetchDepthTooltip: "在当前层之前提前复制的卸载层数量。自动从 1 开始,只有在确实减少复制等待时才加深。",offloadPanelTitle: "卸载的层",@@ -3333,6 +3334,8 @@ export const zhCN = {offloadPanelDepth: "预取深度",offloadPanelPinned: "已固定",offloadPanelSweepNote: "移动窗口放慢显示各层的取入顺序;数字是上一步的实测值。",+ offloadPanelCard: "GPU {index}",+ offloadPanelCardUnknown: "未知显卡",gradCheckpoint: "梯度检查点",gradCheckpointTooltip: "通过重算激活以时间换 VRAM。",none: "无",diff --git a/studio/frontend/tests/offload-panel-placement.test.ts b/studio/frontend/tests/offload-panel-placement.test.tsindex 5d8cd956d79..c43b46e43bc 100644--- a/studio/frontend/tests/offload-panel-placement.test.ts+++ b/studio/frontend/tests/offload-panel-placement.test.ts@@ -10,7 +10,9 @@ import test from "node:test";import { registerBundlerResolver } from "./helpers/kit.ts";registerBundlerResolver();-const { layerPlacement, offloadCountFromInput } = await import("../src/features/studio/sections/offload-panel-layout.ts");+const { groupLayersByCard, layerPlacement, offloadCountFromInput, vramUsage } = await import(+ "../src/features/studio/sections/offload-panel-layout.ts"+);test("the window follows the offloaded order, not the layer index", () => {// Spread placement: every other layer offloaded.@@ -29,6 +31,33 @@ test("nothing offloaded is all resident", () => {assert.deepEqual(layerPlacement(3, [], 2, 0), ["resident", "resident", "resident"]);});+const cards = [{ index: 0, gpu_id: 2 }, { index: 1, gpu_id: 0 }];++test("layers group under the card they run on, in card order", () => {+ const groups = groupLayersByCard(6, { "0": 0, "1": 0, "2": 0, "3": 1, "4": 1, "5": 1 }, cards);+ assert.deepEqual(groups, [+ { card: cards[0], layers: [0, 1, 2] },+ { card: cards[1], layers: [3, 4, 5] },+ ]);+});++test("a card holding no decoder layers still gets its group", () => {+ const groups = groupLayersByCard(2, { "0": 1, "1": 1 }, cards);+ assert.deepEqual(groups.map((g) => g.layers), [[], [0, 1]]);+});++test("layers on no known card come last instead of vanishing", () => {+ const groups = groupLayersByCard(4, { "0": 0, "2": 1, "3": 7 }, cards);+ assert.deepEqual(groups.at(-1), { card: null, layers: [1, 3] });+ assert.equal(groups.flatMap((g) => g.layers).length, 4);+});++test("the VRAM bar reads peak use and draws a budget line only under 1", () => {+ const GIB = 1024 ** 3;+ assert.deepEqual(vramUsage(32 * GIB, 6 * GIB, 5 * GIB, 0.5), { used: 6 * GIB, budget: 16 * GIB, total: 32 * GIB });+ assert.deepEqual(vramUsage(32 * GIB, undefined, 5 * GIB, 1), { used: 5 * GIB, budget: null, total: 32 * GIB });+ assert.deepEqual(vramUsage(undefined, undefined, undefined, undefined), { used: 0, budget: null, total: 0 });});+test("clearing the Count box keeps the last count instead of turning offload off", () => {for (const text of ["", "0", "-3", "abc"]) assert.equal(offloadCountFromInput(text), null);assert.equal(offloadCountFromInput("14"), 14);diff --git a/studio/frontend/tests/training-model-defaults-offload.test.ts b/studio/frontend/tests/training-model-defaults-offload.test.tsindex ebb016a02c1..5dba53d538a 100644--- a/studio/frontend/tests/training-model-defaults-offload.test.ts+++ b/studio/frontend/tests/training-model-defaults-offload.test.ts@@ -26,6 +26,15 @@ test("importing an exported config restores every offload field", () => {});assert.equal(off.offloadVramGb, null);assert.equal(off.prefetchDepth, 3);+ const cards = mapBackendModelConfigToTrainingPatch({+ training: { offload_vram_gb_per_device: { "0": 20, "1": null, "3": 12.5 } },+ });+ assert.deepEqual(cards.offloadVramGbPerDevice, { "0": 20, "3": 12.5 });+ assert.deepEqual(+ mapBackendModelConfigToTrainingPatch({ training: { offload_vram_gb_per_device: [null, 6] } })+ .offloadVramGbPerDevice,+ { "1": 6 },+ );// Configs exported before these fields existed keep the current values.assert.equal("offloadVramGb" in mapBackendModelConfigToTrainingPatch({ training: {} }), false);});diff --git a/studio/frontend/tests/training-start-payload-offload.test.ts b/studio/frontend/tests/training-start-payload-offload.test.tsindex 3199667f422..142df891609 100644--- a/studio/frontend/tests/training-start-payload-offload.test.ts+++ b/studio/frontend/tests/training-start-payload-offload.test.ts@@ -2,7 +2,8 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0// Offload layers in the start payload: off by default, a full finetune always sends it off,-// and the VRAM budget goes out only with "auto", the one mode that sizes to it.+// and the VRAM budget goes out only with "auto", the one mode that sizes to it, per card when+// training sees several GPUs.import assert from "node:assert/strict";import test from "node:test";@@ -10,7 +11,13 @@ import test from "node:test";import { registerBundlerResolver } from "./helpers/kit.ts";registerBundlerResolver();-const { offloadHardwareSupported, offloadPayload, offloadSupported } = await import("../src/features/training/api/mappers.ts");+const {+ offloadHardwareSupported,+ offloadPayload,+ offloadSupported,+ perDeviceBudgetPayload,+ trainingGpuIndices,+} = await import("../src/features/training/api/mappers.ts");const { initialTrainingConfigState } = await import("../src/features/training/stores/training-config-policy.ts");@@ -21,6 +28,7 @@ test("defaults send offload off at depth 2", () => {assert.deepEqual(offloadPayload(base), {offload_layers: 0,offload_vram_gb: null,+ offload_vram_gb_per_device: null,prefetch_depth: 2,});});@@ -28,7 +36,12 @@ test("defaults send offload off at depth 2", () => {test("auto carries the budget and an auto depth", () => {assert.deepEqual(offloadPayload({ ...base, offloadLayers: "auto", offloadVramGb: 11.5, prefetchDepth: "auto" }),- { offload_layers: "auto", offload_vram_gb: 11.5, prefetch_depth: "auto" },+ {+ offload_layers: "auto",+ offload_vram_gb: 11.5,+ offload_vram_gb_per_device: null,+ prefetch_depth: "auto",+ },);});@@ -36,6 +49,7 @@ test("a fixed count drops the budget and rounds the count", () => {assert.deepEqual(offloadPayload({ ...base, offloadLayers: 14.7, offloadVramGb: 8, prefetchDepth: 3 }), {offload_layers: 14,offload_vram_gb: null,+ offload_vram_gb_per_device: null,prefetch_depth: 3,});});@@ -51,6 +65,50 @@ test("depth is clamped to what the backend accepts", () => {assert.equal(offloadPayload({ ...base, offloadLayers: 4, prefetchDepth: 0 }).prefetch_depth, 2);});+test("one visible GPU keeps the single budget", () => {+ const config = { ...base, offloadLayers: "auto" as const, offloadVramGb: 10, offloadVramGbPerDevice: { "0": 6 } };+ const out = offloadPayload(config, [0]);+ assert.equal(out.offload_vram_gb, 10);+ assert.equal(out.offload_vram_gb_per_device, null);+});++test("several GPUs send one budget per card and drop the single one", () => {+ const config = {+ ...base,+ offloadLayers: "auto" as const,+ offloadVramGb: 10,+ offloadVramGbPerDevice: { "0": 20, "1": null, "2": 12.5 },+ };+ const out = offloadPayload(config, [0, 1, 2]);+ assert.equal(out.offload_vram_gb, null);+ assert.deepEqual(out.offload_vram_gb_per_device, [20, null, 12.5]);+});++test("several GPUs with no budget set send none", () => {+ const out = offloadPayload({ ...base, offloadLayers: "auto", offloadVramGb: 10 }, [0, 1]);+ assert.equal(out.offload_vram_gb, null);+ assert.equal(out.offload_vram_gb_per_device, null);+});++test("per-card budgets go out only with auto", () => {+ const config = { ...base, offloadLayers: 6, offloadVramGbPerDevice: { "0": 8, "1": 8 } };+ assert.equal(offloadPayload(config, [0, 1]).offload_vram_gb_per_device, null);+});++test("entries sit at each card's GPU index and skip cards that left", () => {+ // GPUs 1 and 3 visible; 0 and 2 are padding, and the remembered 5 is not sent.+ assert.deepEqual(perDeviceBudgetPayload({ "1": 16, "3": 8, "5": 4 }, [1, 3]), [null, 16, null, 8]);+ assert.deepEqual(perDeviceBudgetPayload({ "0": 0, "1": -2, "2": 5000 }, [0, 1, 2]), null);+ assert.equal(perDeviceBudgetPayload({ "0": 8 }, []), null);+});++test("training GPU indices come from the torch inventory only when it is available", () => {+ assert.deepEqual(trainingGpuIndices({ available: true, devices: [{ index: 0 }, { index: 1 }] }), [0, 1]);+ assert.deepEqual(trainingGpuIndices({ available: false, devices: [{ index: 0 }] }), []);+ assert.deepEqual(trainingGpuIndices({ available: true, devices: [{ index: null }, { index: 2 }] }), [2]);+ assert.deepEqual(trainingGpuIndices(null), []);+});+test("offload goes out off wherever the run cannot offload", () => {const on = { ...base, offloadLayers: "auto" as const, offloadVramGb: 8 };for (const blocked of [@@ -89,7 +147,7 @@ test("offload needs a CUDA or ROCm card that is not a unified-memory APU", () =>assert.equal(offloadHardwareSupported({ ...sys("cpu", []), status: "pending" }), true);// A hidden setting is sent off too, so a saved Count cannot fail the run.const saved = { ...base, offloadLayers: 14 };- assert.equal(offloadPayload(saved, sys("xpu", [false])).offload_layers, 0);- assert.equal(offloadPayload(saved, sys("rocm", [true])).offload_layers, 0);- assert.equal(offloadPayload(saved, sys("cuda", [false])).offload_layers, 14);+ assert.equal(offloadPayload(saved, [], sys("xpu", [false])).offload_layers, 0);+ assert.equal(offloadPayload(saved, [], sys("rocm", [true])).offload_layers, 0);+ assert.equal(offloadPayload(saved, [], sys("cuda", [false])).offload_layers, 14);});