์ด๊ฒ์ด PyTorch ๋ฒ๊ทธ์ธ์ง, scikit-learn ๋ฒ๊ทธ์ธ์ง ๋๋ ์ซ์์ธ์ง ํ์คํ์ง ์์ง๋ง, ์ด๊ฒ์ scikit-learn 0.20.3์์ ์๋ํ๊ณ 0.21.0 ์๋ฆฌ์ฆ์์ ์๋์ ๋ฉ์ท์ผ๋ฏ๋ก ์ง๊ธ์ ๋ชจํ์ ํ๋ ค๊ณ ํฉ๋๋ค. scikit learn์ ํ๊ท๋ผ๊ณ ์ถ์ธกํฉ๋๋ค.
๋ค์ ์ผ๋ จ์ ๊ฐ์ ธ์ค๊ธฐ( import librosa
์๋ ์๋ ๊ฐ์ ธ์ค๊ธฐ์์ ์ต์ํ)๋ฅผ ์ํํ๋ฉด ๋ค์ ํ๋ก๊ทธ๋จ ๋ก๋๊ฐ ์คํจํฉ๋๋ค.
import torch
import soundfile
import scipy.signal
import numba
import sklearn
~์ ํจ๊ป
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sklearn/__check_build/__init__.py", line 44, in <module>
from ._check_build import check_build # noqa
ImportError: dlopen: cannot load any more object with static TLS
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_torch.py", line 5, in <module>
import sklearn
File "/opt/conda/lib/python3.6/site-packages/sklearn/__init__.py", line 75, in <module>
from . import __check_build
File "/opt/conda/lib/python3.6/site-packages/sklearn/__check_build/__init__.py", line 46, in <module>
raise_build_error(e)
File "/opt/conda/lib/python3.6/site-packages/sklearn/__check_build/__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: dlopen: cannot load any more object with static TLS
___________________________________________________________________________
Contents of /opt/conda/lib/python3.6/site-packages/sklearn/__check_build:
_check_build.cpython-36m-x86_64-linux-gnu.so__pycache__ __init__.py
setup.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
scikit-learn 0.20.3์ผ๋ก ๋ค์ด๊ทธ๋ ์ด๋ํ๋ฉด ๋ฌธ์ ๊ฐ ์ฌ๋ผ์ง๋๋ค.
jenkins<strong i="15">@260bf77532d0</strong>:~/workspace/test$ python
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn; sklearn.show_versions()
System:
python: 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) [GCC 7.3.0]
executable: /opt/conda/bin/python
machine: Linux-4.15.0-29-generic-x86_64-with-debian-jessie-sid
BLAS:
macros: SCIPY_MKL_H=None, HAVE_CBLAS=None
lib_dirs: /opt/conda/lib
cblas_libs: mkl_rt, pthread
Python deps:
pip: 19.1.1
setuptools: 41.0.1
sklearn: 0.21.2
numpy: 1.16.4
scipy: 1.1.0
Cython: None
pandas: None
๋ํ ๋ค์ ํญ๋ชฉ์ ๊ด์ฌ์ด ์์ ์ ์์ต๋๋ค.
jenkins<strong i="19">@260bf77532d0</strong>:~/workspace/test$ pip list | grep numba
numba 0.43.1
jenkins<strong i="20">@260bf77532d0</strong>:~/workspace/test$ pip list | grep torch
torch 1.2.0a0+ab800ad
์ด ๋ฌธ์ ๋ฅผ ์ผ์ผํค๋ ค๋ฉด ํ ์น ๋น๋๋ฅผ gcc 5.5.0์ผ๋ก ์ํํด์ผ ํฉ๋๋ค. ๋ค๋ฅธ ๋ฒ์ ์ gcc๋ ์ด ๋ฌธ์ ๋ฅผ ์ผ์ผํค์ง ์๋ ๊ฒ์ผ๋ก ์๋ ค์ ธ ์์ต๋๋ค.
๋ณต์ ์ ์ฉ์ด์ฑ์ ์ํด ๋ค์ ๋์ปค ์ด๋ฏธ์ง ezyang/scikit-learn-tls-repro:1
https://cloud.docker.com/repository/registry-1.docker.io/ezyang/scikit-learn-tls-repro๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์์์ ์ค๋ช
ํ ๋๋ก ์ฌ์์ฐ ์ง์นจ์ ๋ฐ๋ฅด์ญ์์ค. (ํธ์ง ์์ฑ ๋น์ Docker ์ด๋ฏธ์ง๋ ์์ง ์
๋ก๋ ์ค์
๋๋ค. ๊ณง ์๋ฃ๋์ด์ผ ํฉ๋๋ค.)
์ ๊ณ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. sklearn์ ์ด๋ป๊ฒ ๋น๋/์ค์นํ์ จ๋์?
pip install scikit-learn
๊ทธ์ ๋ํ ๋ก๊ทธ๊ฐ ์์ต๋๊น? ์์ค์์ ๋น๋ํ์ต๋๊น ์๋๋ฉด ํ ์ ์ค์นํ์ต๋๊น?
Collecting scikit-learn
Using cached https://files.pythonhosted.org/packages/85/04/49633f490f726da6e454fddc8e938bbb5bfed
2001681118d3814c219b723/scikit_learn-0.21.2-cp36-cp36m-manylinux1_x86_64.whl
@ezyang ๊ฐ๋ฅํ๋ค๋ฉด Dockerfile
๋ฅผ ๊ณต์ ํ ์ ์์ต๋๋ค.
๋๊ตฌ๋ ์ง ์ด ์ค๋ฅ๋ฅผ ์ฌํํ๋ ๋ฐ ๊ด์ฌ์ด ์๋ค๋ฉด ์ฌ์ฉํ ์ฌ๋ฐ๋ฅธ ๋์ปค ์ฃผ๋ฌธ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
docker run -it ezyang/scikit-learn-tls-repro:1 bash
1
ํ๊ทธ๋ฅผ ๋ช
์์ ์ผ๋ก ์ง์ ํด์ผ ํฉ๋๋ค.
Unable to find image 'ezyang/scikit-learn-tls-repro:latest' locally
docker: Error response from daemon: manifest for ezyang/scikit-learn-tls-repro:latest not found.
๋๋ ์ด๋ฐ ์ผ์ด ์ ์๋ฌด ์๊ฐ์ด ์๋ค,ํ์ง๋ง ๋ pytorch์ผ๋ก์ด ์์ ๊ด๋ จ๋ ๋ค์์ ๋ฒ๊ทธ ๋ฆฌํฌํธ๋ฅผ ๋ณด์ผํ๊ณ OpenCV์ https://github.com/pytorch/pytorch/issues/2083 ๋๋ OpenCV์ ๋ฐ Tensorflow https://github.com /tensorflow/models/issues/523. ๋์ฒด๋ก ๋๋ ์ด๊ฒ์ด scikit-learn ๋ฒ๊ทธ๊ฐ ์๋๋ผ๊ณ ์ถ์ธกํฉ๋๋ค.
๊ฐ์ ธ์ค๊ธฐ ์์์ ์์กดํ๋ค๋ ์ฌ์ค์ ๋น์ ์์ ์ ๋๋ค. ์๋ฅผ ๋ค์ด ์ด๊ฒ์ ๋์ปค ์ด๋ฏธ์ง์์ ์๋ํฉ๋๋ค.
python -c 'import torch; import sklearn; import soundfile; import scipy.signal; import numba'
์ฐธ๊ณ ๋๋ conda ํ๊ฒฝ(์ข์ ์ธก์ ์ ์ํด ๋์ปค ์ด๋ฏธ์ง ๋ด๋ถ) ๋ด์์ ์ฌํํ๋ ค๊ณ ์๋ํ์ง๋ง ํ ์ ์์์ต๋๋ค( scikit-learn 0.21.2
๋ฐ pytorch 1.1.0
). ๋ฐ๋ผ์ ์ด๊ฒ์ด pytorch dev์ ์ผ๋ถ ๋ณ๊ฒฝ ์ฌํญ๊ณผ ์ฐ๊ฒฐ๋ ์ ์์ต๋๋ค. ๋ฒ์ .
conda create -n test -c pytorch pytorch scikit-learn scipy numba scikit-learn -y
conda activate test
pip install soundfile
python -c 'import torch; import soundfile; import scipy.signal; import numba; import sklearn'
$ conda list
# packages in environment at /opt/conda/envs/test:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
blas 1.0 mkl
ca-certificates 2019.5.15 0
certifi 2019.6.16 py37_1
cffi 1.12.3 py37h2e261b9_0
cudatoolkit 10.0.130 0
intel-openmp 2019.4 243
joblib 0.13.2 py37_0
libedit 3.1.20181209 hc058e9b_0
libffi 3.2.1 hd88cf55_4
libgcc-ng 9.1.0 hdf63c60_0
libgfortran-ng 7.3.0 hdf63c60_0
libstdcxx-ng 9.1.0 hdf63c60_0
llvmlite 0.29.0 py37hd408876_0
mkl 2019.4 243
mkl-service 2.0.2 py37h7b6447c_0
mkl_fft 1.0.12 py37ha843d7b_0
mkl_random 1.0.2 py37hd81dba3_0
ncurses 6.1 he6710b0_1
ninja 1.9.0 py37hfd86e86_0
numba 0.45.0 py37h962f231_0
numpy 1.16.4 py37h7e9f1db_0
numpy-base 1.16.4 py37hde5b4d6_0
openssl 1.1.1c h7b6447c_1
pip 19.1.1 py37_0
pycparser 2.19 py37_0
python 3.7.3 h0371630_0
pytorch 1.1.0 py3.7_cuda10.0.130_cudnn7.5.1_0 pytorch
readline 7.0 h7b6447c_5
scikit-learn 0.21.2 py37hd81dba3_0
scipy 1.3.0 py37h7c811a0_0
setuptools 41.0.1 py37_0
six 1.12.0 py37_0
soundfile 0.10.2 pypi_0 pypi
sqlite 3.29.0 h7b6447c_0
tk 8.6.8 hbc83047_0
wheel 0.33.4 py37_0
xz 5.2.4 h14c3975_4
zlib 1.2.11 h7b6447c_3
dev ๋น๋์์ ๋ฌธ์ ๊ฐ ์ฌํ๋๋ ๊ฒฝ์ฐ scikit-learn์์ ์ด๋ฑ๋ถ์ ์ป๋ ๊ฒ์ด ์ ์ฉํ๊ณ ๋์์ด ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
์ผ๋ฐ์ ์ผ๋ก ๋งํ์๋ฉด, ์ด๋ฌํ ์ข ๋ฅ์ ๋ฌธ์ ์ ๋ํ ์ ๋ฌธ ์ง์์ PyTorch ์ธก์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ฐ์ธ์ ์ผ๋ก, ๋๋ ์ ์ ์ ์ TLS์ ๋ํด ๋ค์ด๋ณธ ์ ์ด ์์ผ๋ฉฐ ์ด๊ฒ์ด ๋ค๋ฅธ ๋ง์ ํต์ฌ scikit-learn ๊ฐ๋ฐ์์ ๊ฒฝ์ฐ๋ผ๊ณ ์ถ์ธกํ ์ ์์ง๋ง ๋ง์ง๋ง ์ง์ ์ ๋ํด์๋ ํ๋ฆด ์ ์์ต๋๋ค.
IIUC์์๋ ์๋ scikit-learn 0.21.2 ๋ฐ pytorch dev ๋ฒ์ ์ ๋ฌธ์ ๋ฅผ ๋ณด์์ต๋๋ค. https://github.com/scikit-learn/scikit-learn/issues/14485#issuecomment -517195977์ ๋ช ์๋ ๋๋ก scikit-learn 0.21.2 ๋ฐ pytorch 1.1.0์์ ๋ฌธ์ ๋ฅผ ์ฌํํ ์ ์์ต๋๋ค. ์ด๊ฒ์ ๋ ์์ธํ ์ดํดํ๋ ค๊ณ ํ๋ฉด PyTorch๋ฅผ ์ด๋ฑ๋ถํ ๊ฒ์ ๋๋ค.
@ezyang ๋งํฌ๋ ๋ฌธ์ ์๋ ์ด TLS(์ค๋ ๋ ๋ก์ปฌ ์ ์ฅ์) ๋ฌธ์ ์ ๋ํ ๋ง์ ์ ๋ณด๊ฐ ์์ต๋๋ค.
๋ค์์ ๋ด๊ฐ ์ด์ ์ ํํค์น ์ ๋ณด์
๋๋ค. https://github.com/pytorch/pytorch/issues/2575#issuecomment -369892859
;TLDR: ๊ฐ์ ธ์ค๊ธฐ ์ฒด์ธ์ ๋ฌด์ธ๊ฐ๊ฐ -gPIC
ํ๋๊ทธ๋ก C/C++ ์ปดํ์ผ๋์ง ์์์ต๋๋ค. ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ์ ธ์ค๋ฉด ๋ชจ๋ ๊ฐ์ ธ์ค๊ธฐ๊ฐ "์ ์ TLS"๋ก ๋ฐ๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ด๋ฌํ "์ ์ TLS" ์ฌ๋กฏ์ ์ต๋ ๊ฐ์๊ฐ ์์ต๋๋ค(์ฌ๊ธฐ์ ์ฌ์ฉํ๋ ์ด๋ฆ์ ํ์คํ ํ๋ฆฝ๋๋ค). ์ ํํ ์ฌ๋กฏ N์ OS์ ์ปดํ์ผ ๋ฐฉ์์ ๋ฐ๋ผ ๋ค๋ฆ
๋๋ค.
์ฐ๊ฒฐ๋ pytorch ๋ฌธ์ 2575์๋ ์บ์ค์ผ์ด๋๋ฅผ ์ ๋ฐํ๋ ํ๋๊ทธ ์์ด ์ปดํ์ผ๋ ๊ฒ์ด OpenMP๋ผ๋ ์ธ๊ธ์ด ์์ต๋๋ค.
์ด scikit-learn ๋ฌธ์ ๋ ๋ช ๊ฐ์ง ์๋ก์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋์
๋๊ฑฐ๋ ๋ช ๊ฐ์ง ์ ์ TLS ์ฌ๋กฏ์ ๋ ์ฌ์ฉํ๋ ์ผ๋ถ ๋ณ๊ฒฝ์ผ๋ก ์ธํด ๋ฐ์ํ ์ ์์ต๋๋ค.
์ฐธ๊ณ : ์ค์ ์ ๋ฌธ๊ฐ๊ฐ ์๋๋๋ค. ์ด ์ค๋ฅ์ ๋ํ ๋ค๋ฅธ ์์ค๊ฐ "์ปดํ์ผ ์ `-gPIC' ํ๋๊ทธ๊ฐ ๋๋ฝ๋ ํ๋/์ผ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ"๊ฐ ์์ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ํ๋๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค.
์ด์ ๋ํ ์ ๋ฐ์ดํธ๊ฐ ์์์ต๋๊น? librosa๋ฅผ ๊ฐ์ ธ์ฌ ๋๋ ์ด ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์์ต๋๋ค.
https://github.com/pytorch/pytorch/issues/2575#issuecomment -523657178 ํ์ธ
import sklearn์ผ๋ก ํด๊ฒฐํ ๋ค์ tensorflow๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ๊ฐ์ ธ์ค๊ธฐ ์์๋ก ์ธํด ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
import sklearn์ผ๋ก ํด๊ฒฐํ ๋ค์ tensorflow๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ๊ฐ์ ธ์ค๊ธฐ ์์๋ก ์ธํด ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.