Skip to content

Commit df7b01c

Browse files
Flux2TextEncoder.forward: forward return_dict + cache_position via kwargs
Address gemini-code-assist review comment on PR #1434 (#1434). The previous patch captured return_dict and cache_position in the forward signature (for backward compat with older transformers versions where they were positional) but didn't forward them to super().forward(). For 5.8+ callers explicitly passing these args, they would be silently dropped. Now forwarded the same way as output_hidden_states / output_attentions: via kwargs.setdefault so explicit kwargs in the call still win, and None values don't pollute **kwargs. In transformers 5.8 these two are no-ops (return_dict always True; cache_position computed internally), so forwarding them only matters for older transformers versions -- but it's the correct behavior either way, and a cheap fix.
1 parent cb3ef91 commit df7b01c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

diffsynth/models/flux2_text_encoder.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,19 @@ def __init__(self):
5555

5656
def forward(self, input_ids = None, pixel_values = None, attention_mask = None, position_ids = None, past_key_values = None, inputs_embeds = None, labels = None, use_cache = None, output_attentions = None, output_hidden_states = None, return_dict = None, cache_position = None, logits_to_keep = 0, image_sizes = None, **kwargs):
5757
# transformers 5.8 trimmed Mistral3's positional args; pass everything
58-
# as kwargs so the call survives across transformers versions. The dropped
59-
# output_hidden_states / output_attentions are still honored via
60-
# TransformersKwargs -> forward them through **kwargs.
58+
# as kwargs so the call survives across transformers versions. Forward
59+
# the four removed-from-positional args through **kwargs (transformers
60+
# 5.8 honors output_hidden_states / output_attentions via
61+
# TransformersKwargs; return_dict / cache_position are no-ops in 5.8
62+
# but forwarded so older transformers versions still receive them).
6163
if output_hidden_states is not None:
6264
kwargs.setdefault("output_hidden_states", output_hidden_states)
6365
if output_attentions is not None:
6466
kwargs.setdefault("output_attentions", output_attentions)
67+
if return_dict is not None:
68+
kwargs.setdefault("return_dict", return_dict)
69+
if cache_position is not None:
70+
kwargs.setdefault("cache_position", cache_position)
6571
return super().forward(
6672
input_ids=input_ids,
6773
pixel_values=pixel_values,

0 commit comments

Comments
 (0)