-
Notifications
You must be signed in to change notification settings - Fork 124
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
Add logic to build intel-gpu image to build_llama_and_whisper.sh #724
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
FROM quay.io/fedora/fedora:41 as builder | ||
|
||
COPY intel-gpu/oneAPI.repo /etc/yum.repos.d/ | ||
COPY scripts/build_llama_and_whisper.sh / | ||
|
||
RUN dnf install -y intel-opencl g++ cmake git tar libcurl-devel intel-oneapi-mkl-sycl-devel intel-oneapi-dnnl-devel intel-oneapi-compiler-dpcpp-cpp ; \ | ||
git clone https://github.com/ggerganov/llama.cpp.git -b b4523 ; \ | ||
cd llama.cpp ; \ | ||
mkdir -p build ; \ | ||
cd build ; \ | ||
source /opt/intel/oneapi/setvars.sh ; \ | ||
cmake .. -DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_CURL=ON -DGGML_CCACHE=OFF -DGGML_NATIVE=OFF ; \ | ||
cmake --build . --config Release -j -v ; \ | ||
cmake --install . --prefix /llama-cpp | ||
RUN chmod +x /build_llama_and_whisper.sh ; \ | ||
/build_llama_and_whisper.sh intel-gpu | ||
|
||
FROM quay.io/fedora/fedora:41 | ||
|
||
ENV LD_LIBRARY_PATH="/usr/local/lib64:/usr/local/lib/:/opt/intel/oneapi/mkl/2025.0/lib:/opt/intel/oneapi/compiler/2025.0/opt/compiler/lib:/opt/intel/oneapi/compiler/2025.0/lib/clang/19/lib:/opt/intel/oneapi/compiler/2025.0/lib:/opt/intel/oneapi/umf/0.9/lib:/opt/intel/oneapi/tbb/2022.0/lib:/opt/intel/oneapi/tcm/1.2/lib:/opt/intel/oneapi/redist/opt/compiler/lib:/opt/intel/oneapi/redist/lib/clang/19/lib:/opt/intel/oneapi/redist/lib:/opt/intel/oneapi/mkl/2025.0/lib:/opt/intel/oneapi/compiler/2025.0/opt/compiler/lib:/opt/intel/oneapi/compiler/2025.0/lib/clang/19/lib:/opt/intel/oneapi/compiler/2025.0/lib:/opt/intel/oneapi/umf/0.9/lib:/opt/intel/oneapi/tbb/2022.0/lib:/opt/intel/oneapi/tcm/1.2/lib:/opt/intel/oneapi/redist/opt/compiler/lib:/opt/intel/oneapi/redist/lib/clang/19/lib:/opt/intel/oneapi/redist/lib" | ||
|
||
COPY --from=builder /llama-cpp/bin/ /usr/local/bin/ | ||
COPY --from=builder /llama-cpp/lib/ /usr/local/lib/ | ||
COPY --from=builder /llama-cpp/lib64/ /usr/local/lib64/ | ||
COPY --from=builder /llama-cpp/include/ /usr/local/include/ | ||
COPY --from=builder /tmp/install/ /usr/ | ||
COPY intel-gpu/oneAPI.repo /etc/yum.repos.d/ | ||
COPY --chown=0:0 intel-gpu/entrypoint.sh / | ||
|
||
RUN dnf install -y intel-opencl libcurl lspci clinfo intel-oneapi-runtime-compilers intel-oneapi-mkl-core intel-oneapi-mkl-sycl-blas intel-oneapi-runtime-dnnl ; \ | ||
RUN dnf install -y procps-ng python3 python3-pip python3-devel intel-level-zero oneapi-level-zero intel-compute-runtime libcurl lspci clinfo intel-oneapi-runtime-compilers intel-oneapi-mkl-core intel-oneapi-mkl-sycl-blas intel-oneapi-runtime-dnnl ; \ | ||
chown 0:0 /etc/passwd ; \ | ||
chown 0:0 /etc/group ; \ | ||
chmod g=u /etc/passwd /etc/group ; \ | ||
useradd -u 1000 -g render -G video -s /bin/bash -d /home/llama-user llama-user | ||
chmod g=u /etc/passwd /etc/group /home ; \ | ||
chmod +x /entrypoint.sh | ||
|
||
USER 10000 | ||
|
||
USER 1000 | ||
WORKDIR /home/llama-user | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
CMD [ "tail", "-f", "/dev/null" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z ${HOME} ] | ||
then | ||
export HOME=/home/llama-user | ||
fi | ||
|
||
# Create Home directory | ||
if [ ! -d "${HOME}" ] | ||
then | ||
mkdir -p "${HOME}" | ||
fi | ||
|
||
# Create User ID | ||
if ! whoami &> /dev/null | ||
then | ||
if [ -w /etc/passwd ] && [ -w /etc/group ] | ||
then | ||
echo "${USER_NAME:-llama-user}:x:$(id -u):0:${USER_NAME:-llama-user} user:${HOME}:/bin/bash" >> /etc/passwd | ||
echo "${USER_NAME:-llama-user}:x:$(id -u):" >> /etc/group | ||
render_group="$(cat /etc/group | grep 'render:x')" | ||
video_group="$(cat /etc/group | grep 'video:x')" | ||
render_group_new="${render_group}${USER_NAME:-llama-user}" | ||
video_group_new="${video_group}${USER_NAME:-llama-user}" | ||
sed "s|${render_group}|${render_group_new}|g" /etc/group > /tmp/group | ||
cat /tmp/group > /etc/group | ||
sed "s|${video_group}|${video_group_new}|g" /etc/group > /tmp/group | ||
cat /tmp/group > /etc/group | ||
fi | ||
fi | ||
|
||
# Configure Z shell | ||
if [ ! -f ${HOME}/.zshrc ] | ||
then | ||
(echo "source /opt/intel/oneapi/setvars.sh") > ${HOME}/.zshrc | ||
fi | ||
|
||
# Configure Bash shell | ||
if [ ! -f ${HOME}/.bashrc ] | ||
then | ||
(echo "source /opt/intel/oneapi/setvars.sh") > ${HOME}/.bashrc | ||
fi | ||
|
||
source /opt/intel/oneapi/setvars.sh | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🚨 issue (security): The group file modifications could race when multiple containers start simultaneously
Consider using a more atomic approach to modify the group file. Also, the USER_NAME variable should be properly escaped to prevent potential injection issues.
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:
would be more atomic, same on line 28.
I don't see the race condition myself, but mv is a nicer option, if it works, more atomic to replace the inode.
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.
You're right that
mv /tmp/group /etc/group
is more atomic and generally a better approach for replacing the file. However, the race condition I'm referring to isn't about replacing the file itself, but about concurrent modifications to the file. If multiple containers based on this image start simultaneously, they could all be reading/etc/group
, modifying it in memory, and then writing their modified version back. This could lead to some updates being lost.For example:
/etc/group
./etc/group
(same content as Container 1).llama-user
to therender
group and writes the updated/etc/group
.llama-user
to thevideo
group and writes the updated/etc/group
, overwriting the changes made by Container 1 regarding therender
group.Using
mv
doesn't solve this. A more robust solution would be to use a tool designed for concurrent file modifications, likeusermod
andgroupmod
. These tools handle locking and ensure that changes aren't overwritten. They also address the escaping concern I mentioned.Could you try using
usermod -a -G render ${USER_NAME}
andusermod -a -G video ${USER_NAME}
instead of directly manipulating/etc/group
? This would be safer and more idiomatic. Also, ensure thatUSER_NAME
is properly defined and sanitized before being used in these commands.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.
Wouldn't each container have it's own filesystem anyway? Hence no race condition
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.
You're right that each container has its own filesystem, after it starts. However, the
/etc/group
file is typically part of the container image. So, when multiple containers are launched from the same image, they initially share the same/etc/group
file. The modifications made by the entrypoint script happen after the container starts but before any user-specified commands run.So, if multiple containers based on this image start simultaneously, they will all run this entrypoint script concurrently, and they will all be modifying their initially-shared copy of
/etc/group
. This is where the race condition occurs. Even though they each have their own filesystem later, the changes made during startup can be overwritten by other containers starting at the same time.Using tools like
usermod
andgroupmod
is crucial because they handle file locking and ensure that concurrent modifications to/etc/group
are applied correctly, avoiding the race condition even when multiple containers start simultaneously from the same image. They also handle escaping and other potential security issues related to directly manipulating/etc/group
.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 tried
mv
initially but it requiresrw
access to the underlying folder, wherecat >
just requiresrw
on the file.