Skip to content

Conversation

@lixiaolei1982
Copy link

Fixed an off-by-one error in the early stopping logic of WindowedDinov2WithRegistersEncoder.forward().

Bug: The condition if i > int(self.config.out_features[-1][5:]): incorrectly compares a 0-based layer index (i) with a 1-based stage number.

Fix: Changed to if i > int(self.config.out_features[-1][5:]) - 1: to properly convert the stage number to a 0-based index before comparison.

Example:
If out_features[-1] = "stage8", stage number = 8
Corresponding layer index = 7 (0-based)
Old condition: i > 8 → never true for i in [0, 11]
New condition: i > 7 → stops when i reaches 8

Impact: The encoder now correctly stops after processing the last required transformer layer, improving computational efficiency.

- Changed if i > int(self.config.out_features[-1][5:]): to
  if i > int(self.config.out_features[-1][5:]) - 1:
- Properly compares 0-based layer indices with 1-based stage numbers
- Encoder now correctly stops after processing last required layer
- Improves computational efficiency for partial feature extraction
@Borda Borda self-requested a review January 12, 2026 20:32
@Borda Borda added the bug Something isn't working label Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working has conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants