Skip to content

Commit

Permalink
refactor: update typings
Browse files Browse the repository at this point in the history
  • Loading branch information
vectorvp committed Nov 29, 2024
1 parent 4195e29 commit 658dd83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lightly/models/modules/ijepa_timm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import torch
import torch.nn as nn
from timm.models.vision_transformer import Block
from torch import Tensor

from lightly.models import utils

Expand Down Expand Up @@ -58,7 +59,7 @@ def __init__(
drop_path_rate: float = 0.0,
proj_drop_rate: float = 0.0,
attn_drop_rate: float = 0.0,
norm_layer: Callable[..., torch.nn.Module] = partial(nn.LayerNorm, eps=1e-6),
norm_layer: Callable[..., nn.Module] = partial(nn.LayerNorm, eps=1e-6),
):
"""Initializes the IJEPAPredictorTIMM with the specified dimensions."""

Expand Down Expand Up @@ -97,10 +98,10 @@ def __init__(

def forward(
self,
x: torch.Tensor,
masks_x: list[torch.Tensor] | torch.Tensor,
masks: list[torch.Tensor] | torch.Tensor,
) -> torch.Tensor:
x: Tensor,
masks_x: list[Tensor] | Tensor,
masks: list[Tensor] | Tensor,
) -> Tensor:
"""Forward pass of the IJEPAPredictorTIMM.
Args:
Expand Down
6 changes: 3 additions & 3 deletions lightly/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ def update_drop_path_rate(
block.drop_path2 = Identity()


def repeat_interleave_batch(x: torch.Tensor, B: int, repeat: int) -> torch.Tensor:
def repeat_interleave_batch(x: Tensor, B: int, repeat: int) -> Tensor:
"""Repeat and interleave the input tensor."""
N = len(x) // B
x = torch.cat(
Expand All @@ -1277,8 +1277,8 @@ def repeat_interleave_batch(x: torch.Tensor, B: int, repeat: int) -> torch.Tenso


def apply_masks(
x: torch.Tensor, masks: torch.Tensor | list[torch.Tensor]
) -> torch.Tensor:
x: Tensor, masks: Tensor | list[Tensor]
) -> Tensor:
"""Apply masks to the input tensor.
From https://github.com/facebookresearch/ijepa/blob/main/src/masks/utils.py
Expand Down

0 comments on commit 658dd83

Please sign in to comment.