Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
5576bb23
Unverified
Commit
5576bb23
authored
Jan 21, 2024
by
Daniel Hiltgen
Committed by
GitHub
Jan 21, 2024
Browse files
Merge pull request #2130 from dhiltgen/more_faster
Make CPU builds parallel and customizable AMD GPUs
parents
27388377
df54c723
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
44 deletions
+68
-44
Dockerfile
Dockerfile
+26
-15
docs/development.md
docs/development.md
+2
-1
llm/generate/gen_linux.sh
llm/generate/gen_linux.sh
+38
-28
scripts/build_linux.sh
scripts/build_linux.sh
+2
-0
No files found.
Dockerfile
View file @
5576bb23
...
@@ -10,91 +10,102 @@ COPY llm llm
...
@@ -10,91 +10,102 @@ COPY llm llm
FROM
--platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64
FROM
--platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
ARG
CGO_CFLAGS
COPY
./scripts/rh_linux_deps.sh /
COPY
./scripts/rh_linux_deps.sh /
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
ARG
CGO_CFLAGS
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
FROM
--platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
FROM
--platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
ARG
CGO_CFLAGS
COPY
./scripts/rh_linux_deps.sh /
COPY
./scripts/rh_linux_deps.sh /
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
ENV
PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
ENV
PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
ARG
CGO_CFLAGS
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
FROM
--platform=linux/amd64 rocm/dev-centos-7:5.7.1-complete AS rocm-5-build-amd64
FROM
--platform=linux/amd64 rocm/dev-centos-7:5.7.1-complete AS rocm-5-build-amd64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
ARG
CGO_CFLAGS
COPY
./scripts/rh_linux_deps.sh /
COPY
./scripts/rh_linux_deps.sh /
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV
LIBRARY_PATH /opt/amdgpu/lib64
ENV
LIBRARY_PATH /opt/amdgpu/lib64
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
ARG
CGO_CFLAGS
ARG
AMDGPU_TARGETS
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
FROM
--platform=linux/amd64 rocm/dev-centos-7:6.0-complete AS rocm-6-build-amd64
FROM
--platform=linux/amd64 rocm/dev-centos-7:6.0-complete AS rocm-6-build-amd64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
ARG
CGO_CFLAGS
COPY
./scripts/rh_linux_deps.sh /
COPY
./scripts/rh_linux_deps.sh /
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
sh /rh_linux_deps.sh
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV
LIBRARY_PATH /opt/amdgpu/lib64
ENV
LIBRARY_PATH /opt/amdgpu/lib64
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
ARG
CGO_CFLAGS
ARG
AMDGPU_TARGETS
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
RUN
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
FROM
--platform=linux/amd64 centos:7 AS cpu-build-amd64
FROM
--platform=linux/amd64 centos:7 AS cpu-build
er
-amd64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
ARG
GOLANG_VERSION
ARG
GOLANG_VERSION
ARG
OLLAMA_CUSTOM_CPU_DEFS
ARG
CGO_CFLAGS
COPY
./scripts/rh_linux_deps.sh /
COPY
./scripts/rh_linux_deps.sh /
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
GOLANG_VERSION
=
${
GOLANG_VERSION
}
sh /rh_linux_deps.sh
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
GOLANG_VERSION
=
${
GOLANG_VERSION
}
sh /rh_linux_deps.sh
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
ARG
OLLAMA_CUSTOM_CPU_DEFS
ARG
CGO_CFLAGS
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
RUN
sh gen_linux.sh
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
RUN
OLLAMA_CPU_TARGET
=
"cpu"
sh gen_linux.sh
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
RUN
OLLAMA_CPU_TARGET
=
"cpu_avx"
sh gen_linux.sh
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
RUN
OLLAMA_CPU_TARGET
=
"cpu_avx2"
sh gen_linux.sh
FROM
--platform=linux/arm64 centos:7 AS cpu-build-arm64
FROM
--platform=linux/arm64 centos:7 AS cpu-build-arm64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
ARG
GOLANG_VERSION
ARG
GOLANG_VERSION
ARG
OLLAMA_CUSTOM_CPU_DEFS
ARG
CGO_CFLAGS
COPY
./scripts/rh_linux_deps.sh /
COPY
./scripts/rh_linux_deps.sh /
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
GOLANG_VERSION
=
${
GOLANG_VERSION
}
sh /rh_linux_deps.sh
RUN
CMAKE_VERSION
=
${
CMAKE_VERSION
}
GOLANG_VERSION
=
${
GOLANG_VERSION
}
sh /rh_linux_deps.sh
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV
PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
COPY
--from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
WORKDIR
/go/src/github.com/jmorganca/ollama/llm/generate
RUN
sh gen_linux.sh
# Note, we only build the "base" CPU variant on arm since avx/avx2 are x86 features
ARG
OLLAMA_CUSTOM_CPU_DEFS
ARG
CGO_CFLAGS
RUN
OLLAMA_CPU_TARGET
=
"cpu"
sh gen_linux.sh
# Intermediate stage used for ./scripts/build_linux.sh
# Intermediate stage used for ./scripts/build_linux.sh
FROM
--platform=linux/amd64 cpu-build-amd64 AS build-amd64
FROM
--platform=linux/amd64 cpu-build-amd64 AS build-amd64
ENV
CGO_ENABLED 1
ENV
CGO_ENABLED 1
ARG
GOFLAGS
ARG
CGO_CFLAGS
WORKDIR
/go/src/github.com/jmorganca/ollama
WORKDIR
/go/src/github.com/jmorganca/ollama
COPY
. .
COPY
. .
COPY
--from=cpu_avx-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=cpu_avx2-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=cuda-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=cuda-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=rocm-5-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=rocm-5-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=rocm-6-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=rocm-6-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
ARG
GOFLAGS
ARG
CGO_CFLAGS
RUN
go build .
RUN
go build .
# Intermediate stage used for ./scripts/build_linux.sh
# Intermediate stage used for ./scripts/build_linux.sh
FROM
--platform=linux/arm64 cpu-build-arm64 AS build-arm64
FROM
--platform=linux/arm64 cpu-build-arm64 AS build-arm64
ENV
CGO_ENABLED 1
ENV
CGO_ENABLED 1
ARG
GOLANG_VERSION
ARG
GOLANG_VERSION
ARG
GOFLAGS
ARG
CGO_CFLAGS
WORKDIR
/go/src/github.com/jmorganca/ollama
WORKDIR
/go/src/github.com/jmorganca/ollama
COPY
. .
COPY
. .
COPY
--from=cuda-build-arm64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY
--from=cuda-build-arm64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
ARG
GOFLAGS
ARG
CGO_CFLAGS
RUN
go build .
RUN
go build .
# Runtime stages
# Runtime stages
...
...
docs/development.md
View file @
5576bb23
...
@@ -74,7 +74,8 @@ Typically the build scripts will auto-detect ROCm, however, if your Linux distro
...
@@ -74,7 +74,8 @@ Typically the build scripts will auto-detect ROCm, however, if your Linux distro
or installation approach uses unusual paths, you can specify the location by
or installation approach uses unusual paths, you can specify the location by
specifying an environment variable
`ROCM_PATH`
to the location of the ROCm
specifying an environment variable
`ROCM_PATH`
to the location of the ROCm
install (typically
`/opt/rocm`
), and
`CLBlast_DIR`
to the location of the
install (typically
`/opt/rocm`
), and
`CLBlast_DIR`
to the location of the
CLBlast install (typically
`/usr/lib/cmake/CLBlast`
).
CLBlast install (typically
`/usr/lib/cmake/CLBlast`
). You can also customize
the AMD GPU targets by setting AMDGPU_TARGETS (e.g.
`AMDGPU_TARGETS="gfx1101;gfx1102"`
)
```
```
go generate ./...
go generate ./...
...
...
llm/generate/gen_linux.sh
View file @
5576bb23
...
@@ -16,6 +16,10 @@ set -o pipefail
...
@@ -16,6 +16,10 @@ set -o pipefail
# See https://llvm.org/docs/AMDGPUUsage.html#processors for reference
# See https://llvm.org/docs/AMDGPUUsage.html#processors for reference
amdGPUs
()
{
amdGPUs
()
{
if
[
-n
"
${
AMDGPU_TARGETS
}
"
]
;
then
echo
"
${
AMDGPU_TARGETS
}
"
return
fi
GPU_LIST
=(
GPU_LIST
=(
"gfx803"
"gfx803"
"gfx900"
"gfx900"
...
@@ -73,6 +77,7 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
...
@@ -73,6 +77,7 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
# -DLLAMA_AVX512_VNNI -- 2021 Intel Alder Lake
# -DLLAMA_AVX512_VNNI -- 2021 Intel Alder Lake
COMMON_CPU_DEFS
=
"-DCMAKE_POSITION_INDEPENDENT_CODE=on -DLLAMA_NATIVE=off"
COMMON_CPU_DEFS
=
"-DCMAKE_POSITION_INDEPENDENT_CODE=on -DLLAMA_NATIVE=off"
if
[
-z
"
${
OLLAMA_CPU_TARGET
}
"
-o
"
${
OLLAMA_CPU_TARGET
}
"
=
"cpu"
]
;
then
#
#
# CPU first for the default library, set up as lowest common denominator for maximum compatibility (including Rosetta)
# CPU first for the default library, set up as lowest common denominator for maximum compatibility (including Rosetta)
#
#
...
@@ -81,7 +86,9 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
...
@@ -81,7 +86,9 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
echo
"Building LCD CPU"
echo
"Building LCD CPU"
build
build
compress_libs
compress_libs
fi
if
[
-z
"
${
OLLAMA_CPU_TARGET
}
"
-o
"
${
OLLAMA_CPU_TARGET
}
"
=
"cpu_avx"
]
;
then
#
#
# ~2011 CPU Dynamic library with more capabilities turned on to optimize performance
# ~2011 CPU Dynamic library with more capabilities turned on to optimize performance
# Approximately 400% faster than LCD on same CPU
# Approximately 400% faster than LCD on same CPU
...
@@ -92,7 +99,9 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
...
@@ -92,7 +99,9 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
echo
"Building AVX CPU"
echo
"Building AVX CPU"
build
build
compress_libs
compress_libs
fi
if
[
-z
"
${
OLLAMA_CPU_TARGET
}
"
-o
"
${
OLLAMA_CPU_TARGET
}
"
=
"cpu_avx2"
]
;
then
#
#
# ~2013 CPU Dynamic library
# ~2013 CPU Dynamic library
# Approximately 10% faster than AVX on same CPU
# Approximately 10% faster than AVX on same CPU
...
@@ -104,6 +113,7 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
...
@@ -104,6 +113,7 @@ if [ -z "${OLLAMA_SKIP_CPU_GENERATE}" ]; then
build
build
compress_libs
compress_libs
fi
fi
fi
else
else
echo
"Skipping CPU generation step as requested"
echo
"Skipping CPU generation step as requested"
fi
fi
...
...
scripts/build_linux.sh
View file @
5576bb23
...
@@ -6,6 +6,7 @@ export VERSION=${VERSION:-0.0.0}
...
@@ -6,6 +6,7 @@ export VERSION=${VERSION:-0.0.0}
export
GOFLAGS
=
"'-ldflags=-w -s
\"
-X=github.com/jmorganca/ollama/version.Version=
$VERSION
\"
\"
-X=github.com/jmorganca/ollama/server.mode=release
\"
'"
export
GOFLAGS
=
"'-ldflags=-w -s
\"
-X=github.com/jmorganca/ollama/version.Version=
$VERSION
\"
\"
-X=github.com/jmorganca/ollama/server.mode=release
\"
'"
BUILD_ARCH
=
${
BUILD_ARCH
:-
"amd64 arm64"
}
BUILD_ARCH
=
${
BUILD_ARCH
:-
"amd64 arm64"
}
export
AMDGPU_TARGETS
=
${
AMDGPU_TARGETS
:
=
""
}
mkdir
-p
dist
mkdir
-p
dist
for
TARGETARCH
in
${
BUILD_ARCH
}
;
do
for
TARGETARCH
in
${
BUILD_ARCH
}
;
do
...
@@ -14,6 +15,7 @@ for TARGETARCH in ${BUILD_ARCH}; do
...
@@ -14,6 +15,7 @@ for TARGETARCH in ${BUILD_ARCH}; do
--build-arg
=
GOFLAGS
\
--build-arg
=
GOFLAGS
\
--build-arg
=
CGO_CFLAGS
\
--build-arg
=
CGO_CFLAGS
\
--build-arg
=
OLLAMA_CUSTOM_CPU_DEFS
\
--build-arg
=
OLLAMA_CUSTOM_CPU_DEFS
\
--build-arg
=
AMDGPU_TARGETS
\
--target
build-
$TARGETARCH
\
--target
build-
$TARGETARCH
\
-f
Dockerfile
\
-f
Dockerfile
\
-t
builder:
$TARGETARCH
\
-t
builder:
$TARGETARCH
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment