Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into package
Browse files Browse the repository at this point in the history
  • Loading branch information
tnunamak committed Mar 19, 2024
2 parents 600f316 + 716df52 commit d57c9e9
Show file tree
Hide file tree
Showing 23 changed files with 973 additions and 1,625 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
poetry.lock
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Base image for building the UI
FROM node:18.19-alpine3.18 AS selfie-ui
WORKDIR /selfie
COPY selfie-ui/package.json selfie-ui/yarn.lock ./
RUN yarn install --frozen-lockfile --non-interactive
COPY selfie-ui/ .
RUN yarn run build

# Base image for the application
FROM python:3.11 as selfie-base
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR=1
WORKDIR /selfie
COPY . .
COPY --from=selfie-ui /selfie/out/ ./selfie-ui/out
RUN pip install poetry --no-cache-dir
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi
EXPOSE 8181

# CPU-specific configuration
FROM selfie-base as selfie-cpu
CMD ["python", "-m", "selfie"]

# GPU-specific configuration using an NVIDIA base image
# Ensure that the chosen image version has wheels available at https://jllllll.github.io/llama-cpp-python-cuBLAS-wheels.
# You can see what CUDA version an image uses at https://docs.nvidia.com/deeplearning/frameworks/support-matrix/index.html.
# For example, the image nvcr.io/nvidia/pytorch:23.10-py3 uses CUDA 12.2, which is available at https://jllllll.github.io/llama-cpp-python-cuBLAS-wheels/AVX2/cu122.
FROM nvcr.io/nvidia/pytorch:23.10-py3 as selfie-gpu
COPY --from=selfie-base /selfie /selfie
WORKDIR /selfie

RUN pip install poetry --no-cache-dir
ENV PATH="/root/.local/bin:$PATH"
RUN poetry install --no-interaction --no-ansi

RUN bash /selfie/scripts/llama-cpp-python-cublas.sh

# --verbose and other options should probably be controlled by the user
CMD ["poetry", "run", "python", "-m", "selfie", "--gpu", "--verbose"]

# ARM64-specific configuration (Apple Silicon)
FROM selfie-base as selfie-arm64
# Uncomment below if additional dependencies are needed for ARM64
# RUN apt-get update && apt-get install -y --no-install-recommends <arm64-specific-dependencies> && rm -rf /var/lib/apt/lists/*
CMD if [ "$(uname -m)" = "arm64" ]; then \
echo "Running with GPU support"; \
python -m selfie --gpu; \
else \
echo "Running without GPU support"; \
python -m selfie; \
fi
72 changes: 70 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ Imagine AI that is not just smart, but personal. Selfie turns your data into API

Selfie is a local-first, open-source project that runs on your device.

<div align="center">
<a href="https://www.loom.com/share/2b3abdaf35064d00a733c62f3d2fc006" target="_blank">
<img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/2b3abdaf35064d00a733c62f3d2fc006-with-play.gif">
</a>
</div>
<div align="center">
<i style="font-size: 9.5pt">Check out the video tour!</i>
</div>

## Core Features

Selfie offers a more personalized interaction between you and the digital world via:
Expand Down Expand Up @@ -108,16 +117,75 @@ For most users, the easiest way to install Selfie is to follow the [Quick Start]
6. Run `poetry install` to install required Python dependencies.
7. Optional: Run `./scripts/llama-cpp-python-cublas.sh` to enable hardware acceleration (for details, see [Scripts](#llama-cpp-python-cublassh)).
8. Run `poetry run python -m selfie`, or `poetry run python -m selfie --gpu` if your device is GPU-enabled. The first time you run this, it will download ~4GB of model weights.
- On macOS, you may need to run `OMP_NUM_THREADS=1 KMP_DUPLICATE_LIB_OK=TRUE poetry run python -m selfie` to avoid OpenMP errors (with or without `--gpu`). [Read more about OMP_NUM_THREADS here](https://github.com/vana-com/selfie/issues/33#issuecomment-2004637058).

[//]: # (1. `git clone
[//]: # (Disable this note about installing with GPU support until supported via transformers, etc.)

[//]: # (3. `poetry install` or `poetry install -E gpu` &#40;to enable GPU devices via transformers&#41;. Enable GPU or Metal acceleration via llama.cpp by installing GPU-enabled llama-cpp-python, see Scripts.)

[//]: # (This starts a local web server and should launch the UI in your browser at http://localhost:8181. API documentation is available at http://localhost:8181/docs. Now that the server is running, you can use the API to import your data and connect to your LLM.)
</details>

> **Note**: You can host selfie at a publicly-accessible URL with [ngrok](https://ngrok.com). Add your ngrok token (and optionally, ngrok domain) in `selfie/.env` and run `poetry run python -m selfie --share`.
## Using Docker

You can also run Selfie using Docker. To do so, follow these steps:

1. Ensure that [Docker](https://www.docker.com) is installed.
2. Clone or [download](https://github.com/vana-com/selfie) selfie repository.
3. In a terminal, navigate to the project directory.
4. Run the following commands for the image you want to use (CPU, GPU, or ARM64).

This will start the server and the UI in your browser at http://localhost:8181.
Your data will be stored in the `data` directory.
This mounts your Hugging Face cache into the container, so you don't have to download the models again if you already
have them.

### CPU Image
```bash
docker build --target selfie-cpu -t selfie:cpu .

docker run -p 8181:8181 \
--name selfie-cpu \
-v $(pwd)/data:/selfie/data \
-v $(pwd)/selfie:/selfie/selfie \
-v $(pwd)/selfie-ui:/selfie/selfie-ui \
-v $HOME/.cache/huggingface:/root/.cache/huggingface \
selfie:cpu
```

### Nvidia GPU Image
```bash
docker build --target selfie-gpu -t selfie:gpu .

docker run -p 8181:8181 \
--name selfie-gpu \
-v $(pwd)/data:/selfie/data \
-v $(pwd)/selfie:/selfie/selfie \
-v $(pwd)/selfie-ui:/selfie/selfie-ui \
-v $HOME/.cache/huggingface:/root/.cache/huggingface \
--gpus all \
--ipc=host --ulimit memlock=-1 --ulimit stack=67108864 \
selfie:gpu
````

### MacOS ARM64 Image
```bash
DOCKER_BUILDKIT=0 docker build --target selfie-arm64 -t selfie:arm64 .
docker run -p 8181:8181 \
--name selfie-arm64 \
-v $(pwd)/data:/selfie/data \
-v $(pwd)/selfie:/selfie/selfie \
-v $(pwd)/selfie-ui:/selfie/selfie-ui \
-v $HOME/.cache/huggingface:/root/.cache/huggingface \
selfie:arm64
```

> **Note**: on an M1/M2/M3 Mac, you may need to prefix the build command with `DOCKER_BUILDKIT=0` to disable BuildKit.
> ```bash
> DOCKER_BUILDKIT=0 docker build -t selfie:arm64 .
> ```

## Setting Up Selfie

Expand Down
Loading

0 comments on commit d57c9e9

Please sign in to comment.