사용자 정의 데이터세트로 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/
아래에 모델을 생성합니다. 트레이너 스크립트는 두 가지 모델을 생성합니다.
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
반환하고, 그렇지 않으면 false
반환합니다. curl -X ' GET '
' http://localhost:8883/api/ocr/status '
-H ' accept: application/json '
참고자료: