필요한 프로그램
MSVC
![](http://ac.namu.la/20230322sac/a89240100a6f18951fd5eb98dacf6e81c6a6c923baef702bdcb5551b13496546.png?expires=1718957906&key=WmmYh3XsJ8l8q-NFH9uZRg)
스탠드얼론 깔려있으면 비주얼 스튜디오까지 설치할 필요 없음
난 Visual Studio Community 2022 사용 중임
Desktop development with C++
- MSVC v1xx (가장 최신 버전 받으면 됨)
- C++ CMake tools for Windows (마찬가지로 이미 있으면 체크 해제해도 됨)
nvcc
https://developer.nvidia.com/cuda-toolkit-archive
https://developer.nvidia.com/cuda-11-8-0-download-archive
12.x 으로 컴파일해도 문제는 없지만 미리 컴파일된 PyTorch 2.0 은 CUDA 11.8 까지만 지원해서 1.18 사용을 추천 함
컴파일에 필요한 파일만 설치할꺼라 전부 받을 필요 없으니 마지막 선택지에서 'exe (network)' 선택하고 설치 파일 받으면 됨
'Custom (Advanced)' 체크하고 아래 항목만 선택하고 설치하자
- CUDA > Development > Compiler
- CUDA > Runtime > Libraries
- CUDA > Runtime > Visual Studio Integration
Python 3.10.x
https://www.python.org/ftp/python/3.10.10/python-3.10.10-amd64.exe
Git for Windows
https://github.com/git-for-windows/git/releases/latest
작업 환경 만들기
명령 프롬프트 열기
MSVC 와 nvcc 사용을 위해 환경 변수가 모두 잡혀있는 명령 프롬프트를 열 필요가 있음
윈도우 + R 눌러서 실행 창 열고 아래 그대로 입력한 뒤 확인하면 검은 창이 나오는데
앞으로 모든 명령어는 이 검은 창에 입력하도록 하자
%comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
mkdir %USERPROFILE%\workspace
mv %USERPROFILE%\workspace
레포지토리 클론하기
git clone --depth=1 https://github.com/TimDettmers/bitsandbytes.git
mkdir dependencies
git clone --depth=1 https://github.com/GerHobbelt/pthread-win32.git dependencies/pthread-win32
CMake 관련 파일 받아오기
레포지토리 최상위 경로에 넣어야 할 파일:
https://raw.githubusercontent.com/centerionware/bitsandbytes/windows_cmake/CMakeLists.txt
csrc/ 경로에 넣어야 할 파일:
https://raw.githubusercontent.com/centerionware/bitsandbytes/windows_cmake/csrc/CMakeLists.txt
https://raw.githubusercontent.com/centerionware/bitsandbytes/windows_cmake/csrc/pythonInterface.cpp
csrc/CMakeLists.txt 파일에 오타(?) 있어서 수정해줘야함
-O 3 로 적혀있는 부분이 두 곳 있을텐데 -O3 처럼 공백 지우고 붙인 뒤에 저장하면 해결됨
윈도우 호환을 위한 코드 수정하기
csrc/kernels.cu
csrc/ops.cu
자료형 문자열 모두 치환하기
찾을 문자열: float *dequant_stats
치환 문자열: float * __restrict__ const dequant_stats
csrc/ops.cuh
12번 줄을 #ifndef 문으로 감싸기
#ifndef _MSC_VER
#include <unistd.h>
#endif
includes/SIMD.h
50번 줄 뒤에 아래 template 추가하기
template <InstrSet I, class T>
struct InstrFloatTraits
{
typedef T vec_t;
};
컴파일하기
pthread-win32 컴파일하기
cd dependencies\pthread-win32
mkdir build
cd build
cmake ..
rem 명령어 인자 중 -j 뒤에 숫자는 컴파일에 사용할 CPU 코어 수로
rem 사용 중인 CPU 코어 수에 맞게 끔 수정하면 컴파일 시간이 줄어드니 참고
cmake --build ./ --clean-first -j4 --config Release
cd ..\..\
bitsandbytes 컴파일하기
mkdir build
cd build
rem 컴퓨터에 여러 버전의 CUDA 가 설치되어있다면 여기서 설정할 수 있음
rem 한 버전만 있다면 -T 뒤는 전부 지우고 실행해도 됨
cmake .. -T cuda=11.8
rem 명령어 인자 중 -j 뒤에 숫자는 컴파일에 사용할 CPU 코어 수로
rem 사용 중인 CPU 코어 수에 맞게 끔 수정하면 컴파일 시간이 줄어드니 참고
cmake --build ./ --clean-first -j4 --config Release
cd ..\..\
컴파일된 DLL 파일 옮기기
정상적으로 컴파일 됐다면 build/csrc/Release 폴더에 bitsandbytes.dll 파일이 생성 됐을거임
---
출처: https://arca.live/b/characterai/71548977?category=%EC%A0%95%EB%B3%B4&p=3