Mateusz Mróz commited on
Commit ·
df23e97
1
Parent(s): b1740b7
test1
Browse files- modeling_florence2.py +12 -8
modeling_florence2.py
CHANGED
|
@@ -2201,18 +2201,22 @@ class Florence2LanguageForConditionalGeneration(Florence2LanguagePreTrainedModel
|
|
| 2201 |
):
|
| 2202 |
# cut decoder_input_ids if past_key_values is used
|
| 2203 |
if past_key_values is not None:
|
|
|
|
| 2204 |
if not isinstance(past_key_values, tuple):
|
| 2205 |
past_key_values = tuple(past_key_values)
|
| 2206 |
-
past_length = past_key_values[0][0].shape[2]
|
| 2207 |
|
| 2208 |
-
#
|
| 2209 |
-
if
|
| 2210 |
-
|
| 2211 |
-
else:
|
| 2212 |
-
# Default to old behavior: keep only final ID
|
| 2213 |
-
remove_prefix_length = decoder_input_ids.shape[1] - 1
|
| 2214 |
|
| 2215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2216 |
|
| 2217 |
return {
|
| 2218 |
"input_ids": None, # encoder_outputs is defined. input_ids not needed
|
|
|
|
| 2201 |
):
|
| 2202 |
# cut decoder_input_ids if past_key_values is used
|
| 2203 |
if past_key_values is not None:
|
| 2204 |
+
# Dodatkowe zabezpieczenie na wypadek, gdyby `past_key_values` nie było krotką
|
| 2205 |
if not isinstance(past_key_values, tuple):
|
| 2206 |
past_key_values = tuple(past_key_values)
|
|
|
|
| 2207 |
|
| 2208 |
+
# Sprawdzamy, czy wewnętrzne elementy nie są None, zanim uzyskamy do nich dostęp
|
| 2209 |
+
if past_key_values[0] is not None and past_key_values[0][0] is not None:
|
| 2210 |
+
past_length = past_key_values[0][0].shape[2]
|
|
|
|
|
|
|
|
|
|
| 2211 |
|
| 2212 |
+
# Some generation methods already pass only the last input ID
|
| 2213 |
+
if decoder_input_ids.shape[1] > past_length:
|
| 2214 |
+
remove_prefix_length = past_length
|
| 2215 |
+
else:
|
| 2216 |
+
# Default to old behavior: keep only final ID
|
| 2217 |
+
remove_prefix_length = decoder_input_ids.shape[1] - 1
|
| 2218 |
+
|
| 2219 |
+
decoder_input_ids = decoder_input_ids[:, remove_prefix_length:]
|
| 2220 |
|
| 2221 |
return {
|
| 2222 |
"input_ids": None, # encoder_outputs is defined. input_ids not needed
|