Feature Extraction
sentence-transformers
Safetensors
Transformers
qwen3
text-generation
splade
sparse-encoder
code
custom_code
text-embeddings-inference
Run this model with HF Jobs
Run naver/splade-code-8B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/naver/splade-code-8B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/naver/splade-code-8B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use naver/splade-code-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use naver/splade-code-8B with sentence-transformers:
from sentence_transformers import SparseEncoder model = SparseEncoder("naver/splade-code-8B", 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-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="naver/splade-code-8B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("naver/splade-code-8B", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("naver/splade-code-8B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Patch loading SparseEncoder from Hub (#2)
Browse files- Patch loading SparseEncoder from Hub (ebcd7f425e4d05f421138d56ce1a06a0dfc7d5ef)
- Move adapters back to LoRA to avoid inconvenient auto-PEFT trigger (0cf3c13ddf40fb955f6bad5368dcf419f1fb07bb)
- Use snapshot_download to avoid PEFT Windows issue (c7dfa2772eda14c97bfd94b9330d83637a00d735)
Files changed (3)
5 unmodified lines678910111213141516171819202118 unmodified lines4041424344454647484950515253545556575859606162636465662 unmodified lines69707172737475767750 unmodified lines1281291301311321331345 unmodified lines1. Sentence Transformers: `SparseEncoder("naver/splade-code-8B", trust_remote_code=True)` via AutoModelForMaskedLM -> Qwen3ForCausalLM2. Transformers: `AutoModelForCausalLM.from_pretrained("naver/splade-code-8B", trust_remote_code=True)` -> SpladeThe checkpoint is distributed as a LoRA adapter on top of Qwen/Qwen3-8B; `Qwen3ForCausalLM.from_pretrained`loads the base model and applies the adapter."""import torchfrom transformers import Qwen3ForCausalLM as TransformersQwen3ForCausalLMfrom transformers import PretrainedConfig, PreTrainedModel, AutoConfigfrom transformers.utils import is_flash_attn_2_availablefrom .utils import prepare_tokenizer, splade_max, similarity, encodeclass Qwen3ForCausalLM(TransformersQwen3ForCausalLM):def tie_weights(self, *args, **kwargs):18 unmodified lines@classmethoddef from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):from peft import PeftConfig, PeftModeltry:peft_config = PeftConfig.from_pretrained(pretrained_model_name_or_path, token=kwargs.get("token"))except Exception:peft_config = Noneif peft_config is None:return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)# Use provided splade config (has is_causal=False) or load it from the adapter repoconfig = kwargs.pop("config", None)if config is None or not isinstance(config, PretrainedConfig):config = AutoConfig.from_pretrained(pretrained_model_name_or_path, token=kwargs.get("token"))# We apply the adapter manually below, so drop any auto-PEFT hints to avoid double loadingkwargs.pop("adapter_kwargs", None)base_model = super().from_pretrained(peft_config.base_model_name_or_path,2 unmodified lines**kwargs,)return PeftModel.from_pretrained(base_model, pretrained_model_name_or_path, token=kwargs.get("token"))class SpladeConfig(PretrainedConfig):50 unmodified lines)def save_pretrained(self, save_directory, *args, **kwargs):self.model.save_pretrained(save_directory)self.config.save_pretrained(save_directory)@classmethod5 unmodified lines6789101112131415161718192021222324252627282918 unmodified lines4849505152535455565758596061626364656667686970717273747576777879802 unmodified lines8384858687888950 unmodified lines1401411421431441451465 unmodified lines1. Sentence Transformers: `SparseEncoder("naver/splade-code-8B", trust_remote_code=True)` via AutoModelForMaskedLM -> Qwen3ForCausalLM2. Transformers: `AutoModelForCausalLM.from_pretrained("naver/splade-code-8B", trust_remote_code=True)` -> SpladeThe checkpoint is distributed as a LoRA adapter on top of Qwen/Qwen3-8B in the `lora/` subfolder;`Qwen3ForCausalLM.from_pretrained` loads the base model and applies the adapter."""import osimport torchfrom transformers import Qwen3ForCausalLM as TransformersQwen3ForCausalLMfrom transformers import PretrainedConfig, PreTrainedModel, AutoConfigfrom transformers.utils import is_flash_attn_2_availablefrom .utils import prepare_tokenizer, splade_max, similarity, encode# The adapter lives in this subfolder rather than at the repo root so that# `find_adapter_config_file` doesn't trigger transformers' auto-PEFT path,# which would otherwise redirect hub loads to `Qwen/Qwen3-8B` and lose the# `auto_map` routing to the classes in this file.ADAPTER_SUBFOLDER = "lora"class Qwen3ForCausalLM(TransformersQwen3ForCausalLM):def tie_weights(self, *args, **kwargs):18 unmodified lines@classmethoddef from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):from huggingface_hub import snapshot_downloadfrom peft import PeftConfig, PeftModeltoken = kwargs.get("token")# Resolve the adapter to a local path before handing it to PEFT.# PEFT's `subfolder=` kwarg uses `os.path.join` on Windows, producing# backslashed hub paths that break the safetensors-vs-bin fallback.if os.path.isdir(pretrained_model_name_or_path):adapter_path = os.path.join(pretrained_model_name_or_path, ADAPTER_SUBFOLDER)else:local_repo = snapshot_download(pretrained_model_name_or_path,allow_patterns=[f"{ADAPTER_SUBFOLDER}/*"],token=token,)adapter_path = os.path.join(local_repo, ADAPTER_SUBFOLDER)if not os.path.isfile(os.path.join(adapter_path, "adapter_config.json")):return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)peft_config = PeftConfig.from_pretrained(adapter_path, token=token)# Use provided splade config (has is_causal=False) or load it from the adapter repoconfig = kwargs.pop("config", None)if config is None or not isinstance(config, PretrainedConfig):config = AutoConfig.from_pretrained(pretrained_model_name_or_path, token=token)base_model = super().from_pretrained(peft_config.base_model_name_or_path,2 unmodified lines**kwargs,)return PeftModel.from_pretrained(base_model, adapter_path, token=token)class SpladeConfig(PretrainedConfig):50 unmodified lines)def save_pretrained(self, save_directory, *args, **kwargs):self.model.save_pretrained(os.path.join(save_directory, ADAPTER_SUBFOLDER))self.config.save_pretrained(save_directory)@classmethod
adapter_config.json → lora/adapter_config.jsonRenamed
adapter_model.safetensors → lora/adapter_model.safetensorsRenamed
splade.py+30-18