Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

package-gpu-libs.sh copies each symlink as a full file due to cp -arfL, tripling disk usage for libraries like libcublas (~105MB × 3 versions = 315MB instead of 105MB).

Changes

  • Modified copy_lib: Detects symlinks with [ -L ], resolves to real file via readlink -f, copies real file once, recreates symlinks pointing to it
  • Modified copy_libs_glob: Sorts files by type (regular files first, then symlinks) to ensure targets exist before creating symlinks
  • Tracks copied files by basename: Uses associative array to deduplicate across multiple source paths

Before

-rw-r--r-- 105140976 libcublas.so
-rw-r--r-- 105140976 libcublas.so.12
-rw-r--r-- 105140976 libcublas.so.12.9.1.4

After

lrwxrwxrwx libcublas.so -> libcublas.so.12.9.1.4
lrwxrwxrwx libcublas.so.12 -> libcublas.so.12.9.1.4
-rw-r--r-- 105140976 libcublas.so.12.9.1.4
Original prompt

On package-gpu-libs.sh, package-gpu-libs.sh works, however since we copy all the libraries with cp -a, we don't copy symlinks but we copy the real file every time. This is OK, however, we end up with a very large backend image because we also copy the same files more than once, for instance:

#24 55.01 drwxr-xr-x 1 root root 4096 Jan 8 18:45 ..
#24 55.01 -rw-r--r-- 1 root root 105140976 May 31 2025 libcublas.so
#24 55.01 -rw-r--r-- 1 root root 105140976 May 31 2025 libcublas.so.12
#24 55.01 -rw-r--r-- 1 root root 105140976 May 31 2025 libcublas.so.12.9.1.4
#24 55.01 -rw-r--r-- 1 root root 749205904 May 31 2025 libcublasLt.so
#24 55.01 -rw-r--r-- 1 root root 749205904 May 31 2025 libcublasLt.so.12
#24 55.01 -rw-r--r-- 1 root root 749205904 May 31 2025 libcublasLt.so.12.9.1.4
#24 55.01 -rw-r--r-- 1 root root 741088 May 12 2025 libcudart.so
#24 55.01 -rw-r--r-- 1 root root 741088 May 12 2025 libcudart.so.12
#24 55.01 -rw-r--r-- 1 root root 741088 May 12 2025 libcudart.so.12.9.79
#24 55.01 -rw-r--r-- 1 root root 289566960 May 25 2025 libcufft.so
#24 55.01 -rw-r--r-- 1 root root 289566960 May 25 2025 libcufft.so.11
#24 55.01 -rw-r--r-- 1 root root 289566960 May 25 2025 libcufft.so.11.4.1.4
#24 55.01 -rw-r--r-- 1 root root 166965432 Mar 4 2025 libcurand.so
#24 55.01 -rw-r--r-- 1 root root 166965432 Mar 4 2025 libcurand.so.10
#24 55.01 -rw-r--r-- 1 root root 166965432 Mar 4 2025 libcurand.so.10.3.10.19
#24 55.01 -rw-r--r-- 1 root root 301268392 May 19 2025 libcusolver.so
#24 55.01 -rw-r--r-- 1 root root 301268392 May 19 2025 libcusolver.so.11
#24 55.01 -rw-r--r-- 1 root root 301268392 May 19 2025 libcusolver.so.11.7.5.82
#24 55.01 -rw-r--r-- 1 root root 485439480 May 12 2025 libcusparse.so
#24 55.01 -rw-r--r-- 1 root root 485439480 May 12 2025 libcusparse.so.12
#24 55.01 -rw-r--r-- 1 root root 485439480 May 12 2025 libcusparse.so.12.5.10.65

what we want to do here is to identify each of the libraries, copy it, and re-create the symlink for the others. In this way we copy it only once


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link

netlify bot commented Jan 8, 2026

Deploy Preview for localai ready!

Name Link
🔨 Latest commit 2678a14
🔍 Latest deploy log https://app.netlify.com/projects/localai/deploys/696015329467b90008ee8362
😎 Deploy Preview https://deploy-preview-7931--localai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title [WIP] Optimize library copying to reduce backend image size Optimize GPU library copying to preserve symlinks and avoid duplicates Jan 8, 2026
Copilot AI requested a review from mudler January 8, 2026 20:37
@mudler mudler marked this pull request as ready for review January 8, 2026 21:26
@mudler mudler merged commit 06323df into master Jan 8, 2026
31 of 35 checks passed
@mudler mudler deleted the copilot/optimize-copying-libraries branch January 8, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants