FastChat

De Lea Linux
Aller à la navigation Aller à la recherche
Attention ! Cet article est en cours de rédaction. Il n'a donc encore été ni relu, ni corrigé, ni validé par un modérateur.
Léa vous encourage à éditer les articles pour les améliorer ou les corriger.

FastChat est une platforme libre (licence Apache 2.0) pour entraîner, mettre à disposition et évaluer des robots conversationnels utilisation des modèles de langage.

Pré-requis

Un ordinateur avec au moins 15G d'espace libre, car les modèles les plus petits font rapidement cette taille. Par défaut, FastChat les stockent dans le répertoire .cache de votre répertoire personnel. Idéalement, un processeur graphique (GPU) qui va être utilisé par FastChat en complément du processeur, mais ce n'est pas obligatoire.

Installation

Installation directe avec pip:

$ pip3 install "fschat[model_worker,webui]"
Defaulting to user installation because normal site-packages is not writeable
Collecting fschat[model_worker,webui]
  Downloading fschat-0.2.34-py3-none-any.whl (220 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 220.1/220.1 kB 1.8 MB/s eta 0:00:00
Requirement already satisfied: aiohttp in /home/jiel/.local/lib/python3.11/site-packages (from fschat[model_worker,webui]) (3.9.1)
Requirement already satisfied: fastapi in /home/jiel/.local/lib/python3.11/site-packages (from fschat[model_worker,webui]) (0.108.0)
Requirement already satisfied: httpx in /home/jiel/.local/lib/python3.11/site-packages (from fschat[model_worker,webui]) (0.26.0)
Collecting markdown2[all]
  Downloading markdown2-2.4.12-py2.py3-none-any.whl (41 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.2/41.2 kB 4.5 MB/s eta 0:00:00
     
  Running setup.py install for wavedrom ... done
  Attempting uninstall: gradio-client
    Found existing installation: gradio_client 0.8.0
    Uninstalling gradio_client-0.8.0:
      Successfully uninstalled gradio_client-0.8.0
  Attempting uninstall: gradio
    Found existing installation: gradio 4.12.0
    Uninstalling gradio-4.12.0:
      Successfully uninstalled gradio-4.12.0
Successfully installed fschat-0.2.34 gradio-3.50.2 gradio-client-0.6.1 markdown2-2.4.12 nh3-0.2.15 protobuf-4.25.1 pydantic-1.10.13 shortuuid-1.0.11 svgwrite-1.4.3 tiktoken-0.5.2 wavedrom-2.0.3.post3

Alternativement, on peut cloner le dépôt et on installe avec pip:

$ git clone https://github.com/lm-sys/FastChat.git
$ cd FastChat
$ pip3 install --upgrade pip  # enable PEP 660 support
$ pip3 install -e ".[model_worker,webui]"

Lancer FastChat

Ensuite, on peut simplement lancer FastChat pour le modèle Vicuna avec la commande suivante. Elle va d'abord télécharger le modèle et puis lancer l'interface de discussion:

$ python3 -m fastchat.serve.cli --model-path lmsys/vicuna-7b-v1.5

tokenizer_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 749/749 [00:00<00:00, 3.34MB/s]
tokenizer.model: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 500k/500k [00:00<00:00, 1.98MB/s]
special_tokens_map.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 438/438 [00:00<00:00, 1.88MB/s]
config.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 615/615 [00:00<00:00, 2.24MB/s]
pytorch_model.bin.index.json: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 26.8k/26.8k [00:00<00:00, 10.2MB/s]
Downloading shards:   0%|                                                                                                                                                                         
pytorch_model-00001-of-00002.bin: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 9.98G/9.98G [09:17<00:00, 5.48MB/s]
pytorch_model-00001-of-00002.bin:  69%|█████████████████████████████████████████████████████████████████████████████████████████████████                                           | 6.92G/9.98G [58:47<35:10, 1.45MB/s]
pytorch_model-00001-of-00002.bin:  18%|████████████████████████▉                                                                                                                | 1.81G/9.98G [1:05:18<4:53:51, 463kB/s]
pytorch_model-00002-of-00002.bin: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3.50G/3.50G [10:40<00:00, 5.46MB/s]
Downloading shards: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [1:15:59<00:00, 2279.83s/it]
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:15<00:00,  7.54s/it]
generation_config.json: 100%|██████
USER:

Cela peut prendre plusieurs minutes pour que le chat soit prêt, car il doit d'abord télécharger le modèle. Même si la commande finit en erreur, si le modèle a été téléchargé, vous n'aurez plus à le télécharger la prochaine fois si vous relancez la commande.

Si vous avez une erreur de type: "PermissionError: [Errno 13] Permission denied: '/home/jiel/.cache/huggingface/hub/models--lmsys--vicuna-7b-v1.5'"

Ajustez les droits sur le cache puis relancez la commande précédente:

$ sudo chown -R $USER:$USER /home/$USER/.cache/huggingface/
$ python3 -m fastchat.serve.cli --model-path lmsys/vicuna-7b-v1.5

Si vous n'avez pas de processeur graphique (GPU) ou que vous avez une erreur du type "RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx", ou une erreur de mémoire, il existe une solution.

Alors ajoutez deux options à la fin de la commande. Cela indique à FastChat de n'utiliser que le processeur (CPU) mais pas le processeur graphique (GPU). Cependant, dans ce cas cela demande plusieurs dizaines de gigaoctets de mémoire. Si vous n'avez pas assez de mémoire, vous pouvez activer la compresssion 8 bits. Cela va réduire l'utilisation de la mémoire mais dégrader un peu la qualité du modèle. Vous verrez, le chat sera lent, mais fonctionnera très bien quand même!

$ python3 -m fastchat.serve.cli --model-path lmsys/vicuna-7b-v1.5 --device cpu --load-8bit

100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:44<00:00, 22.42s/it]
USER:

Vous pouvez commencer à discuter.


USER: do you like Linux?
ASSISTANT: As an artificial intelligence language model, I don't have personal preferences or feelings. However, I can provide information and answer questions about Linux if that's helpful.
USER: parles-tu français?
ASSISTANT: Oui, je parle français. Que puis-je faire pour vous aujourd'hui?
USER:

Dans cet exemple, on utilise le modèle Vicuna qui n'est pas libre (Llama 2 Community License Agreement).