Update modeling_minicpmv.py
Browse files- modeling_minicpmv.py +16 -17
modeling_minicpmv.py
CHANGED
|
@@ -297,25 +297,24 @@ class MiniCPMV(MiniCPMVPreTrainedModel):
|
|
| 297 |
vector_reshaped = pad_embedding_vector.view(1, 1, 4096)
|
| 298 |
|
| 299 |
for place, tensor in enumerate(batch):
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
# tensor = tensor.to(self.device)
|
| 313 |
-
# if bound != 0:
|
| 314 |
-
# print(tensor[0,bound-1], " BOUND")
|
| 315 |
-
# print(tensor[0,bound], " OTHERSIDE")
|
| 316 |
-
# print(pad_embedding_vector, " VECTOR")
|
| 317 |
print(tensor.shape, "UPDATED_SHAPE")
|
|
|
|
|
|
|
| 318 |
batch[place] = tensor
|
|
|
|
|
|
|
| 319 |
attention_mask.append(to_add)
|
| 320 |
|
| 321 |
attention_mask = torch.tensor(attention_mask)
|
|
|
|
| 297 |
vector_reshaped = pad_embedding_vector.view(1, 1, 4096)
|
| 298 |
|
| 299 |
for place, tensor in enumerate(batch):
|
| 300 |
+
# Calculate how much padding is needed on the left
|
| 301 |
+
padding_needed = max_x - tensor.shape[1]
|
| 302 |
+
|
| 303 |
+
# Create the list for the attention mask, marking the padded tokens
|
| 304 |
+
to_add = [0] * padding_needed + [1] * tensor.shape[1]
|
| 305 |
+
|
| 306 |
+
# Create the padding tensor of the correct size
|
| 307 |
+
padding_tensor = vector_reshaped.expand(tensor.shape[0], padding_needed, tensor.shape[2])
|
| 308 |
+
|
| 309 |
+
# Concatenate the padding tensor to the left of the original tensor
|
| 310 |
+
tensor = torch.cat((padding_tensor, tensor), dim=1)
|
| 311 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
print(tensor.shape, "UPDATED_SHAPE")
|
| 313 |
+
|
| 314 |
+
# Update the batch with the padded tensor
|
| 315 |
batch[place] = tensor
|
| 316 |
+
|
| 317 |
+
# Append the attention mask for this tensor
|
| 318 |
attention_mask.append(to_add)
|
| 319 |
|
| 320 |
attention_mask = torch.tensor(attention_mask)
|