Repository navigation
Description
- Did you update?
pip install --upgrade unsloth unsloth_zoo
Yes — freshpip install unslothon a clean Colab runtime (2026-07-04), resolved to unsloth 2026.6.9 + paired unsloth_zoo. ColaborKaggleor local / cloud
Colab (Pro).- Number GPUs used, use
nvidia-smi
1× NVIDIA L4 (22 GB). Also reproduced identically on T4. - Which notebook? Please link!
Custom notebook following the official embedding recipe from the sentence-transformers × Unsloth integration docs (https://sbert.net/examples/sentence_transformer/training/unsloth/README.html). The bug reproduces at LOAD/INFERENCE time, before any training — minimal repro below needs no notebook. - Which Unsloth version, TRL version, transformers version, PyTorch version?
unsloth 2026.6.9, transformers 5.5.0, torch 2.10.0+cu128, sentence-transformers 5.x, Triton 3.6.0, CUDA 12.8. TRL: not used. - Which trainer?
SFTTrainer,GRPOTraineretc
None — the defect is inFastSentenceTransformer.from_pretrainedinference output itself (planned trainer wasSentenceTransformerTrainer, never reached).
Summary
Loading Qwen/Qwen3-Embedding-0.6B through FastSentenceTransformer produces
embeddings that are materially different from a plain sentence_transformers
load of the same checkpoint, costing ~14 recall points on our retrieval eval.
No error or warning is emitted — the model loads and runs, just worse.
Measured on a private domain-specific retrieval benchmark (267 short French
product-description queries against a ~13k-document taxonomy corpus; metric =
recall of the ground-truth category):
| Load path | recall@10 | @30 | @50 | @100 | @200 | never-in-top-200 |
|---|---|---|---|---|---|---|
SentenceTransformer('Qwen/Qwen3-Embedding-0.6B') |
35.2 | 49.4 | 54.3 | 62.9 | 74.9 | 25.1% |
FastSentenceTransformer (same checkpoint) |
22.8–23.6 | 33.0–34.5 | 39.3–40.4 | 47.6–49.4 | 57.3–60.3 | ~40–42% |
Both measured in the same Colab session (plain ST first, before importing
unsloth), identical eval code, identical data, L4 GPU.
Environment
- unsloth 2026.6.9, unsloth_zoo (paired), transformers 5.5.0, sentence-transformers 5.x
- torch 2.10.0+cu128, CUDA 12.8, Triton 3.6.0
- NVIDIA L4 (Colab), bf16 supported
Repro
# 1) control — plain sentence-transformers (BEFORE importing unsloth)
from sentence_transformers import SentenceTransformer
ctrl = SentenceTransformer('Qwen/Qwen3-Embedding-0.6B', device='cuda')
ctrl.max_seq_length = 256
e_ref = ctrl.encode(['roasted chickpeas in 20 kg bags'], normalize_embeddings=True)[0]
print(e_ref[:8])
# 2) unsloth — restart runtime, then:
from unsloth import FastSentenceTransformer
model = FastSentenceTransformer.from_pretrained(
'Qwen/Qwen3-Embedding-0.6B',
max_seq_length=256, load_in_4bit=False, full_finetuning=False)
e_u = model.encode(['roasted chickpeas in 20 kg bags'], normalize_embeddings=True)[0]
print(e_u[:8])
# e_u differs from e_ref far beyond bf16 jitter — component signs/magnitudes
# visibly diverge (we measured this on our own strings; any text reproduces it).Variables eliminated (all tested, none change the outcome)
load_in_4bit=Falseexplicitly (anddtype=torch.float32)max_seq_length160 vs 256- Pooling config: loads correctly as
lasttoken(verified viamodel[1].get_config_dict()) - Tokenization:
<|endoftext|>(151643) correctly appended as final token
(note: unsloth swapstokenizer.eos_token_idto 151645<|im_end|>, but the
encoded inputs are correct) tokenizer.padding_sideleft vs right: no change- Batch contamination: same text encoded alone vs in a 64-text padded batch,
cosine = 0.9999 — corruption is per-text deterministic, not masking/padding - xformers uninstalled (SDPA fallback): no change
UNSLOTH_COMPILE_DISABLE=1: no changeUNSLOTH_HIGH_PRECISION_LAYERNORM=1+UNSLOTH_FORCE_FLOAT32=1+
dtype=torch.float32: no change (runs 2.6× slower, so the flags engaged) —
rules out kernel numeric precision- Both
Qwen/Qwen3-Embedding-0.6Band theunsloth/Qwen3-Embedding-0.6Bmirror
Structural anomaly found
The wrapped backbone (model[0].auto_model) has no final RMSNorm module:
[n for n, _ in model[0].auto_model.named_modules()
if 'norm' in n.lower() and 'layers' not in n] # -> []
# stock Qwen3Model tree is: embed_tokens -> layers.0..27 -> norm
# here: embed_tokens -> layers.0..27 (top-level `norm` missing; 425 modules total)The checkpoint's norm.weight exists. Manually applying the final RMSNorm
(weights loaded from the safetensors) to last_hidden_state does NOT reproduce
the reference embedding either — so the hidden states diverge somewhere before/
besides the final norm. The missing module suggests the compiled rewrite fuses
the final norm into the (unused, return_logits=False) LM-head epilogue, and
the feature-extraction path returns hidden states from a differently-structured
forward.
Why this matters / severity
For generation these differences are mostly invisible; for embedding models the
hidden state IS the product, and cosine ranking amplifies any drift. The failure
mode is silent — users fine-tuning embedders on top of this get degraded models
with no error. Suggest: a parity test (plain-ST vs FastSentenceTransformer
embedding cosine on a fixed string set) in CI for decoder-style embedding models
(relates to the per-model drift coverage in #6740).
Happy to provide the full eval harness or run candidate fixes.
Activity
InfoSage05 commentedon Jul 5, 2026
@Afnisse I have made PR for this issue ie #6886. Please have a look at it.
Afnisse commentedon Jul 5, 2026
thanks @rehan243 , but normalize_embeddings isn't a from_pretrained kwarg, tokenization/padding were ruled out (see "Variables eliminated"), and the actual cause is the swallowed auto_model param — see #6886.
fix: use PyTorch QK norm for embedding models to match stock HF preci…
Etherll commentedon Jul 6, 2026
Weirdly, this only happens in Colab; it works fine locally. So, I will investigate more, thanks alot.
fix: keep UNSLOTH_EMBEDDING_HIGH_PRECISION active + guard CausalLM-on…
Etherll commentedon Jul 7, 2026
Should be fixed in #6939 can you check ?
Tighten unslothai#6881 comments and docstrings
Fix FastSentenceTransformer Qwen embedding preprocessing (#6939)
Etherll commentedon Jul 10, 2026
Thanks alot for the issue, this should be fixed in unsloth main