Views
No views yet
bnb_4bit_quant_type: "nf4"bnb_4bit_use_double_quant: Truebnb_4bit_compute_dtype: float161from transformers import AutoTokenizer, AutoModel
2import torch
3
4model_name = "dinhhungitsoft/Qwen3-Embedding-4B-bnb4"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModel.from_pretrained(
7 model_name,
8 trust_remote_code=True,
9 device_map="auto"
10)
11
12def embed(texts):
13 inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt", max_length=512)
14 inputs = {k: v.to(model.device) for k, v in inputs.items()}
15
16 with torch.no_grad():
17 outputs = model(**inputs)
18 embeddings = outputs.last_hidden_state[:, 0, :] # CLS token
19
20 # Normalize embeddings
21 embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)
22 return embeddings.cpu().numpy()
23
24texts = ["Hà Nội là thủ đô của Việt Nam", "Paris is the capital of France"]
25embeddings = embed(texts)
26print(embeddings.shape) # (2, embedding_dim)1docker run -d \
2 --gpus all \
3 -v ~/.cache/huggingface:/root/.cache/huggingface \
4 -p 8000:8000 \
5 --ipc=host \
6 vllm/vllm-openai:latest \
7 --model dinhhungitsoft/Qwen3-Embedding-4B-bnb4 \
8 --trust-remote-code \
9 --gpu-memory-utilization 0.6 \
10 --max-model-len 40961import requests
2
3response = requests.post(
4 "http://localhost:8000/v1/embeddings",
5 json={
6 "model": "dinhhungitsoft/Qwen3-Embedding-4B-bnb4",
7 "input": ["Your text here"]
8 }
9)
10embeddings = response.json()["data"][0]["embedding"]1@article{qwen3,
2 title={Qwen3 Technical Report},
3 author={Qwen Team},
4 year={2024}
5}