sugarme/gotch

Cannot Run the Application using Libtorch 2.1 (CPU) Docker Image

MufidJamaluddin opened this issue · 0 comments

Dockerfile

# Build Stage
FROM golang:1.21 AS golang_img

FROM pytorch/libtorch-cxx11-builder:cpu-2.1 AS build

ENV TZ=Asia/Jakarta
ENV DEBIAN_FRONTEND noninteractive
RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone

RUN apt-get update && apt-get install -y sudo wget lsb-release software-properties-common gnupg

COPY --from=golang_img /usr/local/go/ /usr/local/go/
ENV PATH="/usr/local/go/bin:$PATH"

WORKDIR /temp

RUN wget https://apt.llvm.org/llvm.sh
RUN chmod u+x llvm.sh
RUN sudo ./llvm.sh 17

# No /usr/local/lib/libtorch, Need Reinstall

ENV CUDA_VER="cpu"
RUN wget https://github.com/sugarme/gotch/releases/download/v0.9.0/setup-libtorch.sh && \
    chmod +x setup-libtorch.sh && \
    ./setup-libtorch.sh

ENV CUDA_VER="cpu"
ENV GOTCH_VER="v0.9.1"
ENV GOTCH_LIBTORCH="/usr/local/lib/libtorch"
ENV LIBRARY_PATH="/opt/conda/lib:$GOTCH_LIBTORCH/lib:$LIBRARY_PATH"
ENV CPATH="/opt/conda/lib:/opt/conda/include:$GOTCH_LIBTORCH/lib:$GOTCH_LIBTORCH/include:$GOTCH_LIBTORCH/include/torch/csrc/api/include:$CPATH"
ENV LD_LIBRARY_PATH="/opt/conda/lib:$GOTCH_LIBTORCH/lib:$LD_LIBRARY_PATH"

RUN wget https://github.com/sugarme/gotch/releases/download/v0.9.0/setup-gotch.sh && \
    chmod +x setup-gotch.sh && \
    ./setup-gotch.sh

COPY . /app

WORKDIR /app

RUN echo "replace (\n\
	github.com/sugarme/gotch => /root/go/pkg/mod/github.com/sugarme/gotch@v0.9.1\n\
)" >> go.mod

RUN go mod tidy

RUN CGO_ENABLED=1 go build -o app


# Running Stage
FROM scratch

COPY --from=build /app/app /app
COPY /model /model

CMD ["/app"]

Error Message

#21 221.7 # sbert_text_sim
#21 221.7 /usr/local/go/pkg/tool/linux_amd64/link: running g++ failed: exit status 1
#21 221.7 /usr/bin/ld: warning: /opt/conda/lib/../lib/libstdc++.so: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0010001
#21 221.7 /usr/bin/ld: warning: /opt/conda/lib/../lib/libstdc++.so: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0010002
#21 221.7 /usr/bin/ld: cannot find -lcuda
#21 221.7 /usr/bin/ld: cannot find -lcudart
#21 221.7 /usr/bin/ld: cannot find -lcublas
#21 221.7 /usr/bin/ld: cannot find -lcudnn
#21 221.7 /usr/bin/ld: cannot find -lcaffe2_nvrtc
#21 221.7 /usr/bin/ld: cannot find -lnvrtc-builtins
#21 221.7 /usr/bin/ld: cannot find -lnvrtc
#21 221.7 /usr/bin/ld: cannot find -lnvToolsExt
#21 221.7 /usr/bin/ld: cannot find -lc10_cuda
#21 221.7 /usr/bin/ld: cannot find -ltorch_cuda
#21 221.7 collect2: error: ld returned 1 exit status
#21 221.7
#21 ERROR: process "/bin/sh -c CGO_ENABLED=1 go build -o app" did not complete successfully: exit code: 1
------
 > [build 15/15] RUN CGO_ENABLED=1 go build -o app:
221.7 /usr/bin/ld: cannot find -lcublas
221.7 /usr/bin/ld: cannot find -lcudnn
221.7 /usr/bin/ld: cannot find -lcaffe2_nvrtc
221.7 /usr/bin/ld: cannot find -lnvrtc-builtins
221.7 /usr/bin/ld: cannot find -lnvrtc
221.7 /usr/bin/ld: cannot find -lnvToolsExt
221.7 /usr/bin/ld: cannot find -lc10_cuda
221.7 /usr/bin/ld: cannot find -ltorch_cuda
221.7 collect2: error: ld returned 1 exit status
221.7
------
Dockerfile:49
--------------------
  47 |     RUN go mod tidy
  48 |
  49 | >>> RUN CGO_ENABLED=1 go build -o app
  50 |
  51 |
--------------------
ERROR: failed to solve: process "/bin/sh -c CGO_ENABLED=1 go build -o app" did not complete successfully: exit code: 1