Add placeholder for the `prepare_inputs_for_generation` method for compatibility with transformers>=4.50
#78
by
sylwia-kuros
- opened
- modeling_phi4mm.py +12 -0
- processing_phi4mm.py +1 -1
modeling_phi4mm.py
CHANGED
|
@@ -1932,6 +1932,15 @@ class Phi4MMModel(Phi4MMPreTrainedModel):
|
|
| 1932 |
)
|
| 1933 |
return causal_mask
|
| 1934 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1935 |
|
| 1936 |
class Phi4MMForCausalLM(Phi4MMPreTrainedModel, GenerationMixin):
|
| 1937 |
_tied_weights_keys = ["lm_head.weight"]
|
|
@@ -2134,6 +2143,9 @@ class Phi4MMForCausalLM(Phi4MMPreTrainedModel, GenerationMixin):
|
|
| 2134 |
|
| 2135 |
hidden_states = outputs[0]
|
| 2136 |
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
|
|
|
|
|
|
|
|
|
| 2137 |
logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
|
| 2138 |
|
| 2139 |
loss = None
|
|
|
|
| 1932 |
)
|
| 1933 |
return causal_mask
|
| 1934 |
|
| 1935 |
+
def prepare_inputs_for_generation():
|
| 1936 |
+
"""
|
| 1937 |
+
Placeholder for the `prepare_inputs_for_generation` method.
|
| 1938 |
+
|
| 1939 |
+
This function is part of the `GenerationMixin` and is added to the `Phi4MMModel`
|
| 1940 |
+
class to prevent the model from breaking due to the AttributeError.
|
| 1941 |
+
"""
|
| 1942 |
+
pass
|
| 1943 |
+
|
| 1944 |
|
| 1945 |
class Phi4MMForCausalLM(Phi4MMPreTrainedModel, GenerationMixin):
|
| 1946 |
_tied_weights_keys = ["lm_head.weight"]
|
|
|
|
| 2143 |
|
| 2144 |
hidden_states = outputs[0]
|
| 2145 |
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 2146 |
+
if num_logits_to_keep is None:
|
| 2147 |
+
num_logits_to_keep = hidden_states.size(1)
|
| 2148 |
+
|
| 2149 |
logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
|
| 2150 |
|
| 2151 |
loss = None
|
processing_phi4mm.py
CHANGED
|
@@ -506,7 +506,7 @@ class Phi4MMProcessor(ProcessorMixin):
|
|
| 506 |
image_processor_class = "AutoImageProcessor" # Phi4MMImageProcessor will be registered later
|
| 507 |
audio_processor_class = "AutoFeatureExtractor" # Phi4MMAudioFeatureExtractor will be registered later
|
| 508 |
|
| 509 |
-
def __init__(self, image_processor, audio_processor, tokenizer):
|
| 510 |
self.image_processor = image_processor
|
| 511 |
self.audio_processor = audio_processor
|
| 512 |
self.tokenizer = tokenizer
|
|
|
|
| 506 |
image_processor_class = "AutoImageProcessor" # Phi4MMImageProcessor will be registered later
|
| 507 |
audio_processor_class = "AutoFeatureExtractor" # Phi4MMAudioFeatureExtractor will be registered later
|
| 508 |
|
| 509 |
+
def __init__(self, image_processor, audio_processor, tokenizer, **kwargs):
|
| 510 |
self.image_processor = image_processor
|
| 511 |
self.audio_processor = audio_processor
|
| 512 |
self.tokenizer = tokenizer
|