Un entorno completo y listo para ejecutar para ajustar el modelo Llama 3 con un conjunto de datos personalizado y ejecutar inferencias en los modelos ajustados.
Nota: Hasta el momento, esto solo se ha probado en las GPU NVIDIA RTX 2080 y NVIDIA Tesla T4. No se ha probado con otras clases de GPU ni en CPU.
Ejecute este comando en su máquina host para verificar qué GPU Nvidia ha instalado.
nvidia-smi
Eso debería mostrar la información de tu GPU.
+---------------------------------------------------------------------------------------+
| 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
Esto inicia el contenedor Docker con los siguientes servicios.
Servicio | Punto final accesible externamente | Puerto interno | Descripción |
---|---|---|---|
Supervisor | http://localhost:8884 | 9001 | Para ejecutar capacitación en un conjunto de datos personalizado y ver registros del proceso del entrenador |
Servidor FastAPI | http://localhost:8883/docs | 8070 | Para acceder a las API del servidor modelo |
Servidor JupyterLab | http://localhost:8888/lab | 8888 | Acceda a la interfaz de JupyterLab para explorar el contenedor y actualizar/experimentar con el código. |
Nota : Todos los procesos (OCR, entrenamiento e inferencia) utilizan GPU y si se ejecutara más de un proceso de cualquier tipo simultáneamente, encontraríamos problemas de falta de memoria (OOM). Para manejar esto, el sistema ha sido diseñado para ejecutar solo un proceso en un momento dado. (es decir, solo se puede ejecutar una instancia de OCR o entrenamiento o inferencia a la vez)
No dude en actualizar el código según sus necesidades.
Vaya a la terminal y escriba
playground --train
Vaya a la terminal y escriba
playground -l
Esto produce modelos en /app/data/trained-models/
. El script del entrenador produce 2 modelos:
lora-adapters
.Ejecute OCR:
cd /app/llama3_playground/core
python ocr.py
-f " /app/sample.pdf "
Para comprender qué significan las opciones, vaya a JupyterLab y ejecute python ocr.py -h
Inferencia con 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. "
Para comprender qué significan las opciones, vaya a JupyterLab y ejecute python infer_rag.py -h
Esto sería necesario si no tiene NVIDIA Container Toolkit instalado en su máquina host.
# 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
Para otros entornos, consulte esto.
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
si se está ejecutando algún proceso de OCR; false
en caso contrario. curl -X ' GET '
' http://localhost:8883/api/ocr/status '
-H ' accept: application/json '
Referencias: