Lingkungan yang lengkap dan siap dijalankan untuk menyempurnakan model Llama 3 dengan kumpulan data khusus dan menjalankan inferensi pada model yang telah disempurnakan
Catatan: Sejauh ini ini hanya diuji pada GPU NVIDIA RTX 2080 dan NVIDIA Tesla T4. Ini belum diuji dengan kelas GPU lain atau pada CPU.
Jalankan perintah ini di mesin host Anda untuk memeriksa GPU Nvidia mana yang telah Anda instal.
nvidia-smi
Itu akan menampilkan informasi GPU Anda.
+---------------------------------------------------------------------------------------+
| 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
Ini memulai kontainer Docker dengan layanan berikut.
Melayani | Titik akhir yang dapat diakses secara eksternal | Pelabuhan Dalam | Keterangan |
---|---|---|---|
Pengawas | http://localhost:8884 | 9001 | Untuk menjalankan pelatihan pada kumpulan data khusus dan melihat log proses pelatih |
Server API Cepat | http://localhost:8883/docs | 8070 | Untuk mengakses API server model |
Server JupyterLab | http://localhost:8888/lab | 8888 | Akses antarmuka JupyterLab untuk menjelajahi container dan memperbarui/bereksperimen dengan kode |
Catatan : Semua proses (OCR, pelatihan, dan inferensi) menggunakan GPU dan jika lebih dari satu proses jenis apa pun dijalankan secara bersamaan, kami akan mengalami masalah kehabisan memori (OOM). Untuk mengatasinya, sistem telah dirancang untuk menjalankan hanya satu proses pada suatu titik waktu tertentu. (yaitu, Hanya satu contoh OCR atau pelatihan atau inferensi yang dapat dijalankan dalam satu waktu)
Jangan ragu untuk memperbarui kode sesuai kebutuhan Anda.
Pergi ke terminal dan ketik
playground --train
Pergi ke terminal dan ketik
playground -l
Ini menghasilkan model di bawah /app/data/trained-models/
. Skrip pelatih menghasilkan 2 model:
lora-adapters
.Jalankan OCR:
cd /app/llama3_playground/core
python ocr.py
-f " /app/sample.pdf "
Untuk memahami arti opsi, buka JupyterLab dan jalankan python ocr.py -h
Inferensi dengan 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. "
Untuk memahami arti opsi, buka JupyterLab dan jalankan python infer_rag.py -h
Ini diperlukan jika Anda belum menginstal NVIDIA Container Toolkit di mesin host Anda.
# 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
Untuk lingkungan lain, lihat ini.
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
jika ada proses OCR yang berjalan, false
jika sebaliknya. curl -X ' GET '
' http://localhost:8883/api/ocr/status '
-H ' accept: application/json '
Referensi: