Skip to content

Commit

Permalink
formatting changes from black 22.3.0
Browse files Browse the repository at this point in the history
Summary:
Applies the black-fbsource codemod with the new build of pyfmt.

paintitblack

Reviewed By: lisroach

Differential Revision: D36324783

fbshipit-source-id: 280c09e88257e5e569ab729691165d8dedd767bc
  • Loading branch information
amyreese authored and facebook-github-bot committed May 12, 2022
1 parent 3f14368 commit f03c241
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions torchmultimodal/models/flava.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ def __init__(self, n_in: int, n_out: int, kw: int):
super().__init__()

w = torch.empty((n_out, n_in, kw, kw), dtype=torch.float32)
w.normal_(std=1 / math.sqrt(n_in * kw ** 2))
w.normal_(std=1 / math.sqrt(n_in * kw**2))

b = torch.zeros((n_out,), dtype=torch.float32)
self.w, self.b = nn.Parameter(w), nn.Parameter(b)
Expand All @@ -1340,7 +1340,7 @@ class DalleEncoderBlock(nn.Module):
def __init__(self, n_in: int, n_out: int, n_layers: int):
super().__init__()
n_hid = n_out // 4
self.post_gain = 1 / (n_layers ** 2)
self.post_gain = 1 / (n_layers**2)

self.id_path = DalleConv2d(n_in, n_out, 1) if n_in != n_out else nn.Identity()
self.res_path = nn.Sequential(
Expand Down
4 changes: 2 additions & 2 deletions torchmultimodal/modules/encoders/clip_resnet_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(
):
super().__init__()
self.positional_embedding = nn.Parameter(
torch.randn(spacial_dim ** 2 + 1, embed_dim) / embed_dim ** 0.5
torch.randn(spacial_dim**2 + 1, embed_dim) / embed_dim**0.5
)
self.k_proj = nn.Linear(embed_dim, embed_dim)
self.q_proj = nn.Linear(embed_dim, embed_dim)
Expand Down Expand Up @@ -200,7 +200,7 @@ def _make_layer(self, planes: int, blocks: int, stride=1) -> nn.Module:

def initialize_parameters(self):
if self.attnpool is not None:
std = self.attnpool.c_proj.in_features ** -0.5
std = self.attnpool.c_proj.in_features**-0.5
nn.init.normal_(self.attnpool.q_proj.weight, std=std)
nn.init.normal_(self.attnpool.k_proj.weight, std=std)
nn.init.normal_(self.attnpool.v_proj.weight, std=std)
Expand Down
6 changes: 3 additions & 3 deletions torchmultimodal/modules/encoders/clip_text_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def initialize_parameters(self) -> None:
std=self.POS_EMBEDDING_INIT_STD,
)

proj_std = (self.width ** -0.5) * ((2 * self.encoder.layers.num_layers) ** -0.5)
attn_std = self.width ** -0.5
proj_std = (self.width**-0.5) * ((2 * self.encoder.layers.num_layers) ** -0.5)
attn_std = self.width**-0.5
fc_std = (2 * self.width) ** -0.5
for layer in self.encoder.layers.layers:
nn.init.normal_(layer.self_attn.in_proj_weight, std=attn_std)
Expand All @@ -83,7 +83,7 @@ def initialize_parameters(self) -> None:
nn.init.normal_(layer.linear2.weight, std=proj_std)

# Initialize projection
nn.init.normal_(self.projection.weight, std=self.width ** -0.5)
nn.init.normal_(self.projection.weight, std=self.width**-0.5)

def build_attention_mask(self) -> torch.Tensor:
mask = torch.full((self.context_length, self.context_length), True).triu(1)
Expand Down

0 comments on commit f03c241

Please sign in to comment.