สภาพแวดล้อมที่ครบครันและพร้อมใช้งานเพื่อปรับแต่งโมเดล Llama 3 ด้วยชุดข้อมูลที่กำหนดเอง และเรียกใช้การอนุมานบนโมเดลที่ได้รับการปรับแต่งอย่างละเอียด
หมายเหตุ: จนถึงขณะนี้การทดสอบนี้ใช้กับ NVIDIA RTX 2080 และ NVIDIA Tesla T4 GPU เท่านั้น ยังไม่ได้รับการทดสอบกับคลาส GPU อื่นๆ หรือบน CPU
เรียกใช้คำสั่งนี้บนเครื่องโฮสต์ของคุณเพื่อตรวจสอบว่าคุณได้ติดตั้ง Nvidia GPU ตัวใด
nvidia-smi
นั่นควรแสดงข้อมูล 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
สิ่งนี้จะเริ่มต้นคอนเทนเนอร์ Docker ด้วยบริการต่อไปนี้
บริการ | ปลายทางที่สามารถเข้าถึงได้จากภายนอก | พอร์ตภายใน | คำอธิบาย |
---|---|---|---|
หัวหน้างาน | http://localhost:8884 | 9001 | สำหรับการรันการฝึกอบรมบนชุดข้อมูลที่กำหนดเองและการดูบันทึกของกระบวนการเทรนเนอร์ |
เซิร์ฟเวอร์ FastAPI | http://localhost:8883/docs | 8070 | สำหรับการเข้าถึง API ของเซิร์ฟเวอร์โมเดล |
เซิร์ฟเวอร์ JupyterLab | http://localhost:8888/lab | 8888 | เข้าถึงอินเทอร์เฟซ JupyterLab เพื่อเรียกดูคอนเทนเนอร์และอัปเดต/ทดลองโค้ด |
หมายเหตุ : กระบวนการทั้งหมด (OCR, การฝึกอบรม และการอนุมาน) ใช้ GPU และหากมีการเรียกใช้กระบวนการประเภทใดก็ตามมากกว่าหนึ่งกระบวนการพร้อมกัน เราจะพบปัญหาหน่วยความจำไม่เพียงพอ (OOM) เพื่อจัดการกับสิ่งนั้น ระบบได้รับการออกแบบให้รันเพียงกระบวนการเดียว ณ จุดใดเวลาหนึ่ง (เช่น สามารถรัน OCR หรือการฝึกอบรมหรือการอนุมานได้ครั้งละหนึ่งอินสแตนซ์เท่านั้น)
อย่าลังเลที่จะอัปเดตโค้ดตามความต้องการของคุณ
ไปที่เทอร์มินัลแล้วพิมพ์
playground --train
ไปที่เทอร์มินัลแล้วพิมพ์
playground -l
สิ่งนี้สร้างโมเดลภายใต้ /app/data/trained-models/
สคริปต์เทรนเนอร์สร้าง 2 รุ่น:
lora-adapters
เรียกใช้ OCR:
cd /app/llama3_playground/core
python ocr.py
-f " /app/sample.pdf "
เพื่อทำความเข้าใจความหมายของตัวเลือกต่างๆ ให้ไปที่ JupyterLab และดำเนินการ python ocr.py -h
การอนุมานด้วย 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. "
เพื่อทำความเข้าใจความหมายของตัวเลือกต่างๆ ให้ไปที่ JupyterLab และดำเนินการ python infer_rag.py -h
สิ่งนี้จำเป็นหากคุณไม่ได้ติดตั้ง NVIDIA Container Toolkit บนเครื่องโฮสต์ของคุณ
# 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
สำหรับสภาพแวดล้อมอื่น โปรดดูสิ่งนี้
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
หากกระบวนการ OCR ใด ๆ กำลังทำงานอยู่ false
ฉะนั้นจะคืนค่าเป็นเท็จ curl -X ' GET '
' http://localhost:8883/api/ocr/status '
-H ' accept: application/json '
อ้างอิง: