clj-python / clj-python/libpython-clj
Consider releasing returned values from instance fns
未關閉
還沒有人認領這個 Issue。
- 主要語言
- Clojure
- 星號
- 1.2k
- 分支
- 74
- PR 合併指標
- 30 天內沒有已合併 PR
描述
This will collect memory automatically:
(py/run-simple-string "
import torch.utils.data as tud
import torch
class DebugDataset (tud.Dataset):
def __init__(self):
pass
def __len__(self):
return 1000
def __getitem__ (self, i):
return torch.rand(1000, 1000, 1000)
d = DebugDataset()
print(d[0])
print(d[0])")
If the user defines a dataset using clojure and this will cause issues unless the user spams (System/gc):
(let [globals! (py/module-dict (py/add-module "__main__"))]
(.put globals! "DebugDatasetClj" DebugDataset))
(py/run-simple-string "
d = DebugDatasetClj()
print(d[0])
print(d[0])")
The issue is make-instance-fn runs in the normal jvm context so it is keeping jvm references to the produced items. It does not need to do this; the normal python reference keeping system will work just fine. Fixing this in a robust way will require some thought :-)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先追蹤 make-instance-fn 以及它如何從 py/run-simple-string 呼叫,然後重現 dataset 範例以觀察保留的記憶體。確認在正常 JVM 環境中回傳值是如何被持有的,並驗證 Python 參照處理可以在不手動呼叫 System/gc 的情況下釋放它們。完成標準是,重複存取 dataset 不再累積這些 JVM 參照。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- clojure, python
- 領域
- backend, performance
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100