بيئة متكاملة وجاهزة للتشغيل لضبط نموذج Llama 3 باستخدام مجموعة بيانات مخصصة وتشغيل الاستدلال على النماذج المضبوطة بدقة
ملحوظة: تم اختبار هذا فقط على وحدات معالجة الرسوميات NVIDIA RTX 2080 وNVIDIA Tesla T4 حتى الآن. ولم يتم اختباره مع فئات GPU الأخرى أو على وحدات المعالجة المركزية (CPUs).
قم بتشغيل هذا الأمر على جهازك المضيف للتحقق من وحدة معالجة الرسومات Nvidia التي قمت بتثبيتها.
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 | للوصول إلى واجهات برمجة التطبيقات الخاصة بالخادم النموذجي |
خادم جوبيتيرلاب | http://localhost:8888/lab | 8888 | قم بالوصول إلى واجهة JupyterLab لتصفح الحاوية وتحديث/تجربة الكود |
ملاحظة : تستخدم جميع العمليات (التعرف الضوئي على الحروف والتدريب والاستدلال) وحدة معالجة الرسومات وإذا تم تشغيل أكثر من عملية من أي نوع في وقت واحد، فسنواجه مشكلات نفاد الذاكرة (OOM). ولمعالجة ذلك، تم تصميم النظام لتشغيل عملية واحدة فقط في أي وقت محدد. (على سبيل المثال، يمكن تشغيل مثيل واحد فقط من التعرف الضوئي على الحروف أو التدريب أو الاستدلال في المرة الواحدة)
لا تتردد في تحديث الكود وفقًا لاحتياجاتك.
انتقل إلى المحطة واكتب
playground --train
انتقل إلى المحطة واكتب
playground -l
يؤدي هذا إلى إنتاج نماذج ضمن /app/data/trained-models/
. ينتج البرنامج النصي للمدرب نموذجين:
lora-adapters
.تشغيل التعرف الضوئي على الحروف:
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 '
مراجع: