Fix short-conv padding masking on transformers >=5

#1
Files changed (2) hide show
  1. README.md +7 -40
  2. modeling_lfm2_bidirectional.py +0 -4
README.md CHANGED
@@ -19,7 +19,6 @@ tags:
19
  - ColBERT
20
  - PyLate
21
  - sentence-transformers
22
- - multi-vector
23
  - sentence-similarity
24
  - feature-extraction
25
  pipeline_tag: sentence-similarity
@@ -27,7 +26,6 @@ library_name: PyLate
27
  license: other
28
  license_name: lfm1.0
29
  license_link: LICENSE
30
- base_model: LiquidAI/LFM2.5-350M-Base
31
  ---
32
 
33
  <center>
@@ -56,10 +54,7 @@ Both models are 350M params and the first bidirectional members of the LFM famil
56
 
57
  Find more details about the bidirectional architecture and training recipe in our [blog post](https://www.liquid.ai/blog/lfm2-5-retrievers).
58
 
59
- > [!NOTE]
60
- > 💻 **Demo**: https://huggingface.co/spaces/LiquidAI/colbert-tool-selection
61
-
62
- ![colb](https://cdn-uploads.huggingface.co/production/uploads/63f389fda096536aeaae0a66/snq-O6VmWRJNMYCNHGtDD.png)
63
 
64
  ## 📄 Model details
65
 
@@ -69,11 +64,13 @@ Find more details about the bidirectional architecture and training recipe in ou
69
  | **Total parameters** | ~353M | ~354M |
70
  | **Backbone** | [LFM2.5-350M-Base](https://huggingface.co/LiquidAI/LFM2.5-350M-Base) + bi-directional patches | [LFM2.5-350M-Base](https://huggingface.co/LiquidAI/LFM2.5-350M-Base) + bi-directional patches |
71
  | **Layers** | 17 (10 conv + 6 attn + 1 dense) | 17 (10 conv + 6 attn + 1 pool) |
 
72
  | **Vocabulary size** | 64,402 | 65,536 |
73
  | **Output** | 128-dim per token | 1024-dim CLS vector |
74
  | **Similarity** | MaxSim | Cosine |
75
  | **Training precision**| BF16 | BF16 |
76
  | **License** | LFM Open License v1.0 | LFM Open License v1.0 |
 
77
 
78
  **Document length:** 512 tokens &nbsp;&nbsp;
79
 
@@ -101,45 +98,15 @@ We recommend LFM2.5-Embedding-350M and LFM2.5-ColBERT-350M for short-context ret
101
 
102
  <a href="https://colab.research.google.com/drive/1uLswYrRTNw4P2P2qZ8JG-b8j-KDkQqwL?usp=sharing"><img src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/vlOyMEjwHa_b_LXysEu2E.png" width=120 alt="Colab link"></a>
103
 
104
- ### Using Sentence Transformers
105
-
106
- This model can be used as a multi-vector (ColBERT-style late interaction) retriever directly with [Sentence Transformers](https://www.sbert.net/) via the `MultiVectorEncoder`.
107
 
108
  ```bash
109
- pip install "sentence-transformers>=6.0.0"
110
- ```
111
-
112
- ```python
113
- from sentence_transformers import MultiVectorEncoder
114
-
115
- model = MultiVectorEncoder("LiquidAI/LFM2.5-ColBERT-350M", trust_remote_code=True)
116
-
117
- query = "Which planet is known as the Red Planet?"
118
- documents = [
119
- "Venus is often called Earth's twin because of its similar size and proximity.",
120
- "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
121
- "Jupiter, the largest planet in our solar system, has a prominent red spot.",
122
- "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
123
- ]
124
-
125
- query_embeddings = model.encode_query([query])
126
- document_embeddings = model.encode_document(documents)
127
- print(query_embeddings[0].shape, document_embeddings[0].shape)
128
- # (32, 128) (17, 128)
129
-
130
- # MaxSim late-interaction scoring (the Mars document ranks highest)
131
- scores = model.similarity(query_embeddings, document_embeddings)
132
- print(scores)
133
- # tensor([[27.1621, 28.2578, 27.7266, 28.1992]])
134
  ```
135
 
136
- ### Using PyLate
137
 
138
- Use this model with PyLate to index and retrieve documents. The index uses [FastPLAID](https://github.com/lightonai/fast-plaid) for efficient similarity search. First, install PyLate and transformers:
139
-
140
- ```bash
141
- pip install -U pylate
142
- ```
143
 
144
  #### Indexing documents
145
 
 
19
  - ColBERT
20
  - PyLate
21
  - sentence-transformers
 
22
  - sentence-similarity
23
  - feature-extraction
24
  pipeline_tag: sentence-similarity
 
26
  license: other
27
  license_name: lfm1.0
28
  license_link: LICENSE
 
29
  ---
30
 
31
  <center>
 
54
 
55
  Find more details about the bidirectional architecture and training recipe in our [blog post](https://www.liquid.ai/blog/lfm2-5-retrievers).
56
 
57
+ ![colbert_retrieval](https://cdn-uploads.huggingface.co/production/uploads/63f389fda096536aeaae0a66/8J_3tsS-wDq77qeDpDgOd.png)
 
 
 
58
 
59
  ## 📄 Model details
60
 
 
64
  | **Total parameters** | ~353M | ~354M |
65
  | **Backbone** | [LFM2.5-350M-Base](https://huggingface.co/LiquidAI/LFM2.5-350M-Base) + bi-directional patches | [LFM2.5-350M-Base](https://huggingface.co/LiquidAI/LFM2.5-350M-Base) + bi-directional patches |
66
  | **Layers** | 17 (10 conv + 6 attn + 1 dense) | 17 (10 conv + 6 attn + 1 pool) |
67
+ | **Context length** | 32,768 tokens | 32,768 tokens |
68
  | **Vocabulary size** | 64,402 | 65,536 |
69
  | **Output** | 128-dim per token | 1024-dim CLS vector |
70
  | **Similarity** | MaxSim | Cosine |
71
  | **Training precision**| BF16 | BF16 |
72
  | **License** | LFM Open License v1.0 | LFM Open License v1.0 |
73
+ | **Architecture** | <img src="https://cdn-uploads.huggingface.co/production/uploads/63f389fda096536aeaae0a66/neXdblhfapp1Oln8M9J4V.png" width="250">| <img src="https://cdn-uploads.huggingface.co/production/uploads/63f389fda096536aeaae0a66/y4Lx5eS3hZCRv1g3r1e9i.png" width="250"> |
74
 
75
  **Document length:** 512 tokens &nbsp;&nbsp;
76
 
 
98
 
99
  <a href="https://colab.research.google.com/drive/1uLswYrRTNw4P2P2qZ8JG-b8j-KDkQqwL?usp=sharing"><img src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/vlOyMEjwHa_b_LXysEu2E.png" width=120 alt="Colab link"></a>
100
 
101
+ First, install the PyLate and transformers libraries:
 
 
102
 
103
  ```bash
104
+ pip install -U pylate
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  ```
106
 
107
+ ### Retrieval
108
 
109
+ Use this model with PyLate to index and retrieve documents. The index uses [FastPLAID](https://github.com/lightonai/fast-plaid) for efficient similarity search.
 
 
 
 
110
 
111
  #### Indexing documents
112
 
modeling_lfm2_bidirectional.py CHANGED
@@ -71,11 +71,7 @@ def _noncausal_shortconv_forward(
71
  past_key_values=None,
72
  cache_position=None,
73
  attention_mask: Optional[torch.Tensor] = None,
74
- **kwargs,
75
  ) -> torch.Tensor:
76
- # transformers >=5.x passes seq_idx (packed-sample conv-state reset) to the conv. This full
77
- # sequence non-causal conv has no cache and no packing, so it is ignored, like the cache args
78
- # above. **kwargs absorbs it and any future additions rather than breaking on each new one.
79
  # Only the flash_attention_2 path expects padding states zeroed before the
80
  # conv. On eager/sdpa the checkpoints were trained WITHOUT zeroing: under
81
  # transformers 4.56 the conv received the 4D additive mask, on which
 
71
  past_key_values=None,
72
  cache_position=None,
73
  attention_mask: Optional[torch.Tensor] = None,
 
74
  ) -> torch.Tensor:
 
 
 
75
  # Only the flash_attention_2 path expects padding states zeroed before the
76
  # conv. On eager/sdpa the checkpoints were trained WITHOUT zeroing: under
77
  # transformers 4.56 the conv received the 4D additive mask, on which