Mình đã cài đặt thành công môi trường và thư viện.
github.com/username/safety-intent-linear-probes
py-0p # show all versions of python on PC
py-3.11--version # check if Python 3.11 available on PC
nvidia-smi # check driver status
Tạo môi trường khép kín (venv)
py -3.11 -m venv .venv
Kích hoạt môi trường
.\.venv\Scripts\Activate.ps1
Kiểm tra lại
where.exe python
Đường dẫn sẽ có dạng sau
...\safety-probes-under-shift\.venv\Scripts\python.exe
Cài thêm các thư viện
python -m pip install transformers accelerate safetensors sentencepiece pandas numpy scikit-learn matplotlib seaborn jupyter ipykernel tqdm
Cập nhật pip
python -m pip install --upgrade pip
Cài đặt thêm PyTorch có CUDA
python -m pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
Hiện tại mình chưa hiểu ý nghĩa của các thư viện nhưng sẽ học sau.
.gitignoreĐảm bảo file.gitignore có đủ các mục sau:
.venv/
__pycache__/
*.pyc
.ipynb_checkpoints/
Viết file python nhỏ như sau:
import torch, transformers, pandas, sklearn, matplotlib
print('All imports successful')
print('GPU:', torch.cuda.get_device_name(0))
Nếu xuất hiện như sau thì đã thành công
All imports successful
GPU: NVIDIA GeForce RTX 3060
from transformers import pipeline
chatbot = pipeline(
"text-generation",
model="Qwen/Qwen2.5-0.5B-Instruct", # model will be automaticlly downloaded
device=0, #put at GPU0 - RTX 3060 - 12GB - Which is in my computer
)
content = input("Enter input: ")
messages = [
{
"role": "user",
"content": content,
}
]
result = chatbot(
messages,
max_new_tokens=50,
do_sample=False,
)
answer = "AI: " + result[0]["generated_text"][-1]["content"]
content = "User: " + content
print("\n\n")
print(content)
print(answer)
Nhìn chung là đã load được model để chạy.
Loading comments...