phh commited on
Commit
bc541d0
·
verified ·
1 Parent(s): a11e830

Make Phi4MMForCausalLM.forward's num_logits_to_keep actually optional

Browse files

Fixes:
```
File "/home/phh/.cache/huggingface/modules/transformers_modules/microsoft/Phi-4-multimodal-instruct/a11e830f953efbce02a57d3b672f84c5140e3f94/modeling_phi4mm.py", line 2137, in forward
logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
^^^^^^^^^^^^^^^^^^^
TypeError: bad operand type for unary -: 'NoneType'
```

Files changed (1) hide show
  1. modeling_phi4mm.py +4 -1
modeling_phi4mm.py CHANGED
@@ -2134,7 +2134,10 @@ 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
2140
  if labels is not None:
 
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
+ if num_logits_to_keep:
2138
+ logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
2139
+ else:
2140
+ logits = self.lm_head(hidden_states)
2141
 
2142
  loss = None
2143
  if labels is not None: