diff --git a/docs/compiling-wheels-for-comfy3d.adoc b/docs/compiling-wheels-for-comfy3d.adoc new file mode 100644 index 0000000..352d675 --- /dev/null +++ b/docs/compiling-wheels-for-comfy3d.adoc @@ -0,0 +1,213 @@ +# Compile Wheel Files for ComfyUI-3D-Pack on Windows + +This is an alternative to pre-built wheels from Comfy3D: + +https://github.com/MrForExample/Comfy3D_Pre_Builds + +I did this just for using the latest version of PyTorch with ComfyUI. + +The steps are basically ported from: + +* https://github.com/YanWenKun/ComfyUI-3D-Pack-LinuxWheels + +## How to install + +.Using CMD +[source,cmd] +---- +python_embeded\python.exe -s -m pip install ^ + https://github.com/YanWenKun/ComfyUI-Windows-Portable/releases/download/v5.3-wheels/pointnet2_ops-3.0.0-cp312-cp312-win_amd64.whl ^ + https://github.com/YanWenKun/ComfyUI-Windows-Portable/releases/download/v5.3-wheels/simple_knn-0.0.0-cp312-cp312-win_amd64.whl ^ + https://github.com/YanWenKun/ComfyUI-Windows-Portable/releases/download/v5.3-wheels/diff_gaussian_rasterization-0.0.0-cp312-cp312-win_amd64.whl ^ + https://github.com/YanWenKun/ComfyUI-Windows-Portable/releases/download/v5.3-wheels/kiui-0.2.14-py3-none-any.whl ^ + https://github.com/YanWenKun/ComfyUI-Windows-Portable/releases/download/v5.3-wheels/nvdiffrast-0.3.3-py3-none-any.whl ^ + https://github.com/YanWenKun/ComfyUI-Windows-Portable/releases/download/v5.3-wheels/torch_scatter-2.1.2-cp312-cp312-win_amd64.whl ^ + https://github.com/YanWenKun/ComfyUI-Windows-Portable/releases/download/v5.3-wheels/pytorch3d-0.7.8-cp312-cp312-win_amd64.whl +---- + + +## How to build the wheels + +### 0. You need + +* CUDA Toolkit installed +* VS 2022 with C++ Payload installed +* Git for Windows (with Git Bash) installed + +* This ComfyUI-Windows-Portable package, it includes building essentials: +** Ninja +** PyTorch +** Deps for Comfy3D (including `include` and `libs`) + +### 1. Preparation + +First, open Git Bash, `cd` to your ComfyUI_Windows_portable folder. + +#### 1.1 Set env vars + +[source,bash] +---- +workdir=$(pwd) + +alias pip_exe="$workdir/python_embeded/python.exe -s -m pip" + +export PATH="${PATH}:$workdir/python_embeded/Scripts" + +export PYTHONPYCACHEPREFIX="$workdir/pycache" + +mkdir -p "$workdir/tmp_wheels" + +wheeldir="$workdir/tmp_wheels" +---- + +#### 1.2 (Optional) Set proxy + +[source,bash] +---- +export HTTP_PROXY="http://localhost:1081" + +export HTTPS_PROXY="http://localhost:1081" + +export PIP_INDEX_URL="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple" +---- + +#### 1.3 (Optional) Add Ninja binary + +This step is already done if you're using this ComfyUI-Windows-Portable package. + +[source,bash] +---- +curl -L https://github.com/ninja-build/ninja/releases/latest/download/ninja-win.zip \ + -o ninja-win.zip +unzip -o ninja-win.zip -d "$workdir"/python_embeded/Scripts +rm ninja-win.zip +---- + +### 2. Set build args + +#### 2.1 Set CUDA build targets + +I used several build targets for compatibility. It should be running fine on from GTX 900(Maxwell), GTX 1000(Pascal) to RTX 4000(Ada) and later GPUs. +You can shorten the list to save build time. + +** See https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/[Arch List] + +[source,bash] +---- +export TORCH_CUDA_ARCH_LIST="5.2+PTX;6.0;6.1+PTX;7.5;8.0;8.6;8.9+PTX" +---- + +#### 2.2 (Optional) Set CMake args + +This was used by +https://github.com/MrForExample/ComfyUI-3D-Pack/blob/df3b12e3c4e329dc5a1a974412aa1ac118586ca9/_Pre_Builds/_Build_Scripts/auto_build_all.py#L46[Comfy3D's build script], +but not necessary here. + +[source,bash] +---- +export CMAKE_ARGS="-DBUILD_opencv_world=ON -DWITH_CUDA=ON -DCUDA_FAST_MATH=ON -DWITH_CUBLAS=ON -DWITH_NVCUVID=ON" +---- + +### 3. Compile + +#### 3.1 Download the source + +[source,bash] +---- +cd "$workdir" + +git clone --depth=1 --no-tags \ + https://github.com/MrForExample/Comfy3D_Pre_Builds.git + +cd Comfy3D_Pre_Builds/_Libs +---- + +#### 3.2 (Optional) Add `include` and `libs` for C++ + +This step is already done if you're using this ComfyUI-Windows-Portable package. + +[source,bash] +---- +mv \ + "$workdir"/Comfy3D_Pre_Builds/_Python_Source_cpp/py312/include \ + "$workdir"/python_embeded/include + +mv \ + "$workdir"/Comfy3D_Pre_Builds/_Python_Source_cpp/py312/libs \ + "$workdir"/python_embeded/libs +---- + +#### 3.3 Compile Part 1 + +These 4 wheels build fast, and are more likely to success. + +[source,bash] +---- +pip_exe wheel -w $wheeldir \ + ./pointnet2_ops + +pip_exe wheel -w $wheeldir \ + ./simple-knn + +pip_exe wheel -w $wheeldir \ + git+https://github.com/ashawkey/diff-gaussian-rasterization.git + +pip_exe wheel -w $wheeldir \ + git+https://github.com/ashawkey/kiuikit.git +---- + +#### 3.4 Compile nvdiffrast + +[source,bash] +---- +cd $workdir + +git clone --depth=1 https://github.com/NVlabs/nvdiffrast.git + +sed -i '1i../nvdiffrast' ./python_embeded/python312._pth + +cd nvdiffrast + +pip_exe wheel -w $wheeldir . +---- + + +#### 3.5 Compile pytorch_scatter + +`pytorch_scatter` takes more time to build. + +[source,bash] +---- +pip_exe wheel -w $wheeldir \ + git+https://github.com/rusty1s/pytorch_scatter.git +---- + +If failed to build latest `pytorch_scatter`, try its stable version: + +[source,bash] +---- +pip_exe wheel -w $wheeldir \ + torch-scatter +---- + + +#### 3.6 Compile pytorch3d + +`pytorch3d` takes even more time to build, and may throw errors. + +[source,bash] +---- +pip_exe wheel -w $wheeldir \ + git+https://github.com/facebookresearch/pytorch3d.git +---- + +If failed to build latest `pytorch3d`, try its stable version: + +[source,bash] +---- +pip_exe wheel -w $wheeldir \ + git+https://github.com/facebookresearch/pytorch3d.git@stable +---- + +### 4. Copy wheels + +Check the `tmp_wheels` folder under your `ComfyUI_Windows_portable`.