티스토리 뷰

kakao buffalo

카카오에서 쓰는 collaborative filtering이 오픈소스로 공개됐다.

실제 현업에서 쓰는 모듈이기에 유용하게 쓸 수 있을 것 같다.

if kakao에서도 키노트에서 언급할 만큼 카카오에서 밀어주는 것 같은데, 누구보다 빠르게 써봐야겠다.

 

github : https://github.com/kakao/buffalo

docmentation : https://buffalo-recsys.readthedocs.io/en/latest/intro.html#installation

출처 : https://github.com/kakao/buffalo

참 소가 잘 생겼다.

 

설치

내 환경은 우분투 18.04이다.

 

requirement가 3개다.

3개 모두 있어야 버팔로 설치가 가능하다.

numpy는 많이들 쓰고 있어서 이미 설치가 되어있을 것 같고(난 되어 있었음 ㅎ)

n2와 cython을 설치했다.

 

(pip install numpy)
pip install Cython
pip install n2

pip install buffalo

뭔가 많이 설치된다.

 

중간에 에러가 났다.

    ERROR: Command errored out with exit status 1:
     command: /home/.../myvenv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-e9ednexv/buffalo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-e9ednexv/buffalo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-mpf40q31/install-record.txt --single-version-externally-managed --compile --install-headers /home/.../myvenv/include/site/python3.6/buffalo
         cwd: /tmp/pip-install-e9ednexv/buffalo/
    Complete output (47 lines):
    WARNING:root:The nvcc binary could not be located in your $PATH. Either add it to your path, or set $CUDAHOME to enable CUDA extensions
    Failed to find CUDA toolkit. Building without GPU acceleration.
    fatal: not a git repository (or any of the parent directories): .git
    running install
    fatal: (현재 폴더 또는 상위 폴더 중 일부가) 깃 저장소가 아닙니다: .git
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/buffalo
    creating build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/bpr.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/w2v.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/base.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/cfr.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/__init__.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/als.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/options.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    copying buffalo/algo/optimize.py -> build/lib.linux-x86_64-3.6/buffalo/algo
    creating build/lib.linux-x86_64-3.6/buffalo/algo/cuda
    copying buffalo/algo/cuda/__init__.py -> build/lib.linux-x86_64-3.6/buffalo/algo/cuda
    creating build/lib.linux-x86_64-3.6/buffalo/algo/tensorflow
    copying buffalo/algo/tensorflow/__init__.py -> build/lib.linux-x86_64-3.6/buffalo/algo/tensorflow
    copying buffalo/algo/tensorflow/_als.py -> build/lib.linux-x86_64-3.6/buffalo/algo/tensorflow
    creating build/lib.linux-x86_64-3.6/buffalo/data
    copying buffalo/data/buffered_data.py -> build/lib.linux-x86_64-3.6/buffalo/data
    copying buffalo/data/base.py -> build/lib.linux-x86_64-3.6/buffalo/data
    copying buffalo/data/prepro.py -> build/lib.linux-x86_64-3.6/buffalo/data
    copying buffalo/data/mm.py -> build/lib.linux-x86_64-3.6/buffalo/data
    copying buffalo/data/__init__.py -> build/lib.linux-x86_64-3.6/buffalo/data
    copying buffalo/data/stream.py -> build/lib.linux-x86_64-3.6/buffalo/data
    creating build/lib.linux-x86_64-3.6/buffalo/evaluate
    copying buffalo/evaluate/base.py -> build/lib.linux-x86_64-3.6/buffalo/evaluate
    copying buffalo/evaluate/__init__.py -> build/lib.linux-x86_64-3.6/buffalo/evaluate
    creating build/lib.linux-x86_64-3.6/buffalo/parallel
    copying buffalo/parallel/base.py -> build/lib.linux-x86_64-3.6/buffalo/parallel
    copying buffalo/parallel/__init__.py -> build/lib.linux-x86_64-3.6/buffalo/parallel
    creating build/lib.linux-x86_64-3.6/buffalo/misc
    copying buffalo/misc/__init__.py -> build/lib.linux-x86_64-3.6/buffalo/misc
    copying buffalo/misc/aux.py -> build/lib.linux-x86_64-3.6/buffalo/misc
    copying buffalo/version.py -> build/lib.linux-x86_64-3.6/buffalo
    copying buffalo/cli.py -> build/lib.linux-x86_64-3.6/buffalo
    copying buffalo/__init__.py -> build/lib.linux-x86_64-3.6/buffalo
    running build_ext
    cmake /tmp/pip-install-e9ednexv/buffalo -DCMAKE_BUILD_TYPE=Release -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-e9ednexv/buffalo/build/lib.linux-x86_64-3.6
    unable to execute 'cmake': No such file or directory
    error: command 'cmake' failed with exit status 1

 

