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
c7bcb003
Commit
c7bcb003
authored
Aug 09, 2024
by
Daniel Hiltgen
Browse files
Wire up ccache and pigz in the docker based build
This should help speed things up a little
parent
74d45f01
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
20 deletions
+53
-20
Dockerfile
Dockerfile
+26
-11
llm/generate/gen_common.sh
llm/generate/gen_common.sh
+9
-6
llm/generate/gen_darwin.sh
llm/generate/gen_darwin.sh
+2
-0
llm/generate/gen_linux.sh
llm/generate/gen_linux.sh
+2
-0
scripts/build_linux.sh
scripts/build_linux.sh
+2
-1
scripts/rh_linux_deps.sh
scripts/rh_linux_deps.sh
+12
-2
No files found.
Dockerfile
View file @
c7bcb003
...
@@ -19,7 +19,8 @@ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
...
@@ -19,7 +19,8 @@ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
ARG
CGO_CFLAGS
ARG
CGO_CFLAGS
ENV
GOARCH amd64
ENV
GOARCH amd64
RUN
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_SKIP_CPU_GENERATE
=
1 bash 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
...
@@ -30,7 +31,12 @@ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
...
@@ -30,7 +31,12 @@ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
ARG
CGO_CFLAGS
ARG
CGO_CFLAGS
ENV
GOARCH arm64
ENV
GOARCH arm64
RUN
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_SKIP_STATIC_GENERATE
=
1
\
OLLAMA_SKIP_CPU_GENERATE
=
1
\
CMAKE_CUDA_ARCHITECTURES
=
"
${
CUDA_V11_ARCHITECTURES
}
"
\
CUDA_VARIANT
=
"_v11"
\
bash gen_linux.sh
FROM
--platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
FROM
--platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
...
@@ -43,7 +49,8 @@ WORKDIR /go/src/github.com/ollama/ollama/llm/generate
...
@@ -43,7 +49,8 @@ WORKDIR /go/src/github.com/ollama/ollama/llm/generate
ARG
CGO_CFLAGS
ARG
CGO_CFLAGS
ARG
AMDGPU_TARGETS
ARG
AMDGPU_TARGETS
ENV
GOARCH amd64
ENV
GOARCH amd64
RUN
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_SKIP_CPU_GENERATE
=
1 sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_SKIP_CPU_GENERATE
=
1 bash gen_linux.sh
RUN
mkdir
-p
../../dist/linux-amd64/ollama_libs
&&
\
RUN
mkdir
-p
../../dist/linux-amd64/ollama_libs
&&
\
(
cd
/opt/rocm/lib
&&
tar
cf - rocblas/library
)
|
(
cd
../../dist/linux-amd64/ollama_libs
&&
tar
xf -
)
(
cd
/opt/rocm/lib
&&
tar
cf - rocblas/library
)
|
(
cd
../../dist/linux-amd64/ollama_libs
&&
tar
xf -
)
...
@@ -60,13 +67,17 @@ ENV GOARCH amd64
...
@@ -60,13 +67,17 @@ ENV GOARCH amd64
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
FROM
--platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
FROM
--platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
RUN
OLLAMA_CPU_TARGET
=
"static"
sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_CPU_TARGET
=
"static"
bash gen_linux.sh
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
RUN
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu"
sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu"
bash gen_linux.sh
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
RUN
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu_avx"
sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu_avx"
bash gen_linux.sh
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
FROM
--platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
RUN
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu_avx2"
sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu_avx2"
bash gen_linux.sh
FROM
--platform=linux/arm64 rockylinux:8 AS cpu-builder-arm64
FROM
--platform=linux/arm64 rockylinux:8 AS cpu-builder-arm64
ARG
CMAKE_VERSION
ARG
CMAKE_VERSION
...
@@ -81,9 +92,11 @@ ENV GOARCH arm64
...
@@ -81,9 +92,11 @@ ENV GOARCH arm64
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
WORKDIR
/go/src/github.com/ollama/ollama/llm/generate
FROM
--platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
FROM
--platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
RUN
OLLAMA_CPU_TARGET
=
"static"
sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_CPU_TARGET
=
"static"
bash gen_linux.sh
FROM
--platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
FROM
--platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
RUN
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu"
sh gen_linux.sh
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
OLLAMA_SKIP_STATIC_GENERATE
=
1
OLLAMA_CPU_TARGET
=
"cpu"
bash gen_linux.sh
# Intermediate stage used for ./scripts/build_linux.sh
# Intermediate stage used for ./scripts/build_linux.sh
...
@@ -100,7 +113,8 @@ COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
...
@@ -100,7 +113,8 @@ COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
COPY
--from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
COPY
--from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
ARG
GOFLAGS
ARG
GOFLAGS
ARG
CGO_CFLAGS
ARG
CGO_CFLAGS
RUN
go build
-trimpath
-o
dist/linux-amd64/ollama .
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
go build
-trimpath
-o
dist/linux-amd64/ollama .
# 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
...
@@ -113,7 +127,8 @@ COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/dist/ dist/
...
@@ -113,7 +127,8 @@ COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/dist/ dist/
COPY
--from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
COPY
--from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
ARG
GOFLAGS
ARG
GOFLAGS
ARG
CGO_CFLAGS
ARG
CGO_CFLAGS
RUN
go build
-trimpath
-o
dist/linux-arm64/ollama .
RUN
--mount
=
type
=
cache,target
=
/root/.ccache
\
go build
-trimpath
-o
dist/linux-arm64/ollama .
# Runtime stages
# Runtime stages
FROM
--platform=linux/amd64 ubuntu:22.04 as runtime-amd64
FROM
--platform=linux/amd64 ubuntu:22.04 as runtime-amd64
...
...
llm/generate/gen_common.sh
View file @
c7bcb003
...
@@ -47,6 +47,7 @@ init_vars() {
...
@@ -47,6 +47,7 @@ init_vars() {
if
[
-z
"
${
CMAKE_CUDA_ARCHITECTURES
}
"
]
;
then
if
[
-z
"
${
CMAKE_CUDA_ARCHITECTURES
}
"
]
;
then
CMAKE_CUDA_ARCHITECTURES
=
"50;52;61;70;75;80"
CMAKE_CUDA_ARCHITECTURES
=
"50;52;61;70;75;80"
fi
fi
GZIP
=
$(
which pigz 2>/dev/null
||
echo
"gzip"
)
}
}
git_module_setup
()
{
git_module_setup
()
{
...
@@ -90,21 +91,23 @@ build() {
...
@@ -90,21 +91,23 @@ build() {
compress
()
{
compress
()
{
echo
"Compressing payloads to reduce overall binary size..."
echo
"Compressing payloads to reduce overall binary size..."
pids
=
""
rm
-rf
${
BUILD_DIR
}
/bin/
*
.gz
rm
-rf
${
BUILD_DIR
}
/bin/
*
.gz
for
f
in
${
BUILD_DIR
}
/bin/
*
;
do
for
f
in
${
BUILD_DIR
}
/bin/
*
;
do
gzip
-n
--best
-f
${
f
}
&
${
GZIP
}
-n
--best
-f
${
f
}
&
pids+
=
"
$!
"
compress_
pids+
=
"
$!
"
done
done
# check for lib directory
# check for lib directory
if
[
-d
${
BUILD_DIR
}
/lib
]
;
then
if
[
-d
${
BUILD_DIR
}
/lib
]
;
then
for
f
in
${
BUILD_DIR
}
/lib/
*
;
do
for
f
in
${
BUILD_DIR
}
/lib/
*
;
do
gzip
-n
--best
-f
${
f
}
&
${
GZIP
}
-n
--best
-f
${
f
}
&
pids+
=
"
$!
"
compress_
pids+
=
"
$!
"
done
done
fi
fi
echo
echo
for
pid
in
${
pids
}
;
do
}
wait_for_compress
()
{
for
pid
in
${
compress_pids
}
;
do
wait
$pid
wait
$pid
done
done
echo
"Finished compression"
echo
"Finished compression"
...
...
llm/generate/gen_darwin.sh
View file @
c7bcb003
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
set
-ex
set
-ex
set
-o
pipefail
set
-o
pipefail
compress_pids
=
""
echo
"Starting darwin generate script"
echo
"Starting darwin generate script"
source
$(
dirname
$0
)
/gen_common.sh
source
$(
dirname
$0
)
/gen_common.sh
init_vars
init_vars
...
@@ -98,4 +99,5 @@ case "${GOARCH}" in
...
@@ -98,4 +99,5 @@ case "${GOARCH}" in
esac
esac
cleanup
cleanup
wait_for_compress
echo
"go generate completed. LLM runners:
$(
cd
${
BUILD_DIR
}
/..
;
echo
*
)
"
echo
"go generate completed. LLM runners:
$(
cd
${
BUILD_DIR
}
/..
;
echo
*
)
"
llm/generate/gen_linux.sh
View file @
c7bcb003
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
set
-ex
set
-ex
set
-o
pipefail
set
-o
pipefail
compress_pids
=
""
# See https://llvm.org/docs/AMDGPUUsage.html#processors for reference
# See https://llvm.org/docs/AMDGPUUsage.html#processors for reference
amdGPUs
()
{
amdGPUs
()
{
...
@@ -274,4 +275,5 @@ if [ -z "${OLLAMA_SKIP_ROCM_GENERATE}" -a -d "${ROCM_PATH}" ]; then
...
@@ -274,4 +275,5 @@ if [ -z "${OLLAMA_SKIP_ROCM_GENERATE}" -a -d "${ROCM_PATH}" ]; then
fi
fi
cleanup
cleanup
wait_for_compress
echo
"go generate completed. LLM runners:
$(
cd
${
BUILD_DIR
}
/..
;
echo
*
)
"
echo
"go generate completed. LLM runners:
$(
cd
${
BUILD_DIR
}
/..
;
echo
*
)
"
scripts/build_linux.sh
View file @
c7bcb003
...
@@ -4,6 +4,7 @@ set -eu
...
@@ -4,6 +4,7 @@ set -eu
export
VERSION
=
${
VERSION
:-
$(
git describe
--tags
--first-parent
--abbrev
=
7
--long
--dirty
--always
|
sed
-e
"s/^v//g"
)
}
export
VERSION
=
${
VERSION
:-
$(
git describe
--tags
--first-parent
--abbrev
=
7
--long
--dirty
--always
|
sed
-e
"s/^v//g"
)
}
export
GOFLAGS
=
"'-ldflags=-w -s
\"
-X=github.com/ollama/ollama/version.Version=
$VERSION
\"
\"
-X=github.com/ollama/ollama/server.mode=release
\"
'"
export
GOFLAGS
=
"'-ldflags=-w -s
\"
-X=github.com/ollama/ollama/version.Version=
$VERSION
\"
\"
-X=github.com/ollama/ollama/server.mode=release
\"
'"
GZIP
=
$(
which pigz 2>/dev/null
||
echo
"gzip"
)
BUILD_ARCH
=
${
BUILD_ARCH
:-
"amd64 arm64"
}
BUILD_ARCH
=
${
BUILD_ARCH
:-
"amd64 arm64"
}
export
AMDGPU_TARGETS
=
${
AMDGPU_TARGETS
:
=
""
}
export
AMDGPU_TARGETS
=
${
AMDGPU_TARGETS
:
=
""
}
...
@@ -25,5 +26,5 @@ for TARGETARCH in ${BUILD_ARCH}; do
...
@@ -25,5 +26,5 @@ for TARGETARCH in ${BUILD_ARCH}; do
docker
rm
builder-
$TARGETARCH
docker
rm
builder-
$TARGETARCH
echo
"Compressing final linux bundle..."
echo
"Compressing final linux bundle..."
rm
-f
./dist/ollama-linux-
$TARGETARCH
.tgz
rm
-f
./dist/ollama-linux-
$TARGETARCH
.tgz
(
cd
dist/linux-
$TARGETARCH
&&
tar
cf -
.
|
gzip
--best
>
../ollama-linux-
$TARGETARCH
.tgz
)
(
cd
dist/linux-
$TARGETARCH
&&
tar
cf -
.
|
${
GZIP
}
--best
>
../ollama-linux-
$TARGETARCH
.tgz
)
done
done
scripts/rh_linux_deps.sh
View file @
c7bcb003
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
# Script for common Dockerfile dependency installation in redhat linux based images
# Script for common Dockerfile dependency installation in redhat linux based images
set
-ex
set
-ex
set
-o
pipefail
MACHINE
=
$(
uname
-m
)
MACHINE
=
$(
uname
-m
)
if
grep
-i
"centos"
/etc/system-release
>
/dev/null
;
then
if
grep
-i
"centos"
/etc/system-release
>
/dev/null
;
then
...
@@ -29,7 +30,7 @@ if grep -i "centos" /etc/system-release >/dev/null; then
...
@@ -29,7 +30,7 @@ if grep -i "centos" /etc/system-release >/dev/null; then
dnf
install
-y
rh-git227-git
dnf
install
-y
rh-git227-git
ln
-s
/opt/rh/rh-git227/root/usr/bin/git /usr/local/bin/git
ln
-s
/opt/rh/rh-git227/root/usr/bin/git /usr/local/bin/git
fi
fi
dnf
install
-y
devtoolset-10-gcc devtoolset-10-gcc-c++
dnf
install
-y
devtoolset-10-gcc devtoolset-10-gcc-c++
pigz
elif
grep
-i
"rocky"
/etc/system-release
>
/dev/null
;
then
elif
grep
-i
"rocky"
/etc/system-release
>
/dev/null
;
then
# Temporary workaround until rocky 8 AppStream ships GCC 10.4 (10.3 is incompatible with NVCC)
# Temporary workaround until rocky 8 AppStream ships GCC 10.4 (10.3 is incompatible with NVCC)
cat
<<
EOF
> /etc/yum.repos.d/Rocky-Vault.repo
cat
<<
EOF
> /etc/yum.repos.d/Rocky-Vault.repo
...
@@ -43,12 +44,21 @@ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
...
@@ -43,12 +44,21 @@ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
EOF
EOF
dnf
install
-y
git
\
dnf
install
-y
git
\
gcc-toolset-10-gcc-10.2.1-8.2.el8
\
gcc-toolset-10-gcc-10.2.1-8.2.el8
\
gcc-toolset-10-gcc-c++-10.2.1-8.2.el8
gcc-toolset-10-gcc-c++-10.2.1-8.2.el8
\
pigz
else
else
echo
"ERROR Unexpected distro"
echo
"ERROR Unexpected distro"
exit
1
exit
1
fi
fi
if
[
"
${
MACHINE
}
"
=
"x86_64"
]
;
then
curl
-s
-L
https://github.com/ccache/ccache/releases/download/v4.10.2/ccache-4.10.2-linux-x86_64.tar.xz |
tar
-Jx
-C
/tmp
--strip-components
1
&&
\
mv
/tmp/ccache /usr/local/bin/
else
yum
-y
install
epel-release
yum
install
-y
ccache
fi
if
[
-n
"
${
CMAKE_VERSION
}
"
]
;
then
if
[
-n
"
${
CMAKE_VERSION
}
"
]
;
then
curl
-s
-L
https://github.com/Kitware/CMake/releases/download/v
${
CMAKE_VERSION
}
/cmake-
${
CMAKE_VERSION
}
-linux-
$(
uname
-m
)
.tar.gz |
tar
-zx
-C
/usr
--strip-components
1
curl
-s
-L
https://github.com/Kitware/CMake/releases/download/v
${
CMAKE_VERSION
}
/cmake-
${
CMAKE_VERSION
}
-linux-
$(
uname
-m
)
.tar.gz |
tar
-zx
-C
/usr
--strip-components
1
fi
fi
...
...
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