Skip to content

[Fix] Fix get_flops crash for SAN model - #3875

Open
Selig209 wants to merge 1 commit into
open-mmlab:dev-1.xfrom
Selig209:fix/san-get-flops
Open

[Fix] Fix get_flops crash for SAN model#3875
Selig209 wants to merge 1 commit into
open-mmlab:dev-1.xfrom
Selig209:fix/san-get-flops

Conversation

@Selig209

Copy link
Copy Markdown

Running get_flops.py on a SAN config crashes with:

TypeError: SideAdapterCLIPHead.forward() missing 1 required positional argument: 'deep_supervision_idxs'

The issue is that MultimodalEncoderDecoder._forward() passes only backbone features to decode_head.forward(x), but SideAdapterCLIPHead.forward() expects a (imgs, clip_features, class_embeds) triplet and a deep_supervision_idxs arg.

Fixed _forward() to match the encode_decode() path — runs both text encoder and image encoder, passes the full triplet. Also added SAN to the unsupported guard in get_flops.py since the text encoder FLOPs aren't captured by the tracing.

Fixes #3866

Copilot AI review requested due to automatic review settings April 25, 2026 23:29
@CLAassistant

CLAassistant commented Apr 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash when running tools/analysis_tools/get_flops.py on SAN configs by aligning MultimodalEncoderDecoder._forward() with the multimodal encode_decode() path (image encoder + text encoder + triplet input to the decode head), and adds an explicit “unsupported” guard for SAN in the FLOPs script.

Changes:

  • Update MultimodalEncoderDecoder._forward() to run text+image encoding and pass [inputs, clip_features, class_embeds] to the decode head.
  • Add a SAN (SideAdapterCLIPHead) unsupported check in get_flops.py with a NotImplementedError.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tools/analysis_tools/get_flops.py Adds a guard to short-circuit FLOPs computation for SAN.
mmseg/models/segmentors/multimodal_encoder_decoder.py Changes tensor-mode forward to use multimodal inputs compatible with SAN’s decode head.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +229 to +235
classifier_embeds = self.text_encoder()
clip_inputs = inputs
if self.asymetric_input:
clip_inputs = F.interpolate(
inputs, scale_factor=self.encoder_resolution, mode='bilinear')
x = self.image_encoder(clip_inputs)
return self.decode_head.forward([inputs, x, classifier_embeds], [])

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MultimodalEncoderDecoder._forward() now always calls decode_head.forward(..., []) with a second positional arg. This breaks decode heads whose forward() only accepts a single inputs argument (e.g. the ExampleDecodeHead used in tests/test_models/test_segmentors/test_multimodal_encoder_decoder.py), causing mode='tensor' to raise a TypeError. Consider branching based on the decode head type/signature (e.g., only pass deep_supervision_idxs for SideAdapterCLIPHead/SAN), and otherwise call decode_head.forward(multimodal_inputs) with one argument.

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +90
# SAN requires text encoder outputs that _forward() doesn't provide
raise NotImplementedError(
'SAN is not supported yet. See #3866')

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new SAN guard comment is now inaccurate: after this PR, _forward() does run the text encoder and passes the [inputs, clip_features, class_embeds] triplet into the decode head. If SAN is still intentionally unsupported in get_flops.py due to FLOPs undercounting/tracing limitations, please update the comment and the NotImplementedError message to reflect the real limitation (e.g., tracing/caching makes FLOPs incomplete) rather than implying _forward() lacks required inputs.

Suggested change
# SAN requires text encoder outputs that _forward() doesn't provide
raise NotImplementedError(
'SAN is not supported yet. See #3866')
# SAN is intentionally unsupported here because FLOPs analysis can be
# incomplete for SideAdapterCLIPHead: tracing/caching behavior may
# undercount work even though _forward() provides the required inputs.
raise NotImplementedError(
'SAN FLOPs are not supported in get_flops.py because '
'tracing/caching can make the computation incomplete. '
'See #3866')

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants