Skip to content
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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# OSX
.DS_STORE

# Models
models/

# Local Chroma db
.chroma/
db/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#FROM python:3.10.11
#FROM wallies/python-cuda:3.10-cuda11.6-runtime

# Using argument for base image to avoid multiplying Dockerfiles
Comment on lines +1 to +4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️

Suggested change
#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

ARG BASEIMAGE
FROM $BASEIMAGE

RUN groupadd -g 10009 -o privategpt && useradd -m -u 10009 -g 10009 -o -s /bin/bash privategpt
USER privategpt

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.

Copy link
Contributor

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.

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

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️

Suggested change
#RUN CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 pip install $(grep llama-cpp-python src/requirements.txt)

RUN pip install --upgrade pip \
&& ( /bin/bash -c "${LLAMA_CMAKE} pip install \$(grep llama-cpp-python src/requirements.txt)" 2>&1 | tee llama-build.log ) \
&& ( pip install --no-cache-dir -r src/requirements.txt 2>&1 | tee pip-install.log ) \
&& pip cache purge

COPY ./src src

# ENTRYPOINT ["python", "src/privateGPT.py"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️

Suggested change
# ENTRYPOINT ["python", "src/privateGPT.py"]

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,41 @@ To install a C++ compiler on Windows 10/11, follow these steps:
3. Download the MinGW installer from the [MinGW website](https://sourceforge.net/projects/mingw/).
4. Run the installer and select the `gcc` component.

## Docker Version

1. Put your data in models / source_documents in the project root folder (Can be customized changing the corresponding value in the docker-compose.yaml)

2. You can ingest your data using the docker-compose

1. Without Cuda

```sh
docker compose run --rm --build privategpt-ingest
```

2. With Cuda 11.6 or 11.7
Copy link
Contributor

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.


```sh
docker compose run --rm --build privategpt-cuda-11.6-ingest

docker compose run --rm --build privategpt-cuda-11.7-ingest

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

Copy link
Contributor

@mdeweerd mdeweerd May 19, 2023

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 .

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).

Copy link
Contributor

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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebuilt and its working

Copy link
Contributor

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.

```

3. You can run **after** ingesting your data or using an **existing db** with the docker-compose

1. Without Cuda

```sh
docker compose run --rm --build privategpt
```

2. With Cuda 11.6 or 11.7

```sh
docker compose run --rm --build privategpt-cuda-11.6

docker compose run --rm --build privategpt-cuda-11.7
```

# Disclaimer
This is a test project to validate the feasibility of a fully private solution for question answering using LLMs and Vector embeddings. It is not production ready, and it is not meant to be used in production. The models selection is not optimized for performance, but for privacy; but it is possible to use different models and vectorstores to improve performance.
3 changes: 3 additions & 0 deletions cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!.gitkeep
Empty file added cache/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!.gitkeep
Empty file added db/.gitkeep
Empty file.
125 changes: 125 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
version: '3.9'

x-ingest: &ingest
command: [ python, src/ingest.py ]
environment:
- SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-/home/privategpt/source_documents}
volumes:
- ${SOURCE_MOUNT:-./source_documents}:/home/privategpt/source_documents

services:
#
# Base service, without CUDA
#
privategpt:
build:
context: .
dockerfile: ./Dockerfile
args: [ --rm, "BASEIMAGE=python:3.10.11", LLAMA_CMAKE= ]
image: privategpt:test
command: [ python, src/privateGPT.py ]
environment:
- PERSIST_DIRECTORY=${PERSIST_DIRECTORY:-/home/privategpt/db}
- LLAMA_EMBEDDINGS_MODEL=${LLAMA_EMBEDDINGS_MODEL:-/home/privategpt/models/ggml-model-q4_0.bin}
- EMBEDDINGS_MODEL_NAME=${EMBEDDINGS_MODEL_NAME:-all-MiniLM-L6-v2}
- MODEL_TYPE=${MODEL_TYPE:-GPT4All}
- 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
Copy link
Contributor

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".

- ${MODEL_MOUNT:-./models}:/home/privategpt/models
- ${PERSIST_MOUNT:-./db}:/home/privategpt/db

#
# To run with CUDA 11.6
#
# docker compose run --rm --build privategpt-cuda-11.6
#
privategpt-cuda-11.6:
extends: privategpt
image: privategpt:cuda-11.6
build:
args:
- BASEIMAGE=wallies/python-cuda:3.10-cuda11.6-runtime
- LLAMA_CMAKE=CMAKE_ARGS='-DLLAMA_OPENBLAS=on' FORCE_CMAKE=1
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [ gpu ]

#
# To run with CUDA 11.7
#
# docker compose run --rm --build privategpt-cuda-11.7
#
privategpt-cuda-11.7:
extends: privategpt-cuda-11.6
image: privategpt:cuda-11.7
build:
args: [ "BASEIMAGE=wallies/python-cuda:3.10-cuda11.7-runtime" ]

#
# For ingest without cuda:
#
# docker compose run --rm --build privategpt-ingest
#
privategpt-ingest:
extends: privategpt
<<: *ingest

#
# To ingest using cuda 11.6:
#
# docker compose run --rm --build privategpt-cuda-11.6-ingest
#
privategpt-cuda-11.6-ingest:
extends: privategpt-cuda-11.6
image: privategpt:cuda-11.6
<<: *ingest

#
# To ingest using cuda 11.7:
#
# docker compose run --rm --build privategpt-cuda-11.7-ingest
#
privategpt-cuda-11.7-ingest:
extends: privategpt-cuda-11.7
image: privategpt:cuda-11.7
<<: *ingest

# Check your system's version using
#
# docker compose run --rm check-cuda-version
#
# then build and test the privateGPT container
# using
#
# docker compose run --rm check-cuda-<CUDAVERSION>
#
# Where <CUDAVERSION> is the version you found using 'check-cuda-version'.
#
# Example if CUDAVERSION == 11.6
#
# docker compose run --rm --build check-cuda-11.6
#
#
#
# You can update your host's CUDA installation by downloading
# a recent version from
#
# https://developer.nvidia.com/cuda-downloads .
#

check-cuda-version:
image: ubuntu
command: [ nvidia-smi ]
check-cuda-11.6:
extends: privategpt-cuda-11.6
command: [ nvidia-smi ]
check-cuda-11.7:
extends: privategpt-cuda-11.7
command: [ nvidia-smi ]
3 changes: 3 additions & 0 deletions models/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!.gitkeep
Empty file added models/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions source_documents/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!.gitkeep
Empty file added source_documents/.gitkeep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.