5060Ti 本地文本嵌入模型(Qwen/Qwen3-Embedding-0.6B)测试
C:\Users\Administrator.cache\huggingface\hub\models--Qwen--Qwen3-Embedding-0.6B
uv pip install torch==2.11.0+cu128 --index-url https://download.pytorch.org/whl/cu128
Looking in indexes: https://download.pytorch.org/whl/cu128
本地环境(关键依赖包)
tokenizers 0.22.2
torch 2.11.0+cu128
torchaudio 2.11.0+cu128
torchvision 0.26.0+cu128
sentence-transformers 5.5.1
huggingface-hub 1.18.0
测试代码
"""Qwen3-Embedding-0.6B GPU 嵌入测试"""
import torch
from sentence_transformers import SentenceTransformer, util
if not torch.cuda.is_available():
raise SystemExit("CUDA 不可用,请先安装 CUDA 版 PyTorch。")
sentences = [
"今天天气很好,适合出去散步。",
"今天阳光不错,我想去公园走走。",
"PyTorch 是一个非常流行的深度学习框架。",
"这台电脑的显卡支持 CUDA。",
]
print("GPU:", torch.cuda.get_device_name(0))
model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B", device="cuda")
emb = model.encode(sentences, normalize_embeddings=True, convert_to_tensor=True)
print(f"Embedding shape: {tuple(emb.shape)}")
print("Embedding device:", emb.device, "\n")
print("Cosine 相似度矩阵:")
print(util.cos_sim(emb, emb).float().cpu().numpy().round(3))
GPU: NVIDIA GeForce RTX 5060 Ti
Loading weights: 100%|██████████| 310/310 [00:00<00:00, 10285.61it/s]
Embedding shape: (4, 1024)
Embedding device: cuda:0
Cosine 相似度矩阵:
[[1. 0.766 0.256 0.303]
[0.766 0.996 0.246 0.256]
[0.256 0.246 1. 0.438]
[0.303 0.256 0.438 1. ]]
学而不思则罔,思而不学则殆!

浙公网安备 33010602011771号