Project-MONAI / Project-MONAI/MONAI

ResourceWarning: Implicitly cleaning up

Ouverte
#6,167 2 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug
Langage dominant
Python
Étoiles
8.7k
Forks
1.6k
Merge moyen
5 j 1 h
PR mergées (30 j)
20

Description

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 )

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Reproduisez l’avertissement avec python -W error -c "import monai" et inspectez la chaîne d’importation via PyTorch Ignite jusqu’à torch.distributed.nn.jit.instantiator.py, où le répertoire temporaire est créé. Déterminez si MONAI peut éviter de déclencher l’avertissement de nettoyage ; le travail est terminé lorsque l’importation ne produit plus la ResourceWarning signalée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python, pytorch
Domaine
machine-learning
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.