Skip to content

Commit

Permalink
[codemod][pyfmt][ruff] Convert directory fbcode/faim to use the Ruff …
Browse files Browse the repository at this point in the history
…Formatter

Summary:
Converts the directory specified to use the Ruff formatter in pyfmt

ruff_dog

If this diff causes merge conflicts when rebasing, please run
`hg status -n -0 --change . -I '**/*.{py,pyi}' | xargs -0 arc pyfmt`
on your diff, and amend any changes before rebasing onto latest.
That should help reduce or eliminate any merge conflicts.

allow-large-files

Reviewed By: amyreese

Differential Revision: D66013237

fbshipit-source-id: 01748bc342d50faffd0030e3d52b5f5f640c58ac
  • Loading branch information
Thomas Polasek authored and facebook-github-bot committed Nov 15, 2024
1 parent 753edc7 commit a66c952
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 108 deletions.
7 changes: 4 additions & 3 deletions mmf/common/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Register a test reporter: ``@registry.register_test_reporter``
- Register a pl datamodule: ``@registry.register_datamodule``
"""

from mmf.utils.env import setup_imports


Expand Down Expand Up @@ -508,9 +509,9 @@ def wrap(iteration_strategy_cls):
assert issubclass(
iteration_strategy_cls, IterationStrategy
), "All datamodules must inherit IterationStrategy class"
cls.mapping["iteration_strategy_name_mapping"][
name
] = iteration_strategy_cls
cls.mapping["iteration_strategy_name_mapping"][name] = (
iteration_strategy_cls
)
return iteration_strategy_cls

return wrap
Expand Down
16 changes: 8 additions & 8 deletions mmf/common/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ def __setattr__(self, key, value):
def __getattr__(self, key):
if key not in self:
raise AttributeError(
"Key {} not found in the SampleList. "
"Valid choices are {}".format(key, self.fields())
"Key {} not found in the SampleList. " "Valid choices are {}".format(
key, self.fields()
)
)
fields = self.keys()

Expand Down Expand Up @@ -245,8 +246,9 @@ def get_fields(self, fields):
for field in fields:
if field not in current_fields:
raise AttributeError(
"{} not present in SampleList. "
"Valid choices are {}".format(field, current_fields)
"{} not present in SampleList. " "Valid choices are {}".format(
field, current_fields
)
)
return_list.add_field(field, self[field])

Expand Down Expand Up @@ -396,7 +398,7 @@ def to_dict(self) -> Dict[str, Any]:


def convert_batch_to_sample_list(
batch: Union[SampleList, Dict[str, Any]]
batch: Union[SampleList, Dict[str, Any]],
) -> SampleList:
# Create and return sample list with proper name
# and type set if it is already not a sample list
Expand All @@ -405,9 +407,7 @@ def convert_batch_to_sample_list(
if (
# Check if batch is a list before checking batch[0]
# or len as sometimes batch is already SampleList
isinstance(batch, list)
and len(batch) == 1
and isinstance(batch[0], SampleList)
isinstance(batch, list) and len(batch) == 1 and isinstance(batch[0], SampleList)
):
sample_list = batch[0]
elif not isinstance(batch, SampleList):
Expand Down
1 change: 1 addition & 0 deletions mmf/datasets/base_dataset_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def build(self, config, dataset_type, *args, **kwargs):
.. _here: https://github.com/facebookresearch/mmf/blob/main/mmf/datasets/vqa/vqa2/builder.py
"""

import uuid
from typing import Optional

Expand Down
5 changes: 3 additions & 2 deletions mmf/datasets/builders/charades/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ def get_clip(self, idx):
"""
if idx >= self.num_clips():
raise IndexError(
"Index {} out of range "
"({} number of clips)".format(idx, self.num_clips())
"Index {} out of range " "({} number of clips)".format(
idx, self.num_clips()
)
)
video_path = self.video_paths[idx]
clip_pts = self.clips[idx]
Expand Down
1 change: 1 addition & 0 deletions mmf/datasets/multi_dataset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
MultiDatasetLoader class is used by DatasetLoader class to load multiple datasets
and more granular
"""

import logging
import warnings
from typing import Dict, Iterator
Expand Down
27 changes: 14 additions & 13 deletions mmf/datasets/processors/frcnn_processor.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Copyright (c) Facebook, Inc. and its affiliates.

"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""

import os
import sys
from dataclasses import dataclass
Expand Down
1 change: 0 additions & 1 deletion mmf/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def forward(self, sample_list):
return {"scores": scores}
"""


import collections
import logging
import warnings
Expand Down
32 changes: 16 additions & 16 deletions mmf/models/frcnn.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Copyright (c) Facebook, Inc. and its affiliates.

"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2 && Huggingface Co.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2 && Huggingface Co.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""

from typing import List

Expand Down
6 changes: 3 additions & 3 deletions mmf/models/mmf_bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ def forward(self, sample_list):
seq_relationship_score.contiguous().view(-1, 2),
is_random_next.contiguous().view(-1),
)
output_dict["losses"][
loss_key + "/next_sentence_loss"
] = next_sentence_loss
output_dict["losses"][loss_key + "/next_sentence_loss"] = (
next_sentence_loss
)
return output_dict
elif (
"vqa" in self.config.training_head_type
Expand Down
1 change: 1 addition & 0 deletions mmf/models/unit/backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
Backbone modules.
"""

import math
from collections import OrderedDict

Expand Down
1 change: 1 addition & 0 deletions mmf/models/unit/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
Modules to compute the matching cost and solve the corresponding LSAP.
"""

from typing import Dict, List

import torch
Expand Down
1 change: 1 addition & 0 deletions mmf/modules/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CustomLoss(nn.Module):
- type: custom
- params: {}
"""

import collections
import warnings
from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions mmf/modules/poolers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class CustomPool(nn.Module):
...
"""

from typing import Any, List

import torch
Expand Down
5 changes: 3 additions & 2 deletions mmf/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ def _merge_with_dotlist(

raise AttributeError(
"While updating configuration",
"option {} is not present "
"after field {}".format(opt, stripped_field),
"option {} is not present " "after field {}".format(
opt, stripped_field
),
)

return config
Expand Down
1 change: 1 addition & 0 deletions mmf/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
These can be replaced if your particular file system does not support them.
"""

import collections
import datetime
import hashlib
Expand Down
27 changes: 14 additions & 13 deletions mmf/utils/features/visualizing_image.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Copyright (c) Facebook, Inc. and its affiliates.

"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""

import colorsys
import io
import os
Expand Down
5 changes: 3 additions & 2 deletions mmf/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ def get_batch_size():

if batch_size % world_size != 0:
raise RuntimeError(
"Batch size {} must be divisible by number "
"of GPUs {} used.".format(batch_size, world_size)
"Batch size {} must be divisible by number " "of GPUs {} used.".format(
batch_size, world_size
)
)

return batch_size // world_size
Expand Down
1 change: 1 addition & 0 deletions mmf/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- type: greedy
- params: {}
"""

import os
import re
from collections import Counter
Expand Down
1 change: 1 addition & 0 deletions mmf_cli/torchx_entryscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Entrypoint script used by TorchX to start the training run in each process
"""

from mmf_cli.fb_run import fb_scheduler_run


Expand Down
6 changes: 3 additions & 3 deletions tests/models/test_mmf_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def test_finetune_roberta_base(self):

@test_utils.skip_if_no_network
def test_finetune_xlmr_base(self):
self.config.model_config[self.model_name][
"transformer_base"
] = "xlm-roberta-base"
self.config.model_config[self.model_name]["transformer_base"] = (
"xlm-roberta-base"
)
model = build_model(self.config.model_config[self.model_name])
model.eval()
self.assertTrue(
Expand Down
26 changes: 13 additions & 13 deletions tools/scripts/features/frcnn/frcnn_utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Copyright (c) Facebook, Inc. and its affiliates.

"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal, Huggingface team :)
Adapted From Facebook Inc, Detectron2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal, Huggingface team :)
Adapted From Facebook Inc, Detectron2
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""

import copy
import json
Expand Down
33 changes: 17 additions & 16 deletions tools/scripts/features/frcnn/modeling_frcnn.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Copyright (c) Facebook, Inc. and its affiliates.

"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2 && Huggingface Co.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""
coding=utf-8
Copyright 2018, Antonio Mendoza Hao Tan, Mohit Bansal
Adapted From Facebook Inc, Detectron2 && Huggingface Co.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.import copy
"""

import itertools
import math
import os
Expand Down
Loading

0 comments on commit a66c952

Please sign in to comment.