Skip to content

Add GroupViT to NormalizedConfigManager; fix NormalizedTextAndVisionConfig attribute resolution - #2513

Open
kratos0718 wants to merge 1 commit into
huggingface:mainfrom
kratos0718:add-groupvit-normalized-config
Open

kratos0718 wants to merge 1 commit into
huggingface:mainfrom
kratos0718:add-groupvit-normalized-config

Conversation

@kratos0718

Copy link
Copy Markdown

Summary

Part of #351. GroupViT already has an ONNX export config but was missing from NormalizedConfigManager.

GroupViT is a dual text/vision encoder — same text_config/vision_config shape Pix2StructNormalizedTextConfig already handles — so registering it should have been a one-line reuse of that existing class. It wasn't, because of a real bug this surfaced:

The bug: NormalizedTextAndVisionConfig.__getattr__ prefixes the raw accessor name (e.g. "num_layers") onto the sub-config path, instead of first resolving it through the NUM_LAYERS-style constant mapping to the actual underlying config attribute name ("num_hidden_layers"). Concretely, .num_layers was doing getattr(text_config, "num_layers") instead of getattr(text_config, "num_hidden_layers").

This happened to work for Pix2Struct only because its text_config defines both num_layers and num_hidden_layers as synonyms — coincidence, not correctness. It silently breaks (raises AttributeError) for any model with this same composite shape whose sub-config only has the standard name, which is every other model that would use this class, including GroupViT, OwlViT, OwlV2 and SigLIP.

The fix: resolve the mapped name (getattr(self, attr_name.upper(), attr_name)) before prefixing it with the sub-config path, so the correct underlying attribute name is looked up on the nested config either way.

  • Added "groupvit": Pix2StructNormalizedTextConfig to _conf (alphabetically, between gptj and imagegpt)
  • Removed groupvit from the TODO: missing normalized configs comment
  • Fixed NormalizedTextAndVisionConfig.__getattr__ in the same file

Test plan

  • Added test_groupvit_normalizes_expected_attributes: instantiates a real GroupViTConfig() and asserts hidden_size/num_attention_heads/num_layers/image_size/num_channels all resolve correctly against the nested text_config/vision_config
  • Added test_pix2struct_num_layers_unaffected_by_the_groupvit_fix as an explicit regression guard, pinning Pix2Struct's existing normalized values so the fix can't silently regress them
  • Ran the full test file locally (python -m unittest) against the actual transformers.GroupViTConfig and transformers.Pix2StructConfig (not mocked) — all 3 tests pass

Follow-up

OwlViT, OwlV2 and SigLIP have the exact same shape and are also fixed by this change — I'll open those as separate PRs once this one's reviewed, since they're independent registrations, not because they need anything different.

resolution bug in NormalizedTextAndVisionConfig

GroupViT has an ONNX export config but was missing from
NormalizedConfigManager. It's a dual text/vision encoder with the same
text_config/vision_config shape Pix2StructNormalizedTextConfig already
handles, so registering it should have been a one-line reuse of that
existing class.

It wasn't: NormalizedTextAndVisionConfig.__getattr__ prefixes the raw
accessor name (e.g. "num_layers") onto the sub-config path, instead of
first resolving it through the NUM_LAYERS-style constant mapping to the
config's real attribute name ("num_hidden_layers"). This happened to work
for Pix2Struct only because its text_config defines both num_layers and
num_hidden_layers as synonyms - it silently breaks for any model whose
sub-config only has the standard name, which is every other model with
this shape.

Fixed __getattr__ to resolve the mapped name before prefixing. Pinned
Pix2Struct's existing num_layers/hidden_size/num_attention_heads values
in a regression test so this can't quietly break again.
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.

1 participant