어... cmake가 뭐지....

커맨드라인에 cmake를 쳐보니 sudo apt install cmake를 하란다.

 

했더니 조금 다른 에러가 난다.

...

	[100%] Built target cbuffalo
    Install the project...
    -- Install configuration: "Release"
    -- Installing: /usr/local/lib/libcbuffalo.so.0.1.0
    CMake Error at cmake_install.cmake:53 (file):
      file INSTALL cannot copy file
      "/tmp/pip-install-25unylyx/buffalo/build/lib.linux-x86_64-3.6/libcbuffalo.so.0.1.0"
      to "/usr/local/lib/libcbuffalo.so.0.1.0".
    
    
    Makefile:117: recipe for target 'install' failed
    make: *** [install] Error 1
    error: command 'cmake' failed with exit status 2

음... 권한 문제 같아서 sudo pip install buffalo를 했고, pip가 python2로 인식돼서 sudo pip3 install buffalo를 하고, 혹시 몰라서 버전까지 붙여서 최종적으로

sudo pip3 install buffalo==1.0.6 가 됐다.

그런데 에러는 조금씩만 달라질 뿐 계속 생겼다.

(sudo를 붙이는 순간, numpy, n2, cython을 다시 설치해야 한다. 가상환경이 아니니까...)

 

 

    cmake --build . --target install
    Scanning dependencies of target cbuffalo
    [ 50%] Building CXX object CMakeFiles/cbuffalo.dir/3rd/json11/json11.cpp.o
    [100%] Linking CXX shared library ../lib.linux-x86_64-3.6/libcbuffalo.so
    [100%] Built target cbuffalo
    Install the project...
    -- Install configuration: "Release"
    -- Installing: /usr/local/lib/libcbuffalo.so.0.1.0
    -- Up-to-date: /usr/local/lib/libcbuffalo.so.1
    -- Up-to-date: /usr/local/lib/libcbuffalo.so
    building 'cbuffalo' extension
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -o build/lib.linux-x86_64-3.6/cbuffalo.cpython-36m-x86_64-linux-gnu.so
    building 'buffalo.algo._als' extension
    creating build/temp.linux-x86_64-3.6/buffalo
    creating build/temp.linux-x86_64-3.6/buffalo/algo
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I./include -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I3rd/json11 -I3rd/spdlog/include -I3rd/eigen3 -I/usr/include/python3.6m -c buffalo/algo/_als.cpp -o build/temp.linux-x86_64-3.6/buffalo/algo/_als.o -fopenmp -std=c++14 -ggdb -O3 -march=native
    In file included from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
                     from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                     from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
                     from buffalo/algo/_als.cpp:633:
    /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
     #warning "Using deprecated NumPy API, disable it with " \
      ^~~~~~~
    buffalo/algo/_als.cpp:635:10: fatal error: buffalo/algo_impl/als/als.hpp: 그런 파일이나 디렉터리가 없습니다
     #include "buffalo/algo_impl/als/als.hpp"
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

 

어쩔 수 없이 만드신 분한테 메시지를 보내서 왜 그런지 아시냐고 여쭤봤다... ㅎ...

 

---------------------------------------------

 

확인해보시고 1.0.7 버전으로 설치하라고 말씀해주셨다.

 

sudo pip3 install buffalo==1.0.7

 

됐다 ㅎㅎ

 

설치 완료.

 

import buffalo

제대로 되는지 파이썬에서 버팔로를 한 번 import 해보자.

>>> import buffalo

ModuleNotFoundError: No module named 'buffalo'

아... 뭐지?

 

버팔로가 설치된 경로를 찾아보니 /usr/local/lib/python3.6/dist-packages 안에 있다.

sudo를 사용해서 설치했기에 가상환경 안에는 설치되지 않았다.

 

import를 하기 위해서는 sys.path에 해당 경로가 지정되어 있어야 한다.

>>> import sys
>>> sys.path

['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/.../myvenv/lib/python3.6/site-packages']

>>> sys.path.insert(4, '/usr/local/lib/python3.6/dist-packages')
>>> sys.path

['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/home/.../myvenv/lib/python3.6/site-packages']

>>> import buffalo

>>> (no error)

4번째 위치에 넣은 이유는, 가상환경보다는 앞서 있어야 할 것 같아서 그랬다.

dist-packages에 모든 것을 가져와야 하나, 그냥 특정하게 buffalo를 지정해줄까, 고민했지만 일단 그냥 다 넣어놨다.

 

자 이제 제대로 설치가 됐다.

다음에는 실제로 사용해보자.

댓글