Eine vollständig enthaltene, sofort einsatzbereite Umgebung zur Feinabstimmung des Llama 3-Modells mit benutzerdefinierten Datensätzen und zur Ausführung von Inferenzen auf den fein abgestimmten Modellen
Hinweis: Bisher wurde dies nur auf NVIDIA RTX 2080- und NVIDIA Tesla T4-GPUs getestet. Es wurde nicht mit den anderen GPU-Klassen oder auf CPUs getestet.
Führen Sie diesen Befehl auf Ihrem Hostcomputer aus, um zu überprüfen, welche Nvidia-GPU Sie installiert haben.
nvidia-smi
Daraufhin sollten Ihre GPU-Informationen angezeigt werden.
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.171.04 Driver Version: 535.171.04 CUDA Version: 12.2 |
| -----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
| =========================================+======================+====================== |
| 0 NVIDIA GeForce RTX 2080 Off | 00000000:01:00.0 On | N/A |
| 22% 38C P8 17W / 215W | 197MiB / 8192MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
git clone https://github.com/amithkoujalgi/llama3-playground.git
cd llama3-playground
bash build.sh
bash run.sh
Dadurch wird der Docker-Container mit den folgenden Diensten gestartet.
Service | Von außen erreichbarer Endpunkt | Interner Port | Beschreibung |
---|---|---|---|
Aufsicht | http://localhost:8884 | 9001 | Zum Ausführen von Schulungen für benutzerdefinierte Datensätze und zum Anzeigen von Protokollen des Trainerprozesses |
FastAPI-Server | http://localhost:8883/docs | 8070 | Für den Zugriff auf APIs des Modellservers |
JupyterLab-Server | http://localhost:8888/lab | 8888 | Greifen Sie auf die JupyterLab-Schnittstelle zu, um den Container zu durchsuchen und den Code zu aktualisieren/experimentieren |
Hinweis : Alle Prozesse (OCR, Training und Inferenz) nutzen die GPU und wenn mehr als ein Prozess jeglicher Art gleichzeitig ausgeführt würde, würden Probleme mit unzureichendem Arbeitsspeicher (OOM) auftreten. Um dies zu bewältigen, wurde das System so konzipiert, dass es zu einem bestimmten Zeitpunkt nur einen Prozess ausführt. (d. h. es kann jeweils nur eine Instanz von OCR oder Training oder Inferenz ausgeführt werden)
Sie können den Code jederzeit entsprechend Ihren Anforderungen aktualisieren.
Gehen Sie zum Terminal und geben Sie ein
playground --train
Gehen Sie zum Terminal und geben Sie ein
playground -l
Dadurch werden Modelle unter /app/data/trained-models/
erstellt. Das Trainerskript erzeugt zwei Modelle:
lora-adapters
trägt.OCR ausführen:
cd /app/llama3_playground/core
python ocr.py
-f " /app/sample.pdf "
Um zu verstehen, was die Optionen bedeuten, gehen Sie zu JupyterLab und führen Sie python ocr.py -h
aus
Schlussfolgerung mit RAG:
cd /app/llama3_playground/core
python infer_rag.py
-m " llama-3-8b-instruct-custom-1720802202 "
-d " /app/data/ocr-runs/123/text-result.txt "
-q " What is the employer name, address, telephone, TIN, tax year end, type of business, plan name, Plan Sequence Number, Trust ID, Account number, is it a new plan or existing plan as true or false, are elective deferrals and roth deferrals allowed as true or false, are loans permitted as true or false, are life insurance investments permitted and what is the ligibility Service Requirement selected? "
-t 256
-e " Alibaba-NLP/gte-base-en-v1.5 "
-p " There are checkboxes in the text that denote the value as selected if the text is [Yes], and unselected if the text is [No]. The checkbox option's value can either be before the selected value or after. Keep this in context while responding and be very careful and precise in picking these values. Always respond as JSON. Keep the responses precise and concise. "
Um zu verstehen, was die Optionen bedeuten, gehen Sie zu JupyterLab und führen Sie python infer_rag.py -h
aus
Dies ist erforderlich, wenn auf Ihrem Hostcomputer kein NVIDIA Container Toolkit installiert ist.
# Configure the production repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |
sed ' s#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g ' |
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Optionally, configure the repository to use experimental packages
sed -i -e ' /experimental/ s/^#//g ' /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Update the packages list from the repository
sudo apt-get update
# Install the NVIDIA Container Toolkit packages
sudo apt-get install -y nvidia-container-toolkit
Informationen zu anderen Umgebungen finden Sie hier.
curl --silent -X ' POST '
' http://localhost:8883/api/infer/sync/ctx-text '
-H ' accept: application/json '
-H ' Content-Type: application/json '
-d ' {
"model_name": "llama-3-8b-instruct-custom-1720690384",
"context_data": "You are a magician who goes by the name Magica",
"question_text": "Who are you?",
"prompt_text": "Respond in a musical and Shakespearean tone",
"max_new_tokens": 50
} ' | jq -r " .data.response "
curl -X ' POST '
' http://localhost:8883/api/ocr/sync/pdf '
-H ' accept: application/json '
-H ' Content-Type: multipart/form-data '
-F ' file=@your_file.pdf;type=application/pdf '
true
zurück, wenn ein OCR-Prozess ausgeführt wird, andernfalls false
. curl -X ' GET '
' http://localhost:8883/api/ocr/status '
-H ' accept: application/json '
Referenzen: