HaaDeej commited on
Commit
464db64
·
verified ·
1 Parent(s): b6d131a

Upload ltx_loadonce.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. ltx_loadonce.py +12 -2
ltx_loadonce.py CHANGED
@@ -148,9 +148,19 @@ def _patched_gpu_model(model):
148
  finally:
149
  v0 = torch.cuda.memory_allocated() // 1024**3
150
  torch.cuda.synchronize()
151
- model.to("meta")
 
 
 
 
 
 
 
 
 
 
152
  v1 = torch.cuda.memory_allocated() // 1024**3
153
- print(f"[DIAG-gpu_model] {type(model).__name__} to(meta): {v0}GB -> {v1}GB", flush=True)
154
  _patched_cleanup()
155
 
156
  _gm_module.gpu_model = _patched_gpu_model
 
148
  finally:
149
  v0 = torch.cuda.memory_allocated() // 1024**3
150
  torch.cuda.synchronize()
151
+ # to("meta") is a known non-fix: meta device has no storage so GPU allocs stay.
152
+ # to("cpu") actually transfers parameters + registered buffers (incl. CausalConv3d
153
+ # temporal caches) to system RAM, releasing CUDA allocations.
154
+ model.to("cpu")
155
+ # Also null any causal/temporal cache buffers that survive to("cpu") as CUDA refs
156
+ for _m in model.modules():
157
+ for _attr in ("cache", "_cache", "temporal_cache", "causal_cache"):
158
+ if getattr(_m, _attr, None) is not None:
159
+ setattr(_m, _attr, None)
160
+ gc.collect()
161
+ torch.cuda.empty_cache()
162
  v1 = torch.cuda.memory_allocated() // 1024**3
163
+ print(f"[DIAG-gpu_model] {type(model).__name__} to(cpu): {v0}GB -> {v1}GB", flush=True)
164
  _patched_cleanup()
165
 
166
  _gm_module.gpu_model = _patched_gpu_model