106 lines
4.2 KiB
Docker
106 lines
4.2 KiB
Docker
# dobromirpopov/petals-ai :latest full
|
|
# dobromirpopov/petals-ai:full
|
|
|
|
FROM python:slim
|
|
|
|
# System dependencies
|
|
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
|
|
# Upgrade pip
|
|
RUN pip install --upgrade pip
|
|
|
|
# Add ENV for MODEL and HF_TOKEN
|
|
ENV MODEL_NAME=stabilityai/StableBeluga2
|
|
ENV HF_TOKEN=
|
|
ENV DHT_PEERS=
|
|
ENV ENV_PARAMS=
|
|
ENV ID_PATH=\dht\bootstrap1.id
|
|
|
|
# FORMATTED_PEERS=$$(echo $$DHT_PEERS | sed "s/[^ ]\+/\'&\'/g")\n\
|
|
# FORMATTED_PEERS=$$(echo $$DHT_PEERS | sed "s/[^ ]\\+/\\'&\\'/g")\n\
|
|
|
|
# Create the entrypoint script inside the Dockerfile
|
|
RUN echo '#!/bin/sh\n\
|
|
echo "Script is starting..."\n\
|
|
echo "MODE is set to: $MODE"\n\
|
|
if [ "$MODE" = "monitor" ] && [ -n "$DHT_PEERS" ]; then\n\
|
|
echo "DHT_PEERS is set to: $DHT_PEERS"\n\
|
|
FORMATTED_PEERS=[$DHT_PEERS]\n\
|
|
echo "Debug FORMATTED_PEERS: $FORMATTED_PEERS"\n\
|
|
##
|
|
# # Convert space-separated string to comma-separated string\n\
|
|
# TEMP_PEERS=$(echo $DHT_PEERS | tr " " ",")\n\
|
|
# # Add single quotes around each element and make it Python list format\n\
|
|
# FORMATTED_PEERS=$(echo $TEMP_PEERS | sed "s/\\([^,]*\\)/\'\\1\'/g")\n\
|
|
# FORMATTED_PEERS="[$FORMATTED_PEERS]"\n\
|
|
##
|
|
echo "monitoring PRIVATE swarm. Initial F peers set to $FORMATTED_PEERS"\n\
|
|
echo "monitoring PRIVATE swarm. Initial peers set to $DHT_PEERS"\n\
|
|
echo "monitoring PRIVATE swarm. Initial peers array set to [$DHT_PEERS]"\n\
|
|
echo "INITIAL_PEERS = [$DHT_PEERS]" >> /health.petals.dev/config.py\n\
|
|
echo "FORMATTED_PEERS = $FORMATTED_PEERS" >> /health.petals.dev/config.py\n\
|
|
else \n\
|
|
echo "monitor has no DHT peers. Monitoring public swarm."\n\
|
|
fi\n\
|
|
|
|
if [ ! -f "/initialized" ]; then\n\
|
|
touch /initialized\n\
|
|
pip install --upgrade petals\n\
|
|
case "$MODE" in\n\
|
|
"monitor")\n\
|
|
git clone https://github.com/d-popov/health.petals.dev.git && \
|
|
cd /health.petals.dev && pip install -r requirements.txt\n\
|
|
;;\n\
|
|
"chat")\n\
|
|
git clone https://github.com/d-popov/chat.petals.dev.git&& \
|
|
cd /chat.petals.dev && pip install -r requirements.txt\n\
|
|
;;\n\
|
|
"server" | "dht")\n\
|
|
pip install git+https://github.com/d-popov/petals-ai.git\n\
|
|
;;\n\
|
|
esac\n\
|
|
fi\n\
|
|
|
|
if [ -n "$HF_TOKEN" ]; then\n\
|
|
git config --global credential.helper store && \n\
|
|
huggingface-cli login --token $HF_TOKEN --add-to-git-credential && \n\
|
|
ENV_PARAMS="--use_auth_token $ENV_PARAMS"\n\
|
|
fi\n\
|
|
INITIAL_PEERS_ARG=""\n\
|
|
if [ -n "$DHT_PEERS" ]; then\n\
|
|
INITIAL_PEERS_ARG="--initial_peers $DHT_PEERS"\n\
|
|
fi\n\
|
|
case "$MODE" in\n\
|
|
"monitor")\n\
|
|
echo "Running monitor node with params: $ENV_PARAMS\n\
|
|
cd /health.petals.dev\n\
|
|
exec gunicorn app:app --bind 0.0.0.0:8484 --workers 4 --threads 10 $ENV_PARAMS \n\
|
|
;;\n\
|
|
"chat")\n\
|
|
echo "Running chat node with params: $ENV_PARAMS\n\
|
|
cd /chat.petals.dev\n\
|
|
exec gunicorn app:app --bind 0.0.0.0:8484 --workers 4 --threads 10 $ENV_PARAMS \n\
|
|
;;\n\
|
|
"dht")\n\
|
|
echo "Running DHT node with params: --host_maddrs /ip4/0.0.0.0/tcp/31337 --identity_path $ID_PATH $INITIAL_PEERS_ARG $ENV_PARAMS"\n\
|
|
exec python -m petals.cli.run_dht --host_maddrs /ip4/0.0.0.0/tcp/31337 --identity_path $ID_PATH $INITIAL_PEERS_ARG $ENV_PARAMS \n\
|
|
;;\n\
|
|
"server" | *)\n\
|
|
echo "Running server node with params: $ENV_PARAMS $MODEL_NAME $INITIAL_PEERS_ARG"\n\
|
|
|
|
exec python -m petals.cli.run_server $ENV_PARAMS $MODEL_NAME $INITIAL_PEERS_ARG\n\
|
|
;;\n\
|
|
esac' > /entrypoint.sh && chmod +x /entrypoint.sh
|
|
|
|
# pull petals and bake it into the image. comment for lite image
|
|
RUN pip install git+https://github.com/d-popov/petals-ai.git
|
|
RUN pip install git+https://github.com/learning-at-home/hivemind
|
|
RUN git clone https://github.com/d-popov/chat.petals.dev.git && cd /chat.petals.dev && pip install -r requirements.txt
|
|
RUN git clone https://github.com/d-popov/health.petals.dev.git && cd /health.petals.dev && pip install -r requirements.txt
|
|
|
|
# if using separate entrypoint file:
|
|
# COPY entrypoint.sh /entrypoint.sh
|
|
# RUN chmod +x /entrypoint.sh TEST
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|