Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions src/transformers/models/siglip/modeling_siglip.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ def forward(


class SiglipVisionTransformer(nn.Module):
_can_record_outputs = {
"hidden_states": SiglipEncoderLayer,
"attentions": SiglipAttention,
}

def __init__(self, config: SiglipVisionConfig):
super().__init__()
self.config = config
Expand All @@ -691,6 +696,7 @@ def __init__(self, config: SiglipVisionConfig):
if self.use_head:
self.head = SiglipMultiheadAttentionPoolingHead(config)

@check_model_inputs(tie_last_hidden_states=False)
@auto_docstring
def forward(
self,
Expand Down
7 changes: 6 additions & 1 deletion src/transformers/models/siglip2/modeling_siglip2.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ def forward(


class Siglip2VisionTransformer(nn.Module):
_can_record_outputs = {
"hidden_states": Siglip2EncoderLayer,
"attentions": Siglip2Attention,
}

def __init__(self, config: Siglip2VisionConfig):
super().__init__()
self.config = config
Expand All @@ -396,6 +401,7 @@ def __init__(self, config: Siglip2VisionConfig):
if self.use_head:
self.head = Siglip2MultiheadAttentionPoolingHead(config)

@check_model_inputs(tie_last_hidden_states=False)
@auto_docstring
def forward(
self,
Expand Down Expand Up @@ -811,7 +817,6 @@ def get_input_embeddings(self) -> nn.Module:
return self.vision_model.embeddings.patch_embedding

@check_model_inputs(tie_last_hidden_states=False)
@auto_docstring
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Ig this was already inherited?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

uh, interesting. yes it should have been, entirely unrelated to this lol

def forward(
self,
pixel_values: torch.FloatTensor,
Expand Down
2 changes: 2 additions & 0 deletions src/transformers/models/siglip2/modular_siglip2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

from ...modeling_attn_mask_utils import _prepare_4d_attention_mask
from ...utils import auto_docstring, filter_out_non_signature_kwargs
from ...utils.generic import check_model_inputs


class Siglip2TextConfig(SiglipTextConfig):
Expand Down Expand Up @@ -314,6 +315,7 @@ def forward(self, hidden_state: torch.Tensor, attention_mask: Optional[torch.Ten

class Siglip2VisionModel(SiglipVisionModel):
# Update: add `spatial_shapes` and `pixel_attention_mask`
@check_model_inputs(tie_last_hidden_states=False)
def forward(
self,
pixel_values: torch.FloatTensor,
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def wrapper(self, *args, **kwargs):
all_args[k] = v

# _can_record_outputs is None by default
capture_flags = _CAN_RECORD_REGISTRY.get(str(self.__class__)) or {} # there is a weak ref for executorch
capture_flags = _CAN_RECORD_REGISTRY.get(str(self.__class__)) or getattr(self, "_can_record_outputs", {})
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can revert this, the registry should already be either applied to the class or we get the default {}. See

_CAN_RECORD_REGISTRY[str(self.__class__)] = self._can_record_outputs # added for executorch support only

And I honestly don't wanna risk breaking executorch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah the latter reason is compelling 😬

recordable_keys = {
f"output_{k}": all_args.get(
f"output_{k}",
Expand Down