[Offloader] Stream multimodal towers from host RAM with bulk-copy

Add --offload-towers: place multimodal tower weights in pinned host
memory and bulk-copy each unit to the GPU only during its forward,
keeping towers out of VRAM between encodes. Unlike UVA zero-copy,
whole-tensor H2D transfers avoid re-reading operand tiles over PCIe
inside the GEMM inner loop. Tower streaming is independent of layer
group scheduling, so group_size may be 0 for tower-only offload.

Co-authored-by: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-16 14:32:14 +07:00
co-authored by Hinata
parent 5d6754ff6b
commit 18c06ed406
5 changed files with 307 additions and 14 deletions
+27 -3
View File
@@ -73,6 +73,19 @@ class PrefetchOffloadConfig:
parameters of each offloaded layer are offloaded.
Uses segment matching: "w13_weight" matches "mlp.experts.w13_weight"
but not "mlp.experts.w13_weight_scale".
Applies to decoder layers only; `offload_towers` offloads the full
tower regardless of this set.
"""
offload_towers: bool = False
"""Offload multimodal tower weights (vision/audio encoders) to pinned
host memory, and bulk-copy them to the GPU during each encoder forward.
Towers hold no VRAM between image encodes. Unlike UVA zero-copy, weights
are streamed with whole-tensor H2D copies instead of being re-read tile
by tile inside the GEMM inner loops, so encode cost stays near the
resident-tower baseline.
Works together with, or instead of, layer prefetch:
`offload_group_size` may be 0 when only towers are offloaded.
"""
@@ -83,7 +96,8 @@ class OffloadConfig:
offload_backend: OffloadBackend = "auto"
"""The backend for weight offloading. Options:
- "auto": Selects based on which sub-config has non-default values
(prefetch if offload_group_size > 0, uva if cpu_offload_gb > 0).
(prefetch if offload_group_size > 0 or offload_towers, uva if
cpu_offload_gb > 0).
- "uva": UVA (Unified Virtual Addressing) zero-copy offloading.
- "prefetch": Async prefetch with group-based layer offloading.
"""
@@ -97,7 +111,15 @@ class OffloadConfig:
@model_validator(mode="after")
def validate_offload_config(self) -> "OffloadConfig":
"""Validate offload configuration constraints."""
if self.offload_backend == "prefetch" or self.prefetch.offload_group_size > 0:
layer_offload = self.prefetch.offload_group_size > 0
if self.offload_backend == "prefetch" and not (
layer_offload or self.prefetch.offload_towers
):
raise ValueError(
"offload_backend='prefetch' requires offload_group_size > 0"
" or offload_towers=True"
)
if layer_offload:
if self.prefetch.offload_num_in_group > self.prefetch.offload_group_size:
raise ValueError(
f"offload_num_in_group ({self.prefetch.offload_num_in_group})"
@@ -114,7 +136,9 @@ class OffloadConfig:
# Warn if both backends have non-default values
uva_active = self.uva.cpu_offload_gb > 0
prefetch_active = self.prefetch.offload_group_size > 0
prefetch_active = (
self.prefetch.offload_group_size > 0 or self.prefetch.offload_towers
)
if self.offload_backend == "uva" and prefetch_active:
warnings.warn(
"Prefetch offload fields are set but offload_backend='uva'. "