개발/AWS

라이브러리 import 순서에 따른 에러

beomcoder 2023. 7. 10. 10:15
728x90
반응형

로컬에서는 문제없이 돌아가는 코드가 AWS 서버로 옮기니까 다음과 같은 에러가 발생했다.

terminate called after throwing an instance of 'std::runtime_error'
  what():  random_device could not be read

난생 처음보는 에러이고 로컬에서는 돌아가니 난감했다.

그래도 다행히 하나만 추가했는데 에러가 발생해서 금방 원인을 찾을 수 있었다.

내가 추가한건 ultralytics이고, import torch를 포함하는 라이브러리이다.

 

결론부터 말하자면 라이브러리 import 순서에 따른 AWS에서만 발생하는 에러였다.

torch와 tensorflow를 동시에 import를 하면 에러가 발생하는데,

 

torch를 먼저 import하고, tensorflow를 나중에 import하면 문제가 해결된다.

 

왜 이런게 발생하는지는 찾지 못했는데

한번 원인을 찾고 싶은분들은 pytorch issues를 찾아보면 좋겠다.

 

https://github.com/pytorch/pytorch/issues/101152

 

Importing torch after TensorFlow results in std::runtime_error · Issue #101152 · pytorch/pytorch

🐛 Describe the bug The following minimal example (Dockerfile, just run docker build with it ) reproduces the error: FROM python:3.11.3 RUN pip install tensorflow==2.12.0 torch==2.0.1 RUN python -c ...

github.com

import tensorflow
import torch

"""
terminate called after throwing an instance of 'std::runtime_error'
  what():  random_device could not be read
Aborted (core dumped)
"""


import torch
import tensorflow

"""
no err
"""
728x90
반응형