Skip to content

LTX chain hardening: pinned-memory allocation, onload idempotency, connector_embeds, pinned Gemma3 - #41

Merged
TroyHernandez merged 7 commits into
mainfrom
fix/pin-memory-deprecation
Jul 22, 2026
Merged

LTX chain hardening: pinned-memory allocation, onload idempotency, connector_embeds, pinned Gemma3#41
TroyHernandez merged 7 commits into
mainfrom
fix/pin-memory-deprecation

Conversation

@TroyHernandez

@TroyHernandez TroyHernandez commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Four related fixes/seams that came out of chained-generation benchmarking at 960x960. Together they take a 3-chunk chained track from ~490 s to ~418 s (~15%) and make resident-transformer configurations actually work.

1. Pin host memory via torch_empty_strided, not the deprecated overload

This torch build's Tensor$pin_memory() binding requires the deprecated device argument (omitting it errors; passing it prints two libtorch warnings per tensor — thousands of lines per pipeline load). .ltx23_pin_host() now allocates page-locked buffers with torch_empty_strided(pin_memory = TRUE) and copies in; the noisy path survives only as a fallback. Validated at 25.1 GB/s H2D (the card's DMA ceiling) with clean stderr; 931 GPU-visible suite results green.

2. Onload idempotency probes the staging pair

The resident= onload check read module$parameters[[1]] inside a tryCatch whose failure mode was a silent re-onload — for module classes that don't expose $parameters (the NF4 transformer), every "resident" call re-transferred 11 GB over itself and fragmented the allocator pool. The probe now reads the staging pair's live tensor, which exists for every pinned component.

3. connector_embeds= on txt2vid_ltx2()

The per-call connectors phase moves the raw Gemma3 hidden-state stack to the GPU — designed for a card the transformer hasn't boarded yet, and the cause of a geometry-independent OOM (identical 14.97 GiB signature at 928 and 960) in every resident-chain attempt. The prompt is constant across a chained track, so precomputed connector outputs (~9 MB) can now be passed once and reused; benchmarked, this cuts the denoise-phase peak by ~2.5 GiB at constant resolution.

4. Pinned Gemma3 staging

The Gemma3 loaders gain pin= (default: the diffuseR.pin_staging option). A CPU-resident encoder is page-locked once, and encode_with_gemma3() swaps it to the compute device per encode (~0.3 s on at DMA rate, pointer-swap off) instead of holding ~8 GB of VRAM or reloading (~15 s). GPU-validated: staging attaches, weights return to CPU after each encode.

Benchmark context

Four instrumented runs (two per chain variant, alternating order, all phases fenced with cuda_synchronize): resident and cycled transformer configurations are within noise of each other once pinned re-onload (0.5 s for 11 GB) is accounted for — the win comes from in-memory conditioning, trim_frames, and the connector bypass, not residency.

pin_staging defaulting on (#37) made every pipeline load print two
libtorch deprecation warnings per pinned tensor - thousands of lines -
because this torch build's Tensor$pin_memory() binding requires the
deprecated device argument (omitting it errors with 'Expected a
torch_device'). torch_empty_strided is the one creation op exposing
pin_memory, so .ltx23_pin_host allocates pinned storage with
contiguous strides and copies in; the noisy device-arg call remains as
a suppressWarnings fallback for builds where that path fails.

GPU validation (is-it-actually-pinned via transfer-rate check) pending
- the card is occupied by a live render session; code-only change,
nothing installed.
@TroyHernandez
TroyHernandez merged commit 713c5b7 into main Jul 22, 2026
2 checks passed
@TroyHernandez
TroyHernandez deleted the fix/pin-memory-deprecation branch July 22, 2026 19:44
@TroyHernandez TroyHernandez changed the title Pin host memory via torch_empty_strided, not the deprecated overload LTX chain hardening: pinned-memory allocation, onload idempotency, connector_embeds, pinned Gemma3 Jul 22, 2026
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