Skip to content
Open
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
12 changes: 6 additions & 6 deletions models/llama4/vision/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@


class PixelShuffle(nn.Module):
def __init__(self, ps_ratio):
def __init__(self, ps_ratio: float):
super().__init__()
self.ps_ratio = ps_ratio

def forward(self, x):
def forward(self, x: torch.Tensor) -> torch.Tensor:
# x: [B, N, C], N = number of patches
assert self.ps_ratio is not None, "ps_ratio is required for pixel shuffle"
assert x.dim() == 3, "pixel shuffle requires encoded patches [B, N, C]"
Expand All @@ -33,14 +33,14 @@ def forward(self, x):
return pixel_shuffle_patches


def pixel_shuffle_op(input_x, ps_ratio):
n, w, h, c = input_x.size()
input_x = input_x.view(n, w, int(h * ps_ratio), int(c / ps_ratio))
def pixel_shuffle_op(input_x: torch.Tensor, ps_ratio: float) -> torch.Tensor:
n, h, w, c = input_x.size()
input_x = input_x.view(n, h, int(w * ps_ratio), int(c / ps_ratio))
input_x = input_x.permute(0, 2, 1, 3).contiguous()
input_x = input_x.view(
n,
int(h * ps_ratio),
int(w * ps_ratio),
int(h * ps_ratio),
int(c / (ps_ratio * ps_ratio)),
)
input_x = input_x.permute(0, 2, 1, 3).contiguous()
Expand Down