Feature Extraction
sentence-transformers
ONNX
Safetensors
multilingual
bidirectional_pplx_qwen3
sentence-similarity
mteb
custom_code
text-embeddings-inference
Instructions to use perplexity-ai/pplx-embed-v1-0.6b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use perplexity-ai/pplx-embed-v1-0.6b with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("perplexity-ai/pplx-embed-v1-0.6b", trust_remote_code=True) sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Fix create_causal_mask kwarg: input_embeds -> inputs_embeds
#13
by maximilian-schall-ppx - opened
- modeling.py +23 -14
modeling.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from typing import Callable
|
| 2 |
import torch
|
| 3 |
from transformers import Qwen3Model
|
|
@@ -8,6 +9,16 @@ from transformers.processing_utils import Unpack
|
|
| 8 |
from transformers.utils import TransformersKwargs
|
| 9 |
from .configuration import PPLXQwen3Config
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# From modeling_t5gemma.py
|
| 13 |
def bidirectional_mask_function(attention_mask: torch.Tensor | None) -> Callable:
|
|
@@ -54,21 +65,19 @@ class PPLXQwen3Model(Qwen3Model):
|
|
| 54 |
inputs_embeds = self.embed_tokens(input_ids)
|
| 55 |
input_ids = None
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
"
|
| 63 |
-
|
| 64 |
-
input_embeds=inputs_embeds,
|
| 65 |
-
attention_mask=attention_mask,
|
| 66 |
-
cache_position=dummy_cache_position,
|
| 67 |
-
past_key_values=None,
|
| 68 |
-
position_ids=position_ids,
|
| 69 |
-
or_mask_function=bidirectional_mask_function(attention_mask),
|
| 70 |
-
)
|
| 71 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
outputs = super().forward(
|
| 74 |
input_ids=input_ids,
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
from typing import Callable
|
| 3 |
import torch
|
| 4 |
from transformers import Qwen3Model
|
|
|
|
| 9 |
from transformers.utils import TransformersKwargs
|
| 10 |
from .configuration import PPLXQwen3Config
|
| 11 |
|
| 12 |
+
# The transformers `create_causal_mask` signature has shifted over releases:
|
| 13 |
+
# * <= 5.1: kwarg is `input_embeds`, `cache_position` is required positional
|
| 14 |
+
# * 5.2 - 5.5: renamed to `inputs_embeds`, `cache_position` still required
|
| 15 |
+
# * 5.6 - 5.8: `cache_position` has a default (kept for BC)
|
| 16 |
+
# * >= 5.9: `cache_position` removed entirely
|
| 17 |
+
# Detect once at import time which names this transformers exposes.
|
| 18 |
+
_CCM_PARAMS = inspect.signature(create_causal_mask).parameters
|
| 19 |
+
_CCM_EMBEDS_KEY = "inputs_embeds" if "inputs_embeds" in _CCM_PARAMS else "input_embeds"
|
| 20 |
+
_CCM_ACCEPTS_CACHE_POSITION = "cache_position" in _CCM_PARAMS
|
| 21 |
+
|
| 22 |
|
| 23 |
# From modeling_t5gemma.py
|
| 24 |
def bidirectional_mask_function(attention_mask: torch.Tensor | None) -> Callable:
|
|
|
|
| 65 |
inputs_embeds = self.embed_tokens(input_ids)
|
| 66 |
input_ids = None
|
| 67 |
|
| 68 |
+
mask_kwargs = {
|
| 69 |
+
"config": self.config,
|
| 70 |
+
_CCM_EMBEDS_KEY: inputs_embeds,
|
| 71 |
+
"attention_mask": attention_mask,
|
| 72 |
+
"past_key_values": None,
|
| 73 |
+
"position_ids": position_ids,
|
| 74 |
+
"or_mask_function": bidirectional_mask_function(attention_mask),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}
|
| 76 |
+
if _CCM_ACCEPTS_CACHE_POSITION:
|
| 77 |
+
mask_kwargs["cache_position"] = torch.arange(
|
| 78 |
+
inputs_embeds.shape[1], device=inputs_embeds.device, dtype=torch.long
|
| 79 |
+
)
|
| 80 |
+
attention_mask = {"full_attention": create_causal_mask(**mask_kwargs)}
|
| 81 |
|
| 82 |
outputs = super().forward(
|
| 83 |
input_ids=input_ids,
|