mirror of
https://github.com/ollama/ollama.git
synced 2026-01-29 07:12:03 +03:00
CI: dedup cuda libraries to reduce payload size (#13704)
This commit is contained in:
3
.github/workflows/release.yaml
vendored
3
.github/workflows/release.yaml
vendored
@@ -372,6 +372,9 @@ jobs:
|
|||||||
outputs: type=local,dest=dist/${{ matrix.os }}-${{ matrix.arch }}
|
outputs: type=local,dest=dist/${{ matrix.os }}-${{ matrix.arch }}
|
||||||
cache-from: type=registry,ref=${{ vars.DOCKER_REPO }}:latest
|
cache-from: type=registry,ref=${{ vars.DOCKER_REPO }}:latest
|
||||||
cache-to: type=inline
|
cache-to: type=inline
|
||||||
|
- name: Deduplicate CUDA libraries
|
||||||
|
run: |
|
||||||
|
./scripts/deduplicate_cuda_libs.sh dist/${{ matrix.os }}-${{ matrix.arch }}
|
||||||
- run: |
|
- run: |
|
||||||
for COMPONENT in bin/* lib/ollama/*; do
|
for COMPONENT in bin/* lib/ollama/*; do
|
||||||
case "$COMPONENT" in
|
case "$COMPONENT" in
|
||||||
|
|||||||
@@ -48,53 +48,12 @@ if echo $PLATFORM | grep "amd64" > /dev/null; then
|
|||||||
.
|
.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Deduplicate CUDA libraries across mlx_* and cuda_* directories
|
|
||||||
deduplicate_cuda_libs() {
|
|
||||||
local base_dir="$1"
|
|
||||||
echo "Deduplicating CUDA libraries in ${base_dir}..."
|
|
||||||
|
|
||||||
# Find all mlx_cuda_* directories
|
|
||||||
for mlx_dir in "${base_dir}"/lib/ollama/mlx_cuda_*; do
|
|
||||||
[ -d "${mlx_dir}" ] || continue
|
|
||||||
|
|
||||||
# Extract CUDA version (e.g., v12, v13)
|
|
||||||
cuda_version=$(basename "${mlx_dir}" | sed 's/mlx_cuda_//')
|
|
||||||
cuda_dir="${base_dir}/lib/ollama/cuda_${cuda_version}"
|
|
||||||
|
|
||||||
# Skip if corresponding cuda_* directory doesn't exist
|
|
||||||
[ -d "${cuda_dir}" ] || continue
|
|
||||||
|
|
||||||
echo " Checking ${mlx_dir} against ${cuda_dir}..."
|
|
||||||
|
|
||||||
# Find all .so* files in mlx directory
|
|
||||||
find "${mlx_dir}" -type f -name "*.so*" | while read mlx_file; do
|
|
||||||
filename=$(basename "${mlx_file}")
|
|
||||||
cuda_file="${cuda_dir}/${filename}"
|
|
||||||
|
|
||||||
# Skip if file doesn't exist in cuda directory
|
|
||||||
[ -f "${cuda_file}" ] || continue
|
|
||||||
|
|
||||||
# Compare checksums
|
|
||||||
mlx_sum=$(sha256sum "${mlx_file}" | awk '{print $1}')
|
|
||||||
cuda_sum=$(sha256sum "${cuda_file}" | awk '{print $1}')
|
|
||||||
|
|
||||||
if [ "${mlx_sum}" = "${cuda_sum}" ]; then
|
|
||||||
echo " Deduplicating ${filename}"
|
|
||||||
# Calculate relative path from mlx_dir to cuda_dir
|
|
||||||
rel_path="../cuda_${cuda_version}/${filename}"
|
|
||||||
rm -f "${mlx_file}"
|
|
||||||
ln -s "${rel_path}" "${mlx_file}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run deduplication for each platform output directory
|
# Run deduplication for each platform output directory
|
||||||
if echo $PLATFORM | grep "," > /dev/null ; then
|
if echo $PLATFORM | grep "," > /dev/null ; then
|
||||||
deduplicate_cuda_libs "./dist/linux_amd64"
|
$(dirname $0)/deduplicate_cuda_libs.sh "./dist/linux_amd64"
|
||||||
deduplicate_cuda_libs "./dist/linux_arm64"
|
$(dirname $0)/deduplicate_cuda_libs.sh "./dist/linux_arm64"
|
||||||
elif echo $PLATFORM | grep "amd64\|arm64" > /dev/null ; then
|
elif echo $PLATFORM | grep "amd64\|arm64" > /dev/null ; then
|
||||||
deduplicate_cuda_libs "./dist"
|
$(dirname $0)/deduplicate_cuda_libs.sh "./dist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# buildx behavior changes for single vs. multiplatform
|
# buildx behavior changes for single vs. multiplatform
|
||||||
|
|||||||
60
scripts/deduplicate_cuda_libs.sh
Executable file
60
scripts/deduplicate_cuda_libs.sh
Executable file
@@ -0,0 +1,60 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Deduplicate CUDA libraries across mlx_* and cuda_* directories
|
||||||
|
# This script finds identical .so* files in mlx_cuda_* directories that exist
|
||||||
|
# in corresponding cuda_* directories and replaces them with symlinks.
|
||||||
|
#
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
echo "ERROR: No directory specified" >&2
|
||||||
|
echo "Usage: $0 <base_directory>" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
base_dir="$1"
|
||||||
|
|
||||||
|
if [ ! -d "${base_dir}" ]; then
|
||||||
|
echo "ERROR: Directory ${base_dir} does not exist" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Deduplicating CUDA libraries in ${base_dir}..."
|
||||||
|
|
||||||
|
# Find all mlx_cuda_* directories
|
||||||
|
for mlx_dir in "${base_dir}"/lib/ollama/mlx_cuda_*; do
|
||||||
|
[ -d "${mlx_dir}" ] || continue
|
||||||
|
|
||||||
|
# Extract CUDA version (e.g., v12, v13)
|
||||||
|
cuda_version=$(basename "${mlx_dir}" | sed 's/mlx_cuda_//')
|
||||||
|
cuda_dir="${base_dir}/lib/ollama/cuda_${cuda_version}"
|
||||||
|
|
||||||
|
# Skip if corresponding cuda_* directory doesn't exist
|
||||||
|
[ -d "${cuda_dir}" ] || continue
|
||||||
|
|
||||||
|
echo " Checking ${mlx_dir} against ${cuda_dir}..."
|
||||||
|
|
||||||
|
# Find all .so* files in mlx directory
|
||||||
|
find "${mlx_dir}" -type f -name "*.so*" | while read mlx_file; do
|
||||||
|
filename=$(basename "${mlx_file}")
|
||||||
|
cuda_file="${cuda_dir}/${filename}"
|
||||||
|
|
||||||
|
# Skip if file doesn't exist in cuda directory
|
||||||
|
[ -f "${cuda_file}" ] || continue
|
||||||
|
|
||||||
|
# Compare checksums
|
||||||
|
mlx_sum=$(sha256sum "${mlx_file}" | awk '{print $1}')
|
||||||
|
cuda_sum=$(sha256sum "${cuda_file}" | awk '{print $1}')
|
||||||
|
|
||||||
|
if [ "${mlx_sum}" = "${cuda_sum}" ]; then
|
||||||
|
echo " Deduplicating ${filename}"
|
||||||
|
# Calculate relative path from mlx_dir to cuda_dir
|
||||||
|
rel_path="../cuda_${cuda_version}/${filename}"
|
||||||
|
rm -f "${mlx_file}"
|
||||||
|
ln -s "${rel_path}" "${mlx_file}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Deduplication complete"
|
||||||
Reference in New Issue
Block a user