clj-python / clj-python/libpython-clj

Consider releasing returned values from instance fns

オープン
#242 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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. リポジトリをフォークし、ブランチを切って変更します。
  4. 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 を短くまとめたダイジェスト。