Views
No views yet
bfloat16)transformers напрямую, необходимо самостоятельно усреднить (mean-pool) по не-паддинговым токенам и затем применить L2-нормализацию (см. пример ниже). В примерах для sentence-transformers и vLLM это делается автоматически. Сравнивайте эмбеддинги через косинусную близость (скалярное произведение нормированных векторов).Instruct: {описание задачи}
Query: {ваш текст}transformers и pytorch могут вызывать незначительные, но ненулевые различия в результатах.bfloat16)transformers directly, you must mean-pool over non-padding tokens yourself and then L2-normalize (see the example below). The sentence-transformers and vLLM examples do this for you. Compare embeddings with cosine similarity (dot product of normalized vectors).Instruct: {task description}
Query: {your text}transformers and pytorch libraries can cause small but non-zero differences in results.| Benchmark | Giga-Embeddings-instruct-480M-0826 | Qwen3-Embedding-0.6B | EmbeddingGemma-300M | FRIDA-820M |
|---|---|---|---|---|
| MTEB (rus, v1.1) | 70.98 | 63.64 | 64.02 | 70.95 |
| MTEB (eng, v2) | 69.52 | 70.70 | 69.67 | — |
| MTEB (code, v1) | 72.87 | 75.41 | 68.76 | — |
| MTEB (multilingual, v2) | 56.97 | 64.33 | 61.15 | — |
1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer(
4 "ai-sage/Giga-Embeddings-instruct-480M-0826",
5 trust_remote_code=True, # needed for the bidirectional modeling code
6)
7
8instruction = "Given a query, retrieve relevant passages"
9queries = [f"Instruct: {instruction}\nQuery: Где столица России?"]
10documents = ["Москва — столица Российской Федерации.",
11 "Париж — столица Франции."]
12
13q_emb = model.encode(queries, normalize_embeddings=True)
14d_emb = model.encode(documents, normalize_embeddings=True)
15print(model.similarity(q_emb, d_emb))1import torch
2import torch.nn.functional as F
3from transformers import AutoModel, AutoTokenizer
4
5path = "ai-sage/Giga-Embeddings-instruct-480M-0826"
6tok = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
7model = AutoModel.from_pretrained(path, trust_remote_code=True,
8 dtype=torch.bfloat16).cuda().eval()
9
10def encode(texts):
11 enc = tok(texts, return_tensors="pt", padding=True, truncation=True, max_length=512)
12 enc = {k: v.cuda() for k, v in enc.items()}
13 with torch.no_grad():
14 hidden = model(**enc).last_hidden_state
15 mask = enc["attention_mask"].unsqueeze(-1).to(hidden.dtype)
16 emb = (hidden * mask).sum(1) / mask.sum(1).clamp(min=1e-6) # mean pool
17 return F.normalize(emb, dim=-1) # L2 normalize
18
19instr = "Given a query, retrieve relevant passages"
20q = encode([f"Instruct: {instr}\nQuery: Где столица России?"])
21d = encode(["Москва — столица Российской Федерации.", "Париж — столица Франции."])
22print((q @ d.T).cpu())is_causal=false; no custom code is required on the vLLM side.1from vllm import LLM
2from vllm.config import PoolerConfig
3
4llm = LLM(
5 model="ai-sage/Giga-Embeddings-instruct-480M-0826",
6 runner="pooling",
7 convert="embed",
8 hf_overrides={"is_causal": False, "architectures": ["Qwen3ForCausalLM"]},
9 pooler_config=PoolerConfig(pooling_type="MEAN", use_activation=True),
10 trust_remote_code=True,
11)
12
13instr = "Given a query, retrieve relevant passages"
14outs = llm.encode([f"Instruct: {instr}\nQuery: Где столица России?",
15 "Москва — столица Российской Федерации."],
16 pooling_task="embed")
17embs = [o.outputs.data for o in outs]1vllm serve ai-sage/Giga-Embeddings-instruct-480M-0826 \
2 --runner pooling --convert embed \
3 --hf-overrides '{"is_causal": false, "architectures": ["Qwen3ForCausalLM"]}' \
4 --override-pooler-config '{"pooling_type": "MEAN", "use_activation": true}' \
5 --trust-remote-codeQwen3BidirectionalModel architecture used by
ai-sage/Giga-Embeddings-instruct-480M-0826.feat/qwen3-bidirectional-embedding on fork Lossfull/sglang604a3634d235b11dcf4abd4bc012cfa1f7bde43bOnce the PR is merged this whole guide collapses to "use a recent SGLang release." Until then, use one of the two methods below.
1# 1. Start the verified image (its SGLang is editable at /sgl-workspace/sglang).
2docker run --gpus all -it --shm-size 16g \
3 -p 30000:30000 \
4 -v ~/.cache/huggingface:/root/.cache/huggingface \
5 --entrypoint /bin/bash \
6 lmsysorg/sglang:nightly-dev-20260818-c0b6474b
7
8# --- everything below runs INSIDE the container ---
9
10# 2. Download the PR diff.
11curl -fL -H "Accept: application/vnd.github.v3.diff" \
12 -o /tmp/pr35531.diff \
13 https://api.github.com/repos/sgl-project/sglang/pulls/35531
14
15# 3. Apply it onto the image's editable source tree (takes effect immediately).
16cd /sgl-workspace/sglang
17git apply -v /tmp/pr35531.diff # or: patch -p1 < /tmp/pr35531.diff
18
19# 4. Sanity check: the new architecture must resolve to the native class.
20python3 -c "from sglang.srt.models.registry import ModelRegistry; \
21c,a=ModelRegistry.resolve_model_cls('Qwen3BidirectionalModel'); \
22print('OK:', a, '->', c.__module__)"
23# Expect: OK: Qwen3BidirectionalModel -> sglang.srt.models.qwen3_embedding1# Clone the PR branch (or the exact commit).
2git clone https://github.com/Lossfull/sglang.git
3cd sglang
4git checkout feat/qwen3-bidirectional-embedding
5# Optional: pin the exact reviewed commit
6# git checkout 604a3634d235b11dcf4abd4bc012cfa1f7bde43b
7
8# Install SGLang + all runtime deps (compiles/pulls sgl-kernel, flashinfer, ...).
9pip install --upgrade pip
10pip install -e "python[all]"1python3 -m sglang.launch_server \
2 --model-path ai-sage/Giga-Embeddings-instruct-480M-0826 \
3 --is-embedding \
4 --trust-remote-code \
5 --host 0.0.0.0 --port 30000--is-embedding — serve as an embedding model (the arch is auto-classified as
non-generative anyway, but this is explicit and safe).--trust-remote-code — required (custom config class in the checkpoint).--tp-size N if you want to shard across GPUs.The server is fired up and ready to roll!1curl -s http://localhost:30000/v1/embeddings \
2 -H "Content-Type: application/json" \
3 -d '{
4 "model": "ai-sage/Giga-Embeddings-instruct-480M-0826",
5 "input": "What is the capital of France?"
6 }' | python3 -c "import sys,json; d=json.load(sys.stdin); \
7e=d['data'][0]['embedding']; print('dim:', len(e), 'first5:', e[:5])"