-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor image builds to put all of the hardware and platform selection logic into one place. #720
Conversation
… one place. Signed-off-by: Charro Gruver <[email protected]>
Reviewer's Guide by SourceryThis pull request refactors the image build process to consolidate hardware and platform selection logic into a single script, enhancing maintainability and consistency. Flow diagram of the new build processgraph TD
Start[Start Build] --> Script[build_llama_and_whisper.sh]
Script --> SelectHW{Select Hardware Type}
SelectHW --> InstallDeps[Install Common Dependencies]
InstallDeps --> HWSpecific{Hardware-Specific Setup}
HWSpecific --> ConfigCMake[Configure CMake Flags]
ConfigCMake --> BuildLlama[Build llama.cpp]
BuildLlama --> BuildWhisper[Build whisper.cpp]
BuildWhisper --> Cleanup[Cleanup Build Files]
Cleanup --> End[End Build]
style SelectHW fill:#f96,stroke:#333,stroke-width:2px
style HWSpecific fill:#f96,stroke:#333,stroke-width:2px
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Note: Please review, but don't merge yet until we are sure I did not break any of the container images. :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @cgruver - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: Charro Gruver <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @cgruver - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider refactoring the global CMAKE_FLAGS variables into function parameters or a configuration object to improve maintainability and testability.
- The common CMake flags could be extracted into helper functions to reduce duplication across the different hardware targets.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
The |
Signed-off-by: Charro Gruver <[email protected]>
|
||
# Bash does not easily pass arrays as a single arg to a function. So, make this a global var in the script. | ||
CMAKE_FLAGS="" | ||
LLAMA_CPP_CMAKE_FLAGS="" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need a global variables, could we put local variables in main instead? Trying to keep everything scoped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The styling changes aren't a blocker for merge, but why change it?
We don't put "function" in front of the functions in any of the other shell scripts in the project, we don't use camelCase in any of the other shell scripts either.
Now this is the odd shell script in terms of consistency 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't want to be the oddball...
local vulkan_rpms=("vulkan-headers" "vulkan-loader-devel" "vulkan-tools" "spirv-tools" "glslc" "glslang") | ||
local intel_rpms=("intel-oneapi-mkl-sycl-devel" "intel-oneapi-dnnl-devel" "intel-oneapi-compiler-dpcpp-cpp" "intel-level-zero" "oneapi-level-zero" "oneapi-level-zero-devel" "intel-compute-runtime") | ||
|
||
LLAMA_CPP_CMAKE_FLAGS+=("-DGGML_CCACHE=OFF" "-DGGML_NATIVE=OFF" "-DBUILD_SHARED_LIBS=NO" "-DLLAMA_CURL=ON") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right, we want BUILD_SHARE_LIBS for llama.cpp but not whisper.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think -DBUILD_SHARED_LIBS breaks for the intel-gpu build. I'll double check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet that's why the rocm image got really big... -DBUILD_SHARED_LIBS=NO
. That resulted in some huge executables in /usr/bin...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think you got it, -DBUILD_SHARED_LIBS=NO end up in the libraries being duplicated in every single binary produced.
The reason we do it for whisper.cpp is it uses some of the same libraries, with the same names, but with different versions sometimes, so one install will replace the library of the other, breaking whichever was installed first.
whisper.cpp is a small project so we statically link that one to fix the issue.
CMAKE_FLAGS+=(${LLAMA_CPP_CMAKE_FLAGS[@]}) | ||
cloneAndBuild https://github.com/ggerganov/llama.cpp ${llama_cpp_sha} ${install_prefix} | ||
dnf -y clean all | ||
rm -rf /var/cache/*dnf* /opt/rocm-*/lib/*/library/*gfx9* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was where the bulk of the trimming was done for rocm in the past. Not sure why it's ballooned again.
I'd revert this shell script back to it's original state and introduce just enough changes to get "intel-gpu" working with this script. There's no need to rewrite the whole script, it's asking for breakages.
It's not making a reviewers job easy re-writing the whole thing 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. It was a wild hair 🤓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intent is to see if we can prevent the build script from becoming a Rube Goldberg machine. The more logic that we have to drop into places based on different builds may get unmanageable. IMO, it's already a bit challenging to read. Natural entropy of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure my attempt is much easier to read either though...
@@ -0,0 +1,113 @@ | |||
#!/usr/bin/env bash | |||
|
|||
# Bash does not easily pass arrays as a single arg to a function. So, make this a global var in the script. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to pass local variables as parameters in bash, they propagate to called functions, they just don't have global scope if that makes sense.
Besides the build_llama_and_whisper.sh file, the changes look fine. |
Signed-off-by: Charro Gruver <[email protected]>
I'm going to dump this one. It was an experiment. |
This is a proposed refactor of the image build process that I believe will make it easier to maintain as we add more hardware and platform types.
I moved all of the selection logic into a
case
statement in themain
function.Each image has its own selection in the
case
.Summary by Sourcery
Consolidate hardware and platform selection logic for image builds into a single script.
Enhancements:
/usr
for CUDA and Intel GPU builds.quay.io/fedora/fedora:41
.Build:
build_llama_and_whisper.sh
script to manage builds across different hardware and platforms (ramalama, ROCm, CUDA, Vulkan, Asahi, and Intel GPU).