clj-python / clj-python/libpython-clj

Consider releasing returned values from instance fns

未关闭
#242 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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 :-)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。