You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[dlpack][runtime] Memory leak with dlpack capsules #20849
I'm not entirely sure what is going on, but I noticed in iree.turbine.kernel.wave.utils.run_utils, they need to rename the dlpack capsule from used_dltensor back to dltensor for some reason.
I was running into some memory issues with larger models (with several iree kernels plugged in), and renaming the capsules seemed to resolve the OOM.
My rough guess is that renaming the capsule to used_dltensor somehow invalidates the external deleter (which I assume is provided by pytorch).
Steps to reproduce your issue
install iree-turbine versioned earlier than today (5/19/2025)
torch.OutOfMemoryError: HIP out of memory. Tried to allocate 64.00 MiB. GPU 0 has a total capacity of 191.98 GiB of which 40.00 MiB is free. Of the allocated memory 191.25 GiB is allocated by PyTorch, and 0 bytes is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_HIP_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
However, if we rename the capsule back to dltensor after buffer view import in iree.turbine.runtime.device._device_import_torch_tensor_cuda_hip, then the issue no longer persists.
Activity
zjgarvey commentedon May 19, 2025
@raikonenfnu
I remember you having some better idea about what we should do to actually fix this.
[runtime] Rename dltensor capsule to avoid memory leak (#843)
stellaraccident commentedon Jun 3, 2025
Repro is good but this needs a root cause. Also see the design that dlpack uses for the ownership handoff: https://dmlc.github.io/dlpack/latest/python_spec.html#implementation
stellaraccident commentedon Jun 3, 2025
Note that the 843 patch has been reverted, so this likely repros at head.
zjgarvey commentedon Jun 3, 2025
@stellaraccident I'm sorry for the sloppy patch in turbine. I should have prioritized this higher and found a valid fix.
raikonenfnu commentedon Jun 3, 2025
Yeap! there was a typo in the naming of the dlpack capsule tensor haha, will push up a quick fix for that :)
Update IREE version, remove dlpack hack and add tensor leak test (#893)
zjgarvey commentedon Jun 4, 2025
@AWoloszyn @Hardcode84 Is this issue good to close?
AWoloszyn commentedon Jun 4, 2025
As far as I can tell this should be good to close.
I found an obvious memory leak, and the sample no longer leaks.
Hardcode84 commentedon Jun 4, 2025
Yes, look like fix works for Wave