-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
docker file and compose #120
Conversation
Why not build the image in docker-compose directly? |
Pushed both change |
Thanks for sharing. For instance, use: ${MODELS:-./models} to set the models directory so that it can be set in the .env file. |
Not sure to understand correctly but setting load_dotenv(override=True) will override docker-compose env var with the .env file but there is not .env file actually |
There is no .env file in the repo, but we can set one locally. By setting .env as follows, I successfully used my E: drive for the models. A user that does not have a local .env should be using ./models instead.
This avoids changing any git controlled file to adapt to the local setup. I already had some models on my e-drive... . |
I was able to use "MODEL_MOUNT". I suggest to convert the line endings to CRLF of these files. As I was applying a local pre-commit configuration, this detected that the line endings of the yaml files (and Dockerfile) is CRLF - yamllint suggest to have LF line endings - yamlfix helps format the files automatically. I am still struggling to get an anwser to my question - the container stops at some point. Maybe this has to do with memory - the container limit is 7.448GiB . |
FYI, I've set the memory for WSL2 to 12GB which allowed me to get an anwser to a question. My .wslconfig now looks like:
During compilation I noticed some references to nvidia, so I wondered if the image should be based on some cuda image. I tried |
The two docker-compose*.yaml files share elements and duplication could be avoided by adding both into a single docker-compose.yaml files, and using 'extend:'. It also avoids having to specify the docker-compose*.yaml file. You can have a look at https://github.com/mdeweerd/MetersToHA/blob/meters-to-ha/docker-compose.yml for some hints. |
FYI, I tried to enable 'cuda' and got some kind of success: I got a cuda related error message:
In the Dockerfile I used:
and in the docker-compose-ingest.yaml file, I added:
|
I may be wrong but the requirements use the llamacpp so even if you use a cuda related stuff it won't be used ? since the cpp one only use CPU. |
When I run the app and use "docker stats", the cpu use exceeds 100%, so it's using more than 1 core (but only 1 cpu).
So the latest release has support for cuda. |
Dockerfile
Outdated
@@ -0,0 +1,12 @@ | |||
FROM python:3.10.11 |
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.
Hi, I'd suggest having a look at https://github.com/GoogleContainerTools/distroless too
It provides different base images, python3 included, that are very small and already has a user inside them. It could be very effective to slim down the image size as much as possible!
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.
Hello I already tried some light/distroless image, but the requirements.txt get a lot of dependency like 8Go and need GCC compiler, eventually cuda and other stuff.
You will win like 200M (2%) of the total image size and will probably need to add gcc/python-dev/cuda manually
If you have a working dockerfile using a distroless/light don't hesitate to contribute
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, you're right, I didn't take in consideration the CUDA dependencies that are very heavy. It'd make a little sense, size wise. Maybe security wise could have some sense though, because there is no default shell. But I guess it depends on which environment you are going to use it (and since it is a cli, I think it doesn't really make sense).
docker-compose.yaml
Outdated
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 default name is 'docker-compose.yml', so the extension should be yml.
I am making progress with CUDA and moved everything to a single docker-compose.yaml . I proposed a PR for https://github.com/mdeweerd/privateGPT/tree/cuda in your fork. |
I had added the source_documents mount to the privateGPT service because I did not want to repeat it on every ingest service - I try to be DRY. I now remembered the name of the mechanism I was looking for: anchors and aliases.
This is essentially a suggestion - maybe I'll look into it, but I have to attend some other stuff... |
Since the source_document is only need at ingest, i try to avoid mounting it when not needed. |
Yes, that's perfect. |
Dockerfile
Outdated
ARG BASEIMAGE | ||
FROM $BASEIMAGE | ||
|
||
RUN groupadd -g 10009 -o privategpt && useradd -m -u 10009 -g 10009 -o -s /bin/bash privategpt | ||
USER privategpt | ||
WORKDIR /home/privategpt | ||
|
||
COPY ./src/requirements.txt src/requirements.txt | ||
ARG LLAMA_CMAKE | ||
#RUN CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install $(grep llama-cpp-python src/requirements.txt) | ||
RUN ( /bin/bash -c "${LLAMA_CMAKE} pip install \$(grep llama-cpp-python src/requirements.txt)" 2>&1 | tee llama-build.log ) && sleep 10 | ||
RUN pip install --no-cache-dir -r src/requirements.txt 2>&1 | tee pip-install.log | ||
|
||
COPY ./src src |
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.
ARG BASEIMAGE | |
FROM $BASEIMAGE | |
RUN groupadd -g 10009 -o privategpt && useradd -m -u 10009 -g 10009 -o -s /bin/bash privategpt | |
USER privategpt | |
WORKDIR /home/privategpt | |
COPY ./src/requirements.txt src/requirements.txt | |
ARG LLAMA_CMAKE | |
#RUN CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install $(grep llama-cpp-python src/requirements.txt) | |
RUN ( /bin/bash -c "${LLAMA_CMAKE} pip install \$(grep llama-cpp-python src/requirements.txt)" 2>&1 | tee llama-build.log ) && sleep 10 | |
RUN pip install --no-cache-dir -r src/requirements.txt 2>&1 | tee pip-install.log | |
COPY ./src src | |
ARG BASEIMAGE | |
FROM $BASEIMAGE | |
RUN groupadd -g 10009 -o privategpt \ | |
&& useradd -m -u 10009 -g 10009 -o -s /bin/bash privategpt | |
USER privategpt | |
WORKDIR /home/privategpt | |
COPY ./src/requirements.txt src/requirements.txt | |
ARG LLAMA_CMAKE | |
RUN (${LLAMA_CMAKE} pip install $(grep llama-cpp-python src/requirements.txt) 2>&1 | tee llama-build.log) \ | |
&& sleep 10 \ | |
&& pip install --no-cache-dir -r src/requirements.txt 2>&1 | tee pip-install.log | |
COPY ./src src |
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.
Proposed update in PR :JulienA#2 .
- MODEL_PATH=${MODEL_PATH:-/home/privategpt/models/ggml-gpt4all-j-v1.3-groovy.bin} | ||
- MODEL_N_CTX=${MODEL_N_CTX:-1000} | ||
volumes: | ||
- ${CACHE_MOUNT:-./cache}:/home/privategpt/.cache/torch |
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 local .cache may be populated with other subdirectories, so mapping that entire directory to torch is not ok.
This is wy I mapped only the "torch" directory where the models seem to be downloaded and I mapped it from a "cache" directory int he models path, because this is essentially a cache of models.
To avoid having extra patch to specify, I did not add another path such ass "MODEL_CACHE_MOUNT".
docker compose run --rm --build privategpt-ingest | ||
``` | ||
|
||
2. With Cuda 11.6 or 11.7 |
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.
Maybe add a note:
:warning: The use of CUDA is not fully validated yet. Also the CUDA version on your host is important and must be at least the version used in the container. You can check your version with `docker compose run --rm --build check-cuda-version`
:information_source: Get a recent CUDA version from https://developer.nvidia.com/cuda-downloads.
Dockerfile
Outdated
COPY ./src/requirements.txt src/requirements.txt | ||
ARG LLAMA_CMAKE | ||
#RUN CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install $(grep llama-cpp-python src/requirements.txt) | ||
RUN ( /bin/bash -c "${LLAMA_CMAKE} pip install \$(grep llama-cpp-python src/requirements.txt)" 2>&1 | tee llama-build.log ) && sleep 10 |
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 forgot the remove the && sleep 10
here which I added only to visually verify that the executed command was ok.
This && sleep 10
can be removed.
Dockerfile
Outdated
ARG BASEIMAGE | ||
FROM $BASEIMAGE | ||
|
||
RUN groupadd -g 10009 -o privategpt && useradd -m -u 10009 -g 10009 -o -s /bin/bash privategpt | ||
USER privategpt | ||
WORKDIR /home/privategpt | ||
|
||
COPY ./src/requirements.txt src/requirements.txt | ||
ARG LLAMA_CMAKE | ||
#RUN CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install $(grep llama-cpp-python src/requirements.txt) | ||
RUN ( /bin/bash -c "${LLAMA_CMAKE} pip install \$(grep llama-cpp-python src/requirements.txt)" 2>&1 | tee llama-build.log ) && sleep 10 | ||
RUN pip install --no-cache-dir -r src/requirements.txt 2>&1 | tee pip-install.log | ||
|
||
COPY ./src src |
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.
Proposed update in PR :JulienA#2 .
Add pip upgrade to avoid sha256 mismatches, also cleanup cache
```sh | ||
docker compose run --rm --build privategpt-cuda-11.6-ingest | ||
|
||
docker compose run --rm --build privategpt-cuda-11.7-ingest |
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 get an error when running this command, not sure if its related to docker compose version?
PS C:\Users\bme\projects\privateGPT> docker compose run --rm --build privategpt-cuda-11.7-ingest
unknown flag: --build
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 am on Win11 and the flag is ok with (tested from a powershell prompt)
> docker --version
Docker version 23.0.5, build bc4487a
> docker compose version
Docker Compose version v2.17.3
Added in Docker compose 2.13.0 docker/docs@b00b1d2 .
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.
Thanks
> docker --version
Docker version 20.10.14, build a224086
> docker compose version
Docker Compose version v2.5.1
after doing a build, it runs and give this error:
> docker compose run --rm privategpt-cuda-11.7-ingest
Traceback (most recent call last):
File "/home/privategpt/src/ingest.py", line 4, in <module>
from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'
I see python-dotenv==1.0.0
in the requirements.txt and the pip install succeeded in the docker build (presumably, cause the build completed and ran).
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 branch needs a merge from main.
You can do this locally for now:
git remote add upstream https://github.com/imartinez/privateGPT
git fetch upstream
git checkout -b local-merge
git merge upstream/main
git add README.md
git commit -m "Ignore README conflicts"
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.
rebuilt and its working
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 also received this error, I think it's a red herring due to the output of pip
being hidden and piped into a log file. This prevents it from erroring when it can't find a package etc. and falls through to trying to run the script.
Solution to prevent this would be to remove the pipe into the log file within Dockerfile
.
#FROM python:3.10.11 | ||
#FROM wallies/python-cuda:3.10-cuda11.6-runtime | ||
|
||
# Using argument for base image to avoid multiplying Dockerfiles |
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.
♻️
#FROM python:3.10.11 | |
#FROM wallies/python-cuda:3.10-cuda11.6-runtime | |
# Using argument for base image to avoid multiplying Dockerfiles | |
# Using argument for base image to avoid multiplying Dockerfiles |
|
||
COPY ./src/requirements.txt src/requirements.txt | ||
ARG LLAMA_CMAKE | ||
#RUN CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install $(grep llama-cpp-python src/requirements.txt) |
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.
♻️
#RUN CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install $(grep llama-cpp-python src/requirements.txt) |
|
||
COPY ./src src | ||
|
||
# ENTRYPOINT ["python", "src/privateGPT.py"] |
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.
♻️
# ENTRYPOINT ["python", "src/privateGPT.py"] |
FROM $BASEIMAGE | ||
|
||
RUN groupadd -g 10009 -o privategpt && useradd -m -u 10009 -g 10009 -o -s /bin/bash privategpt | ||
USER privategpt |
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.
Tried running ingest docker container in linux and getting this error:
$ sudo docker compose run --rm privategpt-ingest
[sudo] password for brian:
Loading documents from /home/privategpt/source_documents
Loaded 1 documents from /home/privategpt/source_documents
Split into 90 chunks of text (max. 500 characters each)
Traceback (most recent call last):
File "/home/privategpt/src/ingest.py", line 97, in <module>
main()
File "/home/privategpt/src/ingest.py", line 88, in main
embeddings = HuggingFaceEmbeddings(model_name=embeddings_model_name)
File "/home/privategpt/.local/lib/python3.10/site-packages/langchain/embeddings/huggingface.py", line 54, in __init__
self.client = sentence_transformers.SentenceTransformer(
File "/home/privategpt/.local/lib/python3.10/site-packages/sentence_transformers/SentenceTransformer.py", line 87, in __init__
snapshot_download(model_name_or_path,
File "/home/privategpt/.local/lib/python3.10/site-packages/sentence_transformers/util.py", line 476, in snapshot_download
os.makedirs(nested_dirname, exist_ok=True)
File "/usr/local/lib/python3.10/os.py", line 215, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/usr/local/lib/python3.10/os.py", line 225, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/privategpt/.cache/torch/sentence_transformers'
googling it suggests that its related to the Dockerfile USER not having correct permissions, but I'm not sure.
Do you know what could be causing this? I ran it fine on windows through wsl2 docker desktop, but get this error when running on a linux machine.
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.
It's related to the fact that you're running the docker container as root, and the unpriviliged container user can't create directories as root.
For this particular error mkdir cache ; chmod 777 cache
should do the trick, you also need to do this for the 'db' directory.
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.
thank you, that fixed it. maybe worth noting in the readme? not sure how many other people will get this
You might want to consider reworking this as a |
Just dropping a comment here, this doesn't work out of the box on Apple M1 due to Short term solution appears to be this: #226 (comment) |
After change of permissions and running the ingest, I get a missing model file
|
the model is not download automatically. you need to download it from docker-compose.yml
I changed some code to automatically check for the model
entrypoint.sh:
|
LGTM |
Came looking for an updated Dockerfile that doesn't have the old --chown on the COPY lines and found this PR. What's the thought on merging @denis-ev's approach? |
I wanted to chime in regarding a CUDA container for running PrivateGPT locally in docker on the NVIDIA Container Toolkit. I combined elements from:
An official NVIDIA CUDA image is used as base. The drawback of this is that The resulting image has a size of At least this is what I think these two environment variables are used for after looking at imartinez/privateGPT/scripts/setup and imartinez/privateGPT/settings-docker.yaml. Specifying the model name with This is the Dockerfile I came up with: ARG UBUNTU_VERSION=22.04
ARG CUDA_VERSION=11.8.0
ARG CUDA_DOCKER_ARCH=all
ARG APP_DIR=/home/worker/app
### Build Image ###
FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} as builder
ARG CUDA_DOCKER_ARCH
ARG APP_DIR
ENV DEBIAN_FRONTEND=noninteractive \
CUDA_DOCKER_ARCH=${CUDA_DOCKER_ARCH} \
LLAMA_CUBLAS=1 \
CMAKE_ARGS="-DLLAMA_CUBLAS=on" \
FORCE_CMAKE=1 \
POETRY_VIRTUALENVS_IN_PROJECT=true
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y --no-install-recommends \
python3.11 \
python3.11-dev \
python3.11-venv \
build-essential \
git && \
python3.11 -m ensurepip && \
python3.11 -m pip install pipx && \
python3.11 -m pipx ensurepath && \
pipx install poetry
ENV PATH="/root/.local/bin:$PATH"
WORKDIR $APP_DIR
RUN git clone https://github.com/imartinez/privateGPT.git . --depth 1
RUN poetry install --with local && \
poetry install --with ui
RUN mkdir build_artifacts && \
cp -r .venv private_gpt docs *.yaml *.md build_artifacts/
### Runtime Image ###
FROM nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION} as runtime
ARG APP_DIR
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PGPT_PROFILES=docker,local
EXPOSE 8080
RUN adduser --system worker
WORKDIR $APP_DIR
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y --no-install-recommends \
python3.11 \
python3.11-venv \
curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
mkdir local_data models && \
chown worker local_data models
COPY --chown=worker --from=builder $APP_DIR/build_artifacts ./
USER worker
HEALTHCHECK --start-period=1m --interval=5m --timeout=3s \
CMD curl --head --silent --fail --show-error http://localhost:8080 || exit 1
ENTRYPOINT [".venv/bin/python", "-m", "private_gpt"] |
No description provided.