|
26 | 26 | from .. import AutoTokenizer, MistralModel, PretrainedConfig, PretrainedModel |
27 | 27 | from ..model_outputs import BaseModelOutputWithPast, ModelOutput |
28 | 28 |
|
| 29 | +__all__ = ["NVEncodeModel"] |
| 30 | + |
29 | 31 |
|
30 | 32 | @dataclass |
31 | 33 | class EncoderOutput(ModelOutput): |
@@ -121,7 +123,7 @@ def forward(self, last_hidden_states, pool_mask): |
121 | 123 | one = paddle.eye( |
122 | 124 | num_rows=self.config.hidden_size, |
123 | 125 | num_columns=self.config.hidden_size, |
124 | | - dtype=str(self.latents.weight.dtype).split(".")[-1], |
| 126 | + dtype=self.latents.weight.dtype, |
125 | 127 | ) |
126 | 128 | self_latents_weight_T = self.latents(one).T |
127 | 129 | # latents = repeat(self_latents_weight_T, "d h -> b d h", b=last_hidden_states.shape[0]) # from einops import repeat |
@@ -206,7 +208,8 @@ def __init__( |
206 | 208 | self.latent_model = LatentModel(config=config) # get latent model structure |
207 | 209 |
|
208 | 210 | self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, padding_side="right") |
209 | | - self.tokenizer.pad_token = self.tokenizer.eos_token |
| 211 | + if self.tokenizer.pad_token is None: |
| 212 | + self.tokenizer.pad_token = self.tokenizer.eos_token |
210 | 213 |
|
211 | 214 | self.query_instruction = query_instruction |
212 | 215 | self.document_instruction = document_instruction |
@@ -495,6 +498,7 @@ def encode_sentences(self, sentences: List[str], instruction_len, **kwargs) -> n |
495 | 498 | sentences_batch, |
496 | 499 | max_length=4096, |
497 | 500 | padding=True, |
| 501 | + return_attention_mask=True, |
498 | 502 | return_token_type_ids=False, |
499 | 503 | return_tensors="pd", |
500 | 504 | truncation=True, |
|
0 commit comments