Update modeling_minicpmv.py
Browse files- modeling_minicpmv.py +9 -1
modeling_minicpmv.py
CHANGED
|
@@ -288,16 +288,24 @@ class MiniCPMV(MiniCPMVPreTrainedModel):
|
|
| 288 |
|
| 289 |
# Step 2: Automatically pad each tensor to have the same length (L) in the last dimension
|
| 290 |
attention_mask = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
for tensor in batch:
|
| 292 |
to_add = []
|
| 293 |
for pl in range(tensor.shape[1]):
|
| 294 |
to_add.append(1)
|
| 295 |
for pl in range(tensor.shape[1], max_x):
|
|
|
|
| 296 |
to_add.append(0)
|
| 297 |
attention_mask.append(to_add)
|
| 298 |
attention_mask = torch.tensor(attention_mask)
|
| 299 |
|
| 300 |
-
padded_tensors = [torch.nn.functional.pad(tensor, (0, 0, 0, max_x - tensor.shape[1]), padding_value=0.0) for tensor in batch]
|
| 301 |
|
| 302 |
# Step 3: Stack the padded tensors into a single batch
|
| 303 |
for stuff in batch:
|
|
|
|
| 288 |
|
| 289 |
# Step 2: Automatically pad each tensor to have the same length (L) in the last dimension
|
| 290 |
attention_mask = []
|
| 291 |
+
|
| 292 |
+
embedding_layer = self.get_input_embeddings()
|
| 293 |
+
|
| 294 |
+
# Retrieve the embedding vector for pad_token_id
|
| 295 |
+
pad_embedding_vector = embedding_layer.weight[0]
|
| 296 |
+
vector_reshaped = pad_embedding_vector.view(1, 1, 10)
|
| 297 |
+
|
| 298 |
for tensor in batch:
|
| 299 |
to_add = []
|
| 300 |
for pl in range(tensor.shape[1]):
|
| 301 |
to_add.append(1)
|
| 302 |
for pl in range(tensor.shape[1], max_x):
|
| 303 |
+
tensor = torch.cat((tensor, vector_reshaped), dim=1)
|
| 304 |
to_add.append(0)
|
| 305 |
attention_mask.append(to_add)
|
| 306 |
attention_mask = torch.tensor(attention_mask)
|
| 307 |
|
| 308 |
+
# padded_tensors = [torch.nn.functional.pad(tensor, (0, 0, 0, max_x - tensor.shape[1]), padding_value=0.0) for tensor in batch]
|
| 309 |
|
| 310 |
# Step 3: Stack the padded tensors into a single batch
|
| 311 |
for stuff in batch:
|