Skip to content

[Bug] FastSentenceTransformer silently degrades Qwen3-Embedding quality (recall@50: 54.3 → 39.7 on our eval) #6881

Closed

Description

@Afnisse
  1. Did you update? pip install --upgrade unsloth unsloth_zoo
    Yes — fresh pip install unsloth on a clean Colab runtime (2026-07-04), resolved to unsloth 2026.6.9 + paired unsloth_zoo.
  2. Colab or Kaggle or local / cloud
    Colab (Pro).
  3. Number GPUs used, use nvidia-smi
    1× NVIDIA L4 (22 GB). Also reproduced identically on T4.
  4. 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.
  5. 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.
  6. Which trainer? SFTTrainer, GRPOTrainer etc
    None — the defect is in FastSentenceTransformer.from_pretrained inference output itself (planned trainer was SentenceTransformerTrainer, 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=False explicitly (and dtype=torch.float32)
  • max_seq_length 160 vs 256
  • Pooling config: loads correctly as lasttoken (verified via model[1].get_config_dict())
  • Tokenization: <|endoftext|> (151643) correctly appended as final token
    (note: unsloth swaps tokenizer.eos_token_id to 151645 <|im_end|>, but the
    encoded inputs are correct)
  • tokenizer.padding_side left 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 change
  • UNSLOTH_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.6B and the unsloth/Qwen3-Embedding-0.6B mirror

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

  1. InfoSage05 commented on Jul 5, 2026

    @InfoSage05
    Contributor

    @Afnisse I have made PR for this issue ie #6886. Please have a look at it.

  2. Afnisse commented on Jul 5, 2026

    @Afnisse
    Author

    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.

  3. Etherll commented on Jul 6, 2026

    @Etherll
    Collaborator

    Weirdly, this only happens in Colab; it works fine locally. So, I will investigate more, thanks alot.

  4. added a commit that references this issue on Jul 7, 2026
    e5a94f5
  5. self-assigned this
    on Jul 7, 2026
  6. Etherll commented on Jul 7, 2026

    @Etherll
    Collaborator

    Should be fixed in #6939 can you check ?

  7. Etherll commented on Jul 10, 2026

    @Etherll
    Collaborator

    Thanks alot for the issue, this should be fixed in unsloth main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions