lucataco / cog-faceswap

Cog wrapper for faceswap with face enhancer
https://replicate.com/lucataco/faceswap
13 stars 7 forks source link

Error during build #1

Closed DanielZanchi closed 1 year ago

DanielZanchi commented 1 year ago

I'm on a MBP with M1 and during the command: cog build -t faceswap i got this error:

`[+] Building 570.8s (12/22)                                                                                                                                                                                                                                                                                                                                                                                                              
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                                                                                                0.0s
 => => transferring dockerfile: 2.28kB                                                                                                                                                                                                                                                                                                                                                                                              0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4                                                                                                                                                                                                                                                                                                                                                                        2.1s
 => [auth] docker/dockerfile:pull token for registry-1.docker.io                                                                                                                                                                                                                                                                                                                                                                    0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc                                                                                                                                                                                                                                                                                                   0.0s
 => => resolve docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc                                                                                                                                                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                                                                                   0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04                                                                                                                                                                                                                                                                                                                                              1.6s
 => [auth] nvidia/cuda:pull token for registry-1.docker.io                                                                                                                                                                                                                                                                                                                                                                          0.0s
 => [stage-0  1/14] FROM docker.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04@sha256:b856c89aa26c1dc1b56c834a66b44c527a298325173c87291486fc100ceedb6e                                                                                                                                                                                                                                                                             87.7s
 => => resolve docker.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04@sha256:b856c89aa26c1dc1b56c834a66b44c527a298325173c87291486fc100ceedb6e                                                                                                                                                                                                                                                                                        0.0s
 => => sha256:8171a8ea64b561182474e012c3dc4b0754317d0b49cc2be793c5a6bca742f71e 1.47GB / 1.47GB                                                                                                                                                                                                                                                                                                                                     36.3s
 => => sha256:e5f5c15a666415cd3010024e939e14c0051fbebedf71e5c10e2a95f6496e1c02 88.21kB / 88.21kB                                                                                                                                                                                                                                                                                                                                    0.8s
 => => sha256:e1bab5cae66b430aacd675a54b6c1d91dfb17aeb41306419ca976f7f2bbaa6e8 2.46GB / 2.46GB                                                                                                                                                                                                                                                                                                                                     54.7s
 => => extracting sha256:e1bab5cae66b430aacd675a54b6c1d91dfb17aeb41306419ca976f7f2bbaa6e8                                                                                                                                                                                                                                                                                                                                          20.4s
 => => extracting sha256:e5f5c15a666415cd3010024e939e14c0051fbebedf71e5c10e2a95f6496e1c02                                                                                                                                                                                                                                                                                                                                           0.0s
 => => extracting sha256:8171a8ea64b561182474e012c3dc4b0754317d0b49cc2be793c5a6bca742f71e                                                                                                                                                                                                                                                                                                                                          12.5s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                                                                                                   0.0s
 => => transferring context: 1.64MB                                                                                                                                                                                                                                                                                                                                                                                                 0.0s
 => [stage-0  2/14] RUN --mount=type=cache,target=/var/cache/apt set -eux; apt-get update -qq; apt-get install -qqy --no-install-recommends curl; rm -rf /var/lib/apt/lists/*; TINI_VERSION=v0.19.0; TINI_ARCH="$(dpkg --print-architecture)"; curl -sSL -o /sbin/tini "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TINI_ARCH}"; chmod +x /sbin/tini                                                  26.6s
 => [stage-0  3/14] RUN --mount=type=cache,target=/var/cache/apt apt-get update -qq && apt-get install -qqy --no-install-recommends  make  build-essential  libssl-dev  zlib1g-dev  libbz2-dev  libreadline-dev  libsqlite3-dev  wget  curl  llvm  libncurses5-dev  libncursesw5-dev  xz-utils  tk-dev  libffi-dev  liblzma-dev  git  ca-certificates  && rm -rf /var/lib/apt/lists/*                                              51.1s 
 => ERROR [stage-0  4/14] RUN curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash &&  git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest &&  pyenv install-latest "3.8" &&  pyenv global $(pyenv install-latest --print "3.8") &&  pip install "wheel<1"                                                             401.2s 
------                                                                                                                                                                                                                                                                                                                                                                                                                                   
 > [stage-0  4/14] RUN curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash &&       git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest &&  pyenv install-latest "3.8" &&   pyenv global $(pyenv install-latest --print "3.8") &&   pip install "wheel<1":                                                                   
#0 0.905 Cloning into '/root/.pyenv'...                                                                                                                                                                                                                                                                                                                                                                                                  
#0 2.477 Cloning into '/root/.pyenv/plugins/pyenv-doctor'...                                                                                                                                                                                                                                                                                                                                                                             
#0 4.105 Cloning into '/root/.pyenv/plugins/pyenv-update'...                                                                                                                                                                                                                                                                                                                                                                             
#0 5.448 Cloning into '/root/.pyenv/plugins/pyenv-virtualenv'...                                                                                                                                                                                                                                                                                                                                                                         
#0 7.042 Cloning into '/root/.pyenv/plugins/pyenv-install-latest'...
#0 9.095 Install 3.8.18...
#0 11.10 Downloading Python-3.8.18.tar.xz...
#0 11.10 -> https://www.python.org/ftp/python/3.8.18/Python-3.8.18.tar.xz
#0 16.89 Installing Python-3.8.18...
#0 400.9 
#0 400.9 BUILD FAILED (Ubuntu 22.04 using python-build 2.3.31)
#0 401.0 
#0 401.0 Inspect or clean up the working tree at /tmp/python-build.20231030094126.452
#0 401.0 Results logged to /tmp/python-build.20231030094126.452.log
#0 401.0 
#0 401.0 Last 10 log lines:
#0 401.1  6184 |     if (register_at_forker(&interp->after_forkers_parent, after_in_parent)) {
#0 401.1       |                                   ^~
#0 401.1 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DOPENSSL_NO_SSL3   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include -I/root/.pyenv/versions/3.8.18/include -I/root/.pyenv/versions/3.8.18/include -fPIC -DPy_BUILD_CORE_BUILTIN  -c ./Modules/pwdmodule.c -o Modules/pwdmodule.o
#0 401.1 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DOPENSSL_NO_SSL3   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include -I/root/.pyenv/versions/3.8.18/include -I/root/.pyenv/versions/3.8.18/include -fPIC -DPy_BUILD_CORE_BUILTIN  -c ./Modules/_sre.c -o Modules/_sre.o
#0 401.1 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DOPENSSL_NO_SSL3   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include -I/root/.pyenv/versions/3.8.18/include -I/root/.pyenv/versions/3.8.18/include -fPIC -DPy_BUILD_CORE_BUILTIN  -c ./Modules/_codecsmodule.c -o Modules/_codecsmodule.o
#0 401.1 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DOPENSSL_NO_SSL3   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include -I/root/.pyenv/versions/3.8.18/include -I/root/.pyenv/versions/3.8.18/include -fPIC -DPy_BUILD_CORE_BUILTIN  -c ./Modules/_weakref.c -o Modules/_weakref.o
#0 401.1 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DOPENSSL_NO_SSL3   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include -I/root/.pyenv/versions/3.8.18/include -I/root/.pyenv/versions/3.8.18/include -fPIC -DPy_BUILD_CORE_BUILTIN  -DPy_BUILD_CORE_BUILTIN -I./Include/internal -c ./Modules/_functoolsmodule.c -o Modules/_functoolsmodule.o
#0 401.1 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DOPENSSL_NO_SSL3   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include -I/root/.pyenv/versions/3.8.18/include -I/root/.pyenv/versions/3.8.18/include -fPIC -DPy_BUILD_CORE_BUILTIN  -c ./Modules/_operator.c -o Modules/_operator.o
#0 401.1 make: *** [Makefile:1902: Modules/posixmodule.o] Error 1
#0 401.1 make: *** Waiting for unfinished jobs....
------
Dockerfile:36
--------------------
  35 |      && rm -rf /var/lib/apt/lists/*
  36 | >>> RUN curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash && \
  37 | >>>  git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest && \
  38 | >>>  pyenv install-latest "3.8" && \
  39 | >>>  pyenv global $(pyenv install-latest --print "3.8") && \
  40 | >>>  pip install "wheel<1"
  41 |     COPY .cog/tmp/build1555178518/cog-0.0.1.dev-py3-none-any.whl /tmp/cog-0.0.1.dev-py3-none-any.whl
--------------------
ERROR: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash && \tgit clone https://github.com/momo-lab/pyenv-install-latest.git \"$(pyenv root)\"/plugins/pyenv-install-latest && \tpyenv install-latest \"3.8\" && \tpyenv global $(pyenv install-latest --print \"3.8\") && \tpip install \"wheel<1\"" did not complete successfully: exit code: 1
ⅹ Failed to build Docker image: exit status 1`
lucataco commented 1 year ago

For Apple silicon you need to run the following before building cog: export DOCKER_DEFAULT_PLATFORM=linux/amd64

DanielZanchi commented 1 year ago

Thanks for the reply. Getting this now:

cog-faceswap-main % cog predict -i target_image=@tony.jpg -i swap_image=@elon.jpg

Building Docker image from environment in cog.yaml...
[+] Building 1.8s (21/21) FINISHED                                                                                                                                                                                                                                                                                                                                     docker:desktop-linux
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                                                                                        0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 2.27kB                                                                                                                                                                                                                                                                                                                                                 0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4                                                                                                                                                                                                                                                                                                                           0.9s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc                                                                                                                                                                                                                                                      0.0s
 => [internal] load metadata for docker.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04                                                                                                                                                                                                                                                                                                 0.7s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                                                      0.0s
 => => transferring context: 83.78kB                                                                                                                                                                                                                                                                                                                                                   0.0s
 => [stage-0  1/13] FROM docker.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04@sha256:b856c89aa26c1dc1b56c834a66b44c527a298325173c87291486fc100ceedb6e                                                                                                                                                                                                                                 0.0s
 => CACHED [stage-0  2/13] RUN --mount=type=cache,target=/var/cache/apt set -eux; apt-get update -qq; apt-get install -qqy --no-install-recommends curl; rm -rf /var/lib/apt/lists/*; TINI_VERSION=v0.19.0; TINI_ARCH="$(dpkg --print-architecture)"; curl -sSL -o /sbin/tini "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TINI_ARCH}"; chmod +x /sbin/t  0.0s
 => CACHED [stage-0  3/13] RUN --mount=type=cache,target=/var/cache/apt apt-get update -qq && apt-get install -qqy --no-install-recommends  make  build-essential  libssl-dev  zlib1g-dev  libbz2-dev  libreadline-dev  libsqlite3-dev  wget  curl  llvm  libncurses5-dev  libncursesw5-dev  xz-utils  tk-dev  libffi-dev  liblzma-dev  git  ca-certificates  && rm -rf /var/lib/apt/  0.0s
 => CACHED [stage-0  4/13] RUN curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash &&  git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest &&  pyenv install-latest "3.8" &&  pyenv global $(pyenv install-latest --print "3.8") &&  pip install "wheel<1"                 0.0s
 => CACHED [stage-0  5/13] COPY .cog/tmp/build3659661191/cog-0.0.1.dev-py3-none-any.whl /tmp/cog-0.0.1.dev-py3-none-any.whl                                                                                                                                                                                                                                                            0.0s
 => CACHED [stage-0  6/13] RUN --mount=type=cache,target=/root/.cache/pip pip install /tmp/cog-0.0.1.dev-py3-none-any.whl                                                                                                                                                                                                                                                              0.0s
 => CACHED [stage-0  7/13] RUN --mount=type=cache,target=/var/cache/apt apt-get update -qq && apt-get install -qqy cmake zip ffmpeg libsm6 libxext6 && rm -rf /var/lib/apt/lists/*                                                                                                                                                                                                     0.0s
 => CACHED [stage-0  8/13] COPY .cog/tmp/build3659661191/requirements.txt /tmp/requirements.txt                                                                                                                                                                                                                                                                                        0.0s
 => CACHED [stage-0  9/13] RUN --mount=type=cache,target=/root/.cache/pip pip install -r /tmp/requirements.txt                                                                                                                                                                                                                                                                         0.0s
 => CACHED [stage-0 10/13] RUN mkdir -p /root/.insightface/models/buffalo_l/                                                                                                                                                                                                                                                                                                           0.0s
 => CACHED [stage-0 11/13] RUN wget https://github.com/deepinsight/insightface/releases/download/v0.7/buffalo_l.zip                                                                                                                                                                                                                                                                    0.0s
 => CACHED [stage-0 12/13] RUN unzip buffalo_l.zip -d /root/.insightface/models/buffalo_l                                                                                                                                                                                                                                                                                              0.0s
 => CACHED [stage-0 13/13] WORKDIR /src                                                                                                                                                                                                                                                                                                                                                0.0s
 => preparing layers for inline cache                                                                                                                                                                                                                                                                                                                                                  0.0s
 => exporting to image                                                                                                                                                                                                                                                                                                                                                                 0.0s
 => => exporting layers                                                                                                                                                                                                                                                                                                                                                                0.0s
 => => writing image sha256:975818db4d49f01673563519c9f1084272ebb7915e9f8823830c91e2476dc841                                                                                                                                                                                                                                                                                           0.0s
 => => naming to docker.io/library/cog-faceswap-main-base                                                                                                                                                                                                                                                                                                                              0.0s

Starting Docker image cog-faceswap-main-base and running setup()...
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
Missing device driver, re-trying without GPU
Error response from daemon: page not found
/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/torchvision/transforms/functional_tensor.py:5: UserWarning: The torchvision.transforms.functional_tensor module is deprecated in 0.15 and will be **removed in 0.17**. Please don't rely on it. You probably just need to use APIs in torchvision.transforms.functional or in torchvision.transforms.v2.functional.
  warnings.warn(
/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/torchvision/transforms/functional_tensor.py:5: UserWarning: The torchvision.transforms.functional_tensor module is deprecated in 0.15 and will be **removed in 0.17**. Please don't rely on it. You probably just need to use APIs in torchvision.transforms.functional or in torchvision.transforms.v2.functional.
warnings.warn(
2023-10-31 08:52:48.610726679 [W:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing initializer 'buff2fs'. It is not used by any node and should be removed from the model.
2023-10-31 08:52:50.714907597 [W:onnxruntime:, graph.cc:3553 CleanUnusedInitializersAndNodeArgs] Removing initializer 'buff2fs'. It is not used by any node and should be removed from the model.
EP Error /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1193 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_tensorrt.so with error: libnvinfer.so.8: cannot open shared object file: No such file or directory
when using ['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'AzureExecutionProvider', 'CPUExecutionProvider']
Falling back to ['CUDAExecutionProvider', 'CPUExecutionProvider'] and retrying.
Traceback (most recent call last):
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in __init__
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 463, in _create_inference_session
sess.initialize_session(providers, provider_options, disabled_optimizers)
RuntimeError: /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1193 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_tensorrt.so with error: libnvinfer.so.8: cannot open shared object file: No such file or directory
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/cog/server/worker.py", line 185, in _setup
run_setup(self._predictor)
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/cog/predictor.py", line 66, in run_setup
predictor.setup()
File "predict.py", line 16, in setup
self.face_swapper = insightface.model_zoo.get_model('cache/inswapper_128.onnx', providers=onnxruntime.get_available_providers())
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/insightface/model_zoo/model_zoo.py", line 96, in get_model
model = router.get_model(providers=providers, provider_options=provider_options)
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/insightface/model_zoo/model_zoo.py", line 40, in get_model
session = PickableInferenceSession(self.onnx_file, **kwargs)
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/insightface/model_zoo/model_zoo.py", line 25, in __init__
super().__init__(model_path, **kwargs)
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 430, in __init__
raise fallback_error from e
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 425, in __init__
self._create_inference_session(self._fallback_providers, None)
File "/root/.pyenv/versions/3.8.18/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 463, in _create_inference_session
sess.initialize_session(providers, provider_options, disabled_optimizers)
RuntimeError: /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:121 std::conditional_t<THRW, void, onnxruntime::common::Status> onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*, const char*, int) [with ERRTYPE = cudaError; bool THRW = true; std::conditional_t<THRW, void, onnxruntime::common::Status> = void] /onnxruntime_src/onnxruntime/core/providers/cuda/cuda_call.cc:114 std::conditional_t<THRW, void, onnxruntime::common::Status> onnxruntime::CudaCall(ERRTYPE, const char*, const char*, ERRTYPE, const char*, const char*, int) [with ERRTYPE = cudaError; bool THRW = true; std::conditional_t<THRW, void, onnxruntime::common::Status> = void] CUDA failure 35: CUDA driver version is insufficient for CUDA runtime version ; GPU=764642560 ; hostname=e56efa1b9238 ; file=/onnxruntime_src/onnxruntime/core/providers/cuda/cuda_execution_provider.cc ; line=236 ; expr=cudaSetDevice(info_.device_id);
ⅹ Model setup failed
lucataco commented 1 year ago

Ah, my assumption was that you just needed to build the cog model on your apple silicon mac to push to Replicate. Afaik you cant run this model locally as is, because apple silicon doesnt have an nvidia driver and the model is looking for CUDA. You might have to remove all instances of cuda and torch, but Im not sure.