|
13 | 13 |
|
14 | 14 | from collections.abc import Callable, Sequence |
15 | 15 | from functools import partial |
| 16 | +from typing import cast |
16 | 17 |
|
17 | 18 | import torch |
18 | 19 | import torch.nn as nn |
@@ -96,7 +97,7 @@ def __init__(self, num_heads: int, dim_head: int) -> None: |
96 | 97 | self.gamma = nn.Parameter(torch.ones(num_heads, 1, dim_head)) |
97 | 98 |
|
98 | 99 | def forward(self, x: Tensor) -> Tensor: |
99 | | - return F.normalize(x, dim=-1) * self.scale * self.gamma |
| 100 | + return cast(Tensor, F.normalize(x, dim=-1) * self.scale * self.gamma) |
100 | 101 |
|
101 | 102 |
|
102 | 103 | class _NaViTAttention(nn.Module): |
@@ -174,7 +175,7 @@ def forward(self, x: Tensor, context: Tensor | None = None, attn_mask: Tensor | |
174 | 175 | attn = self.drop_weights(dots.softmax(dim=-1)) |
175 | 176 | out = torch.matmul(attn, v) # (B, heads, N, dim_head) |
176 | 177 | out = out.transpose(1, 2).flatten(-2) # (B, N, inner_dim) |
177 | | - return self.drop_output(self.out_proj(out)) |
| 178 | + return cast(Tensor, self.drop_output(self.out_proj(out))) |
178 | 179 |
|
179 | 180 |
|
180 | 181 | class _NaViTTransformerBlock(nn.Module): |
@@ -571,4 +572,4 @@ def forward( |
571 | 572 | is_valid = (image_id_range.unsqueeze(0) < num_images_t.unsqueeze(1)).reshape(-1) # (B * max_queries,) |
572 | 573 | pooled = pooled[is_valid] # (total_images, hidden_size) |
573 | 574 |
|
574 | | - return self.mlp_head(pooled) # (total_images, num_classes) |
| 575 | + return cast(Tensor, self.mlp_head(pooled)) # (total_images, num_classes) |
0 commit comments