TurboDiffusion icon indicating copy to clipboard operation
TurboDiffusion copied to clipboard

OOM on 24GB GPU (like RTX 4090) on umt5 loading

Open gnattu opened this issue 11 months ago • 3 comments

Traceback (most recent call last):
  File "/src/TurboDiffusion/turbodiffusion/inference/wan2.2_i2v_infer.py", line 69, in <module>
    text_emb = get_umt5_embedding(checkpoint_path=args.text_encoder_path, prompts=args.prompt).to(**tensor_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/turbodiffusion/rcm/utils/umt5.py", line 534, in get_umt5_embedding
    t5_encoder = UMT5EncoderModel(text_len=max_length, device=device, checkpoint_path=checkpoint_path)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/turbodiffusion/rcm/utils/umt5.py", line 494, in __init__
    model = umt5_xxl(encoder_only=True, dtype=dtype, device=device).eval().requires_grad_(False)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/turbodiffusion/rcm/utils/umt5.py", line 465, in umt5_xxl
    return _t5("umt5-xxl", **cfg)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/turbodiffusion/rcm/utils/umt5.py", line 446, in _t5
    model = model.to(dtype=dtype, device=device)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1369, in to
    return self._apply(convert)
           ^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 928, in _apply
    module._apply(fn)
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 955, in _apply
    param_applied = fn(param)
                    ^^^^^^^^^
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1355, in convert
    return t.to(
           ^^^^^
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1.96 GiB. GPU 0 has a total capacity of 23.52 GiB of which 1.87 GiB is free. Including non-PyTorch memory, this process has 21.61 GiB memory in use. Of the allocated memory 21.16 GiB is allocated by PyTorch, and 11.05 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)

I'm running with torch==2.8.0 with cu128, this is totally unexpected as the paper mentioned that 4090 is a tested card.

gnattu avatar Dec 16 '25 12:12 gnattu

In commit 4b7bc05, we initialize UMT5 on the meta device, which should resolve this issue. Please try again and let us know if the problem persists.

whx1003 avatar Dec 16 '25 16:12 whx1003

It did make umt5 load but it looks like it is not properly unloaded before loading high noise model?

Traceback (most recent call last):
  File "/src/TurboDiffusion/turbodiffusion/inference/wan2.2_i2v_infer.py", line 73, in <module>
    high_noise_model = create_model(dit_path=args.high_noise_model_path, args=args).cpu()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/turbodiffusion/inference/modify_model.py", line 124, in create_model
    net = net.to(tensor_kwargs["device"]).eval()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1369, in to
    return self._apply(convert)
           ^^^^^^^^^^^^^^^^^^^^
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 928, in _apply
    module._apply(fn)
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 928, in _apply
    module._apply(fn)
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 928, in _apply
    module._apply(fn)
  [Previous line repeated 2 more times]
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1020, in _apply
    self._buffers[key] = fn(buf)
                         ^^^^^^^
  File "/src/TurboDiffusion/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1355, in convert
    return t.to(
           ^^^^^
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 26.00 MiB. GPU 0 has a total capacity of 23.52 GiB of which 14.25 MiB is free. Including non-PyTorch memory, this process has 23.00 GiB memory in use. Of the allocated memory 22.53 GiB is allocated by PyTorch, and 21.15 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)

It looks like umt5 is still in GPU memory so that the high noise model cannot even be loaded.

gnattu avatar Dec 17 '25 02:12 gnattu

Thanks for your feedback! The issue has been fixed in the latest code. Could you please try again to figure out if the problem is resolved :)

BTW, I noticed that you’re running inference with the I2V model. Based on our tests, inference with the 14B model requires slightly more than 24GB of VRAM. You can try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to reduce the amount of memory reserved by PyTorch. This can help run 14B inference on an RTX4090, although it may result in slightly slower performance.

whx1003 avatar Dec 17 '25 10:12 whx1003