decord icon indicating copy to clipboard operation
decord copied to clipboard

Importing `torch` after importing `decord` causes hanging behavior

Open akashc1 opened this issue 1 year ago • 6 comments

I ran into a strange issue where the import order specifically between torch and decord can causing hanging behavior.

Concretely, I found that having your imports like this (which could happen by chance or if you use isort):

import decord
import torch  # hangs :(

will cause a hang. However, switching the order of imports fixes the issue:

import torch
import decord

This seems like some issue with the way decord's imports are set up internally, though I'm not sure exactly what would cause this. This is what the trace looks like when it's truly hanging:

>(963): <frozen importlib._bootstrap>(1003): <frozen importlib._bootstrap>(1006):  --- modulename: _bootstrap, funcname: _load_unlocked
<frozen importlib._bootstrap>(666): <frozen importlib._bootstrap>(668): <frozen importlib._bootstrap>(674):  --- modulename: _bootstrap, funcname: module_from_spec
<frozen importlib._bootstrap>(567): <frozen importlib._bootstrap>(568): <frozen importlib._bootstrap>(571):  --- modulename: _bootstrap_external, funcname: create_module
<frozen importlib._bootstrap_external>(1176): <frozen importlib._bootstrap_external>(1177): <frozen importlib._bootstrap_external>(1176):  --- modulename: _bootstrap, funcname: _call_with_frames_removed

Steps to reproduce:

  1. Create conda environment
conda create -p NEW_ENV_PATH python=3.10
conda activate NEW_ENV_PATH
pip install torch decord
  1. Create interactive python session
  2. Import decord: import decord
  3. Attempt to import torch: import torch

I found this to be reproducible with the following settings:

>>> torch.__version__
'2.0.0+cu117'
>>> decord.__version__
'0.6.0'

OS: CentOS Linux Version 7 (Core)

akashc1 avatar Apr 27 '23 20:04 akashc1

Bumping this! I spent a while trying to figure out my script wasn't running, but this was exactly why.

naitian avatar Aug 08 '23 21:08 naitian

Same issue here

ChristianIngwersen avatar Sep 19 '23 08:09 ChristianIngwersen

Same issue

Jesse-XIE avatar Oct 06 '23 11:10 Jesse-XIE

See @sailordiary's comment on #186 https://github.com/dmlc/decord/issues/186#issuecomment-1171882325

zhanwenchen avatar Oct 13 '23 18:10 zhanwenchen

I found this to be reproducible with the following settings:

@zhanwenchen thanks for the pointer, could you please clarify how that comment addresses this issue? Are you proposing that it's related to the FFmpeg build?

akashc1 avatar Oct 13 '23 22:10 akashc1

I hit the same issue when using pytorch==2.0.1 and decord==0.6.0 ; Another environment with pytorch==2.2.1 and decord==0.6.0 seems to work though.

SuperIRabbit avatar Apr 13 '24 21:04 SuperIRabbit