Giter Club home page Giter Club logo

fastchat-systemd's Introduction

Documentation d'installation de FastChat avec HuggingFace et SystemD

Prérequis

  • Un environnement Linux.
  • Accès root pour l'exécution des commandes.

Installation

#!/bin/bash
#https://github.com/lm-sys/FastChat

# LLM model
#mistralai/Mixtral-8x7B-Instruct-v0.1
export modelPath=lmsys/vicuna-33b-v1.3
export load_8bit=False

export modelName=$(basename "${modelPath}" |sed -rn 's#^(|[0-9]+[bB][^[:alnum:]]+)([[:alnum:]]+)([^[:alnum:]].*|)$#\2#p' |tr '[:upper:]' '[:lower:]' )

# Vérifiez si le script est exécuté en tant que root
if [[ $EUID -ne 0 ]]; then
    echo "Veuillez exécuter ce script en tant que root" 1>&2
    exit 1
fi

# Créer l'utilisateur ailab
userName=ailab
useradd ${userName} -s /bin/bash -d /home/${userName} -g root -m -k /etc/skel

# Mise à jour et installation des dépendances
apt update
apt upgrade -y
apt install python3-venv -y

# Configuration de l'environnement utilisateur
su - ${userName} <<'EOF'
mkdir -p ~/venv/FastChat
python3 -m venv ~/venv/FastChat
source ~/venv/FastChat/bin/activate
python3 -m pip cache purge
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pip install "fschat[model_worker,webui]"
python3 -m pip install --upgrade pip install fschat transformers torch accelerate sentencepiece protobuf gradio bitsandbytes scipy
EOF

cat <<'EOT' > /home/ailab/FastChat/wait-for-message.sh
#!/bin/bash
LOGFILE="$1"
MESSAGE="$2"
while true; do
  if grep -q "$MESSAGE" "$LOGFILE"; then
    break
  fi
  sleep 1
done
EOT
chmod +x /home/ailab/FastChat/wait-for-message.sh
chown ailab: /home/ailab/FastChat/wait-for-message.sh

# Configuration des services systemd
cat <<EOT > /etc/systemd/system/controller.service
[Unit]
Description=fastchat Controller
After=network.target
Requires=network.target
[Service]
ExecStart=/bin/bash -c 'cd /home/ailab/FastChat && source ~/venv/FastChat/bin/activate && python3 -m fastchat.serve.controller > /tmp/controller.log 2>&1'
ExecStartPost=/bin/bash -c '/home/ailab/FastChat/wait-for-message.sh /tmp/controller.log "Uvicorn running"'
User=ailab
Restart=always
[Install]
WantedBy=multi-user.target
EOT

cat <<EOT > /etc/systemd/system/model_worker.service
[Unit]
Description=fastchat Model Worker
After=controller.service
Requires=controller.service
[Service]
WorkingDirectory=/home/ailab/FastChat
Environment="modelPath=${modelPath}"
Environment="modelName=${modelName}"
ExecStart=/bin/bash -c 'cd /home/ailab/FastChat && source ~/venv/FastChat/bin/activate && python3 -m fastchat.serve.model_worker $([ "${load_8bit}" == "True" ] && echo '--load-8bit' ) --model-names "'"\${modelName}"',gpt-4,gpt-3.5-turbo-instruct,gpt-3.5-turbo,gpt-3.5-turbo-16k,text-davinci-003,text-embedding-ada-002" --model-path '"\${modelPath}"' $(lspci | grep -iEw "VGA|NVIDIA" >/dev/null 2>&1 ||echo -n "--device cpu" ) > /tmp/model_worker.log 2>&1'
TimeoutStartSec=900
ExecStartPost=/bin/bash -c '/home/ailab/FastChat/wait-for-message.sh /tmp/model_worker.log "Uvicorn running"'
User=ailab
Restart=always
[Install]
WantedBy=multi-user.target
EOT

cat <<EOT >/etc/systemd/system/fastchat-openai-api.service
[Unit]
Description=fastchat Api
After=model_worker.service
Requires=model_worker.service

[Service]
ExecStart=/bin/bash -c 'cd /home/ailab/FastChat && source ~/venv/FastChat/bin/activate && python3 -m fastchat.serve.openai_api_server --host 0.0.0.0 --port 8501'
User=ailab
Restart=always

[Install]
WantedBy=multi-user.target
EOT

cat <<EOT > /etc/systemd/system/gradio_web_server.service
[Unit]
Description=fastchat Gradio Web Server
After=model_worker.service
Requires=model_worker.service
[Service]
ExecStart=/bin/bash -c 'cd /home/ailab/FastChat && source ~/venv/FastChat/bin/activate && python3 -m fastchat.serve.gradio_web_server --port 8502'
User=ailab
Restart=always

[Install]
WantedBy=multi-user.target
EOT

# Activation et démarrage des services
systemctl daemon-reload
systemctl enable controller model_worker gradio_web_server fastchat-openai-api
pkill -9 -u ailab python3
systemctl restart controller model_worker gradio_web_server fastchat-openai-api

echo "Installation terminée!"

L'utilisateur doit simplement exécuter le script avec des droits root pour installer tout ce dont il a besoin. Pour l'utiliser, sauvegardez ce contenu dans un fichier, par exemple install_fastchat.sh, rendez-le exécutable avec chmod +x install_fastchat.sh et exécutez-le avec sudo ./install_fastchat.sh.

Vérification

Vérifiez que les services sont en cours d'exécution avec:

systemctl status controller model_worker gradio_web_server fastchat-openai-api

Références

Voilà! Vous avez maintenant configuré et démarré FastChat sur votre système.

fastchat-systemd's People

Contributors

ynotopec avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.