Feature Extraction
sentence-transformers
Safetensors
Transformers
qwen3
text-generation
splade
sparse-encoder
code
custom_code
text-embeddings-inference
Instructions to use naver/splade-code-06B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use naver/splade-code-06B with sentence-transformers:
from sentence_transformers import SparseEncoder model = SparseEncoder("naver/splade-code-06B", trust_remote_code=True) queries = ["Which planet is known as the Red Planet?"] documents = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", ] query_embeddings = model.encode_query(queries) document_embeddings = model.encode_document(documents) similarities = model.similarity(query_embeddings, document_embeddings) print(similarities) - Transformers
How to use naver/splade-code-06B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="naver/splade-code-06B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("naver/splade-code-06B", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("naver/splade-code-06B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Tom Aarsen commited on
Commit ·
c4c1b0e
1
Parent(s): d71d855
Attempt to fix meta tensor loading error
Browse files- modeling_splade.py +22 -2
modeling_splade.py
CHANGED
|
@@ -3,6 +3,26 @@ This file exists solely to allow loading the Qwen3ForCausalLM via the AutoModelF
|
|
| 3 |
Compared to standard Qwen3, we're using bidirectional attention and not causal attention, but it's specified
|
| 4 |
with `is_causal=False` in the config.
|
| 5 |
"""
|
| 6 |
-
from transformers import Qwen3ForCausalLM
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
Compared to standard Qwen3, we're using bidirectional attention and not causal attention, but it's specified
|
| 4 |
with `is_causal=False` in the config.
|
| 5 |
"""
|
|
|
|
| 6 |
|
| 7 |
+
from transformers import Qwen3ForCausalLM as _Qwen3ForCausalLM
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Qwen3ForCausalLM(_Qwen3ForCausalLM):
|
| 11 |
+
def tie_weights(self, *args, **kwargs):
|
| 12 |
+
"""Explicitly re-tie lm_head to embed_tokens to hopefully avoid meta tensor errors."""
|
| 13 |
+
super().tie_weights(*args, **kwargs)
|
| 14 |
+
if (
|
| 15 |
+
self.config.tie_word_embeddings
|
| 16 |
+
and hasattr(self, "lm_head")
|
| 17 |
+
and hasattr(self, "model")
|
| 18 |
+
):
|
| 19 |
+
self.lm_head.weight = self.model.embed_tokens.weight
|
| 20 |
+
|
| 21 |
+
def _init_weights(self, module):
|
| 22 |
+
"""Skip lm_head init when it will be tied to embed_tokens later."""
|
| 23 |
+
if module is getattr(self, "lm_head", None) and self.config.tie_word_embeddings:
|
| 24 |
+
return
|
| 25 |
+
super()._init_weights(module)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
__all__ = ["Qwen3ForCausalLM"]
|