The WeakValueDictionary holds weak references to tensors. When a tensor's reference count reaches zero, Python automatically removes it from the cache, freeing memory. This mechanism prevents memory leaks by auto-removing cached tensors that are no longer in use, thus saving RAM during large model inference without requiring manual cleanup.
python WeakValueDictionary
Creator
Creator

Created
Created
2024 Oct 25 19:20Editor
Editor

Edited
Edited
2024 Oct 25 19:21Refs
Refs
C++ Smart Pointer