LoRA fusion is ~10x slower than it needs to be on DGX Spark (GB10); a registry state-dict aliasing bug in `_build_pinned_source`; and slow first GPU reads of `cudaHostRegistered` block buffers
Hello there,
We run ICLoraPipeline (HDR / ACEScct, --offload cpu) in production on NVIDIA
DGX Spark (GB10) nodes. While profiling we found two issues in ltx-core and one
platform effect that other GB10 users will probably hit. Everything below was measured on
the vendored 1.3.0 release, and every fix was checked for bit-identical output.
Both issues affect the LTX-2.5 and the LTX-2.3 stacks, since the streaming builder is shared. Issue 1 saves more on 2.3: a 49-frame 2560x1024 job goes from 381 s to 197 s.
Environment
- NVIDIA GB10 (DGX Spark): aarch64, 121 GiB unified CPU/GPU memory, compute capability 12.1
- Driver 580.173.02, kernel 6.17.0-1029-nvidia
- Container
nvcr.io/nvidia/cuda:13.0.1-runtime-ubuntu24.04, Python 3.12.3 - torch 2.13.0+cu132 (arch list sm_80 to sm_120), cuDNN 9.24.0, safetensors 0.8.0
- ltx-core / ltx-pipelines 1.3.0 at
a95ab856bf29407b6b066ede0abe1846050db56c - LTX-2.5 distilled transformer (split layout) and LTX-2.3 distilled 1.1 (monolith), each
with
ltx-2.3-22b-ic-lora-in-outpainting-0.9
1. fuse_lora_weights copies file-backed tensors straight to CUDA: 0.13 GiB/s on GB10
On the pinned streaming path, _build_pinned_source loads block weights with
load_state_dict. The tensors safetensors returns are backed by the memory-mapped
checkpoint. fuse_lora_weights then does, for every LoRA-affected key
(fuse_loras.py:144):
weight = original_weight.to(device=fusion_device)On GB10, a CUDA copy from that file-backed memory is dramatically slower than from ordinary process memory. Measured with 4 GiB of transformer block tensors:
| source of the host-to-device copy | rate |
|---|---|
safetensors.get_tensor(...) then .to("cuda"), cold page cache |
0.13 GiB/s |
| same, file fully in page cache | 0.13 GiB/s |
same tensors after .clone() (get_tensor + clone included in the time) |
12 GiB/s |
| ordinary pageable memory, one call | 17.6-20.1 GiB/s |
| ordinary pageable memory, 128 MiB calls | 55 GiB/s |
| pinned memory | 55 GiB/s |
Effect on a streaming build of the 22B transformer (--offload cpu, TRIM):
| build | time | of which base-weight host-to-device copy in fusion |
|---|---|---|
| without LoRA | 3.5-16 s | 0 |
| with the in/outpainting LoRA | 149-201 s | 135-178 s |
| with the LoRA, base weights cloned first | 15-21 s | 1.4-1.8 s |
In a full ICLoraPipeline render this made stage 1's transformer build 134-201 s, while
stage 2 (the same checkpoint without the LoRA) built in 6-12 s. With the workaround, stage
1 builds in 18-19 s, and a steady-state 9-frame 2560x1024 job goes from 233 s to 111 s.
Workaround we run: a view of the state dict whose get() returns
tensor.clone() for CPU tensors, passed to fuse_lora_weights only. Across five LoRA
builds, staged and unstaged, the sampled pinned block buffers were identical. A full
9-frame render compares bit-identical (max absolute difference 0 on every frame).
Suggested upstream fix: in _build_pinned_source, copy the base weight into its
pinned fill_views[key] first (host memcpy, fast), move it to CUDA from there (pinned),
fuse, and copy the result back into the same view. That needs no extra host allocation
and uses the fastest transfer path. We have only validated the clone variant.
We don't know why file-backed pages are this slow for the driver on GB10's unified memory, or whether discrete-GPU systems are affected. It reproduces in isolation:
import time, safetensors, torch
path = ".../ltx-2.5-22b-distilled-transformer-bf16.safetensors"
with safetensors.safe_open(path, framework="pt", device="cpu") as f:
names = [k for k in f.keys() if "transformer_blocks." in k]
for staged in (False, True):
got, secs = 0, 0.0
for name in names:
t = f.get_tensor(name)
torch.cuda.synchronize(); start = time.perf_counter()
(t.clone() if staged else t).to("cuda")
torch.cuda.synchronize(); secs += time.perf_counter() - start
got += t.nbytes
if got >= 4 * 1024**3:
break
print("staged" if staged else "file-backed", round(got / 1024**3 / secs, 2), "GiB/s")2. _build_pinned_source mutates a registry-owned state dict
_build_pinned_source nulls each entry it consumes (block_sd.sd[key] = None). But
load_state_dict (loader/helpers.py:37) returns the registry's retained object on a
cache hit. With a weight-caching registry (ModelRegistry() defaults to
cache_weights=True), the first build empties the cached dict. A second build of the same
checkpoint, such as ICLoraPipeline's stage 2 when both stages share a registry, gets
None for every block key, skips every fill, and streams from uninitialised pinned
memory without raising. Our render had max absolute difference 251 against a correct
one.
ic_lora.main() passes registry=None, so the stock CLI is not affected. Any library
caller that shares a registry across stages is.
Workaround we run: a registry subclass that stores and returns shallow copies of the
dict. Renders are then bit-identical to unshared ones. Suggested fix: track consumed
keys in a local set instead of writing None into block_sd.sd, or copy the dict before
mutating it. apply_loras' docstring already treats retained caches as read-only.
3. Slow first GPU read of cudaHostRegistered block buffers on GB10
_alloc_pinned_exact (block_streaming/utils.py:67) allocates each block's buffer with
torch.empty and pins it with cudaHostRegister, to avoid the caching host allocator's
power-of-2 rounding. On GB10 the GPU's first read of stage 1's buffers is
intermittently ~100x slower than it should be. Later steps, and stage 2, are always fast.
Measured by timing each block's copy in WeightsProvider._copy_to_gpu during the first
step of each stage. Six containers, one 9-frame 2560x1024 job each, page cache flushed
before each one:
| stage 1, step 1 (48 blocks, 34.6 GiB) | stage 2, step 1 | job | |
|---|---|---|---|
| 2 containers | 0.66 s (52.6 GiB/s) | 0.66 s | 120 s |
| 4 containers | 48-65 s (0.53-0.72 GiB/s) | 0.66 s | 171-220 s |
A block is either fast (0.014 s) or slow (~2.0 s for 0.72 GiB), with almost nothing in between; a stalled run has 23-32 slow blocks out of 48. Roughly 11 us per 4 KiB page of an affected block, which looks like a per-page cost on first access.
Two experiments:
- Transparent huge pages (
THP_MEM_ALLOC_ENABLE=1; the node is inmadvisemode): no effect, 4 of 6 containers still stalled. - Driver-allocated pinned memory instead of registered memory (forcing LTX's own
torch.empty(..., pin_memory=True)fallback): the stall disappeared, 6 of 6 containers at 0.66-1.04 s. But allocating and freeing it costs ~10 s each per model, and TRIM empties the host cache after every model, so the job went to 164-173 s. The denoise steps themselves were unchanged.
So the slow path is specific to memory pinned with cudaHostRegister after allocation.
Questions for you: have you seen this on DGX Spark, and would you consider allocating the
pinned block buffers with cudaHostAlloc at exact size, reused across the two stages
rather than freed between them? That would avoid both the rounding you are avoiding today
and the stall, at one allocation per process.
For reference, the earlier host-memory findings that led here: with a full page cache the
first denoise step stalled far more often, and flushing it
(sync; echo 3 > /proc/sys/vm/drop_caches) before each container removed most of it. We
first suspected memory compaction, but the kernel's compact_stall / compact_fail
counters move identically in fast runs, so that was a red herring. We now flush before
each task and budget for the remaining stall.
Source: Lightricks/LTX-2