Skip to content

Commit

Permalink
[codemod][pyfmt] apply Black 2024 style in fbcode (9/16)
Browse files Browse the repository at this point in the history
Summary:
Formats the covered files with pyfmt.

paintitblack

Reviewed By: aleivag

Differential Revision: D54447729

fbshipit-source-id: fc781322b254f7027c24888cdadd5f1e90325ba8
  • Loading branch information
amyreese authored and facebook-github-bot committed Mar 3, 2024
1 parent f0f0845 commit f704bc5
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 24 deletions.
1 change: 1 addition & 0 deletions mmf/common/registry.py
Expand Up @@ -35,6 +35,7 @@ class Registry:
r"""Class for registry object which acts as central source of truth
for MMF
"""

mapping = {
# Mappings of builder name to their respective classes
# Use `registry.register_builder` to register a builder class
Expand Down
6 changes: 3 additions & 3 deletions mmf/datasets/builders/charades/_utils.py
Expand Up @@ -21,9 +21,9 @@ def make_charades_df(csv_path, video_dir, classes_file):

# parse action labels
df["action_labels"] = df["actions"].map(
lambda x: [label.split(" ")[0] for label in x.split(";")]
if pd.notnull(x)
else []
lambda x: (
[label.split(" ")[0] for label in x.split(";")] if pd.notnull(x) else []
)
)

# load id to class map
Expand Down
4 changes: 1 addition & 3 deletions mmf/datasets/databases/readers/feature_readers.py
Expand Up @@ -275,9 +275,7 @@ def read(self, image_feat_path):
tmp_image_feat = image_feat_bbox.item().get("image_feature")
image_loc, image_dim = tmp_image_feat.shape
tmp_image_feat_2 = np.zeros((self.max_loc, image_dim), dtype=np.float32)
tmp_image_feat_2[
0:image_loc,
] = tmp_image_feat # noqa
tmp_image_feat_2[0:image_loc,] = tmp_image_feat # noqa
tmp_image_feat_2 = torch.from_numpy(tmp_image_feat_2)
tmp_image_box = np.zeros((self.max_loc, 4), dtype=np.int32)
tmp_image_box[0:image_loc] = image_boxes
Expand Down
6 changes: 3 additions & 3 deletions mmf/datasets/multi_datamodule.py
Expand Up @@ -29,9 +29,9 @@ def __init__(self, config: DictConfig):
self.batch_size = get_batch_size()

self.dataset_list: List[str] = dataset_list_from_config(self.config)
self.datamodules: Dict[
str, pl.LightningDataModule
] = build_multiple_datamodules(self.dataset_list, self.config.dataset_config)
self.datamodules: Dict[str, pl.LightningDataModule] = (
build_multiple_datamodules(self.dataset_list, self.config.dataset_config)
)
self.train_loader: Optional[MultiDataLoader] = None
self.val_loader: Optional[MultiDataLoader] = None
self.test_loader: Optional[MultiDataLoader] = None
Expand Down
4 changes: 1 addition & 3 deletions mmf/models/albef/vit.py
Expand Up @@ -660,9 +660,7 @@ def interpolate_pos_embed(pos_embed_checkpoint, visual_encoder):
)
pos_tokens = pos_tokens.permute(0, 2, 3, 1).flatten(1, 2)
new_pos_embed = torch.cat((extra_tokens, pos_tokens), dim=1)
print(
"reshape position embedding from %d to %d" % (orig_size**2, new_size**2)
)
print("reshape position embedding from %d to %d" % (orig_size**2, new_size**2))

return new_pos_embed
else:
Expand Down
6 changes: 3 additions & 3 deletions mmf/models/krisp.py
Expand Up @@ -123,9 +123,9 @@ def build(self):
# Answer indices not in graph
if self.config.output_combine == "add":
self.missing_ans_inds = torch.LongTensor(self.config.num_labels).fill_(1)
self.missing_ans_inds[
self.graph_module.index_in_ans
] = 0 # Now any index stil set to 1 is missing from graph
self.missing_ans_inds[self.graph_module.index_in_ans] = (
0 # Now any index stil set to 1 is missing from graph
)

# Each model in MMF gets a dict called sample_list which contains
# all of the necessary information returned from the image
Expand Down
6 changes: 3 additions & 3 deletions mmf/models/visual_bert.py
Expand Up @@ -459,9 +459,9 @@ def add_post_flatten_params(
new_lm_labels = torch.ones_like(attention_mask) * -1
size_masked_lm_labels = sample_list["masked_lm_labels"].size()
assert len(size_masked_lm_labels) == 2
new_lm_labels[
: size_masked_lm_labels[0], : size_masked_lm_labels[1]
] = sample_list["masked_lm_labels"]
new_lm_labels[: size_masked_lm_labels[0], : size_masked_lm_labels[1]] = (
sample_list["masked_lm_labels"]
)
sample_list["masked_lm_labels"] = new_lm_labels

return sample_list
Expand Down
3 changes: 0 additions & 3 deletions mmf/modules/losses.py
Expand Up @@ -880,7 +880,6 @@ def calc_ms_loss(pair, base, param, multiplier):

@registry.register_loss("refiner_ms")
class RefinerMSLoss(nn.Module):

"""
A Multi-Similarity loss between the decoder outputs of a given embedding size
and its targets
Expand Down Expand Up @@ -949,7 +948,6 @@ def forward(self, sample_list, model_output):

@registry.register_loss("ms_loss")
class MSLoss(nn.Module):

"""
A Multi-Similarity loss between embeddings of similar and dissimilar
labels is implemented here.
Expand Down Expand Up @@ -1049,7 +1047,6 @@ def forward(self, sample_list, model_output):

@registry.register_loss("refiner_contrastive_loss")
class RefinerContrastiveLoss(nn.Module):

"""
A contrastive loss between the decoder outputs of a given embedding size
and its targets
Expand Down
6 changes: 3 additions & 3 deletions tests/models/transformers/test_heads.py
Expand Up @@ -247,9 +247,9 @@ def setUp(self):
)
self.processed_sample_list = Sample()
feat_targets = torch.zeros((bs, num_feat, img_dim))
self.processed_sample_list[
"mrfr_region_target"
] = feat_targets.contiguous().view(-1, img_dim)
self.processed_sample_list["mrfr_region_target"] = (
feat_targets.contiguous().view(-1, img_dim)
)
self.processed_sample_list["mrfr_region_mask"] = torch.ones(
(bs, num_feat)
).bool()
Expand Down

0 comments on commit f704bc5

Please sign in to comment.