Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,17 @@ def forward(
output = self.hook_out(output)

return output

def set_original_component(self, original_component: torch.nn.Module) -> None:
"""Set the original component that this bridge wraps.
Note that CLIPVisionModel used to wrap a inner object as .vision_model before
transformers version 5.6.0, but after that it must directly be used.
This is a temporary hack to fix that till the transformers version is bumped.

Args:
original_component: The original transformer component to wrap
"""
if not hasattr(original_component, "vision_model"):
# We should bypass any pytorch module registration.
object.__setattr__(original_component, "vision_model", original_component)
super().set_original_component(original_component)
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def __init__(
"""
# All submodule names are resolved relative to the parent's
# original_component (a SiglipVisionModel) by setup_submodules().
# SiglipVisionModel wraps SiglipVisionTransformer as .vision_model,
# so all paths go through vision_model.*.
# SiglipVisionModel wraps a SiglipVisionTransformer as .vision_model till
# transformers version 5.6.0
# post_layernorm is nn.LayerNorm; NormalizationBridge introspects the
# wrapped module so the RMSNorm-LM config (Gemma 3, LLaVA) doesn't leak.
default_submodules = {
Expand Down Expand Up @@ -171,3 +171,17 @@ def forward(
output = self.hook_out(output)

return output

def set_original_component(self, original_component: torch.nn.Module) -> None:
"""Set the original component that this bridge wraps.
Note that SiglipVisionModel used to wrap a inner object as .vision_model before
transformers version 5.6.0, but after that it must directly be used.
This is a temporary hack to fix that till the transformers version is bumped.

Args:
original_component: The original transformer component to wrap
"""
if not hasattr(original_component, "vision_model"):
# We should bypass any pytorch module registration.
object.__setattr__(original_component, "vision_model", original_component)
super().set_original_component(original_component)
Loading