Project-MONAI / Project-MONAI/MONAI

ResourceWarning: Implicitly cleaning up

Offen
#6,167 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
8.7k
Forks
1.6k
Ø Merge
5 T. 1 Std.
Gemergte PRs (30 T.)
20

Beschreibung

Describe the bug
warning message from

python -W error -c "import monai"

with pytorch 2.0

Traceback (most recent call last):
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/weakref.py", line 642, in _exitfunc
    f()
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/weakref.py", line 566, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/tempfile.py", line 818, in _cleanup
    _warnings.warn(warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <TemporaryDirectory '/var/folders/6f/fdkl7m0x7sz3nj_t7p3ccgz00000gp/T/tmpqtvvcx_b'>

debugging further looks like it's triggered via importing pytorch ignite

  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/ignite/handlers/checkpoint.py(17)<module>()
-> from torch.distributed.optim import ZeroRedundancyOptimizer
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/optim/__init__.py(20)<module>()
-> from .named_optimizer import _NamedOptimizer
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/optim/named_optimizer.py(10)<module>()
-> from torch.distributed._shard.sharded_tensor import ShardedTensor
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(961)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/_shard/__init__.py(1)<module>()
-> from .api import (
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/_shard/api.py(6)<module>()
-> from torch.distributed._shard.sharded_tensor import (
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/_shard/sharded_tensor/__init__.py(9)<module>()
-> from torch.distributed._shard.partial_tensor import _PartialTensor
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/_shard/partial_tensor.py(8)<module>()
-> from torch.distributed.nn.functional import (
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(961)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/nn/__init__.py(3)<module>()
-> from .api.remote_module import RemoteModule
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/nn/api/remote_module.py(24)<module>()
-> from torch.distributed.nn.jit import instantiator
  <frozen importlib._bootstrap>(1042)_handle_fromlist()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  <frozen importlib._bootstrap>(991)_find_and_load()
  <frozen importlib._bootstrap>(975)_find_and_load_unlocked()
  <frozen importlib._bootstrap>(671)_load_unlocked()
  <frozen importlib._bootstrap_external>(843)exec_module()
  <frozen importlib._bootstrap>(219)_call_with_frames_removed()
  /usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/torch/distributed/nn/jit/instantiator.py(19)<module>()
-> _TEMP_DIR = tempfile.TemporaryDirectory()
  /usr/local/anaconda3/envs/py38/lib/python3.8/tempfile.py(781)__init__()
-> self._finalizer = _weakref.finalize(
> /usr/local/anaconda3/envs/py38/lib/python3.8/weakref.py(519)__init__()
-> if len(args) >= 3:

(fyi @vfdev-5 )

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduzieren Sie die Warnung mit python -W error -c "import monai" und untersuchen Sie die Importkette über PyTorch Ignite bis zu torch.distributed.nn.jit.instantiator.py, wo das temporäre Verzeichnis erstellt wird. Ermitteln Sie, ob MONAI das Auslösen der Cleanup-Warnung vermeiden kann; erledigt ist die Aufgabe, wenn der Import keine gemeldete ResourceWarning mehr erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python, pytorch
Bereich
machine-learning
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.