Skip to content

Commit 3788fea

Browse files
artemspectorclaude
andcommitted
granite4_vision: replace unbound forward call with self.language_model()
The Granite4VisionTextModel.forward(self.language_model, ...) pattern was added to bypass nn.Module.__call__ overhead, but compare_implementations shows no measurable difference (1.05x total vs card, within noise). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: artemspector <artems@il.ibm.com>
1 parent fa6bd19 commit 3788fea

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

src/transformers/models/granite4_vision/modeling_granite4_vision.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,7 @@ def forward(
10451045
inputs_embeds = inputs_embeds.masked_fill(vision_mask, 0.0)
10461046
deepstack_features[llm_layer_idx] = concat_features
10471047

1048-
# Bypass nn.Module.__call__ overhead by calling the unbound forward directly.
1049-
# nn.Module.__call__ has non-trivial per-call overhead that accumulates across 40 layers × N steps.
1050-
outputs = Granite4VisionTextModel.forward(
1051-
self.language_model,
1048+
outputs = self.language_model(
10521049
input_ids=None,
10531050
inputs_embeds=inputs_embeds,
10541051
attention_mask=attention_mask,

src/transformers/models/granite4_vision/modular_granite4_vision.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,7 @@ def forward(
704704
inputs_embeds = inputs_embeds.masked_fill(vision_mask, 0.0)
705705
deepstack_features[llm_layer_idx] = concat_features
706706

707-
# Bypass nn.Module.__call__ overhead by calling the unbound forward directly.
708-
# nn.Module.__call__ has non-trivial per-call overhead that accumulates across 40 layers × N steps.
709-
outputs = Granite4VisionTextModel.forward(
710-
self.language_model,
707+
outputs = self.language_model(
711708
input_ids=None,
712709
inputs_embeds=inputs_embeds,
713710
attention_mask=attention_mask,

0 commit comments

Comments
 (0)