diff --git a/mmf/common/registry.py b/mmf/common/registry.py index bf077733f..9045178b8 100644 --- a/mmf/common/registry.py +++ b/mmf/common/registry.py @@ -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 @@ -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 diff --git a/mmf/common/sample.py b/mmf/common/sample.py index 13be35310..acac2754e 100644 --- a/mmf/common/sample.py +++ b/mmf/common/sample.py @@ -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() @@ -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]) @@ -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 @@ -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): diff --git a/mmf/datasets/base_dataset_builder.py b/mmf/datasets/base_dataset_builder.py index 463f29830..533836705 100644 --- a/mmf/datasets/base_dataset_builder.py +++ b/mmf/datasets/base_dataset_builder.py @@ -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 diff --git a/mmf/datasets/builders/charades/_utils.py b/mmf/datasets/builders/charades/_utils.py index d59b632a6..fd423062d 100644 --- a/mmf/datasets/builders/charades/_utils.py +++ b/mmf/datasets/builders/charades/_utils.py @@ -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] diff --git a/mmf/datasets/multi_dataset_loader.py b/mmf/datasets/multi_dataset_loader.py index 9aff9ee40..5456c73d8 100644 --- a/mmf/datasets/multi_dataset_loader.py +++ b/mmf/datasets/multi_dataset_loader.py @@ -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 diff --git a/mmf/datasets/processors/frcnn_processor.py b/mmf/datasets/processors/frcnn_processor.py index cd454b122..14a5b6c52 100644 --- a/mmf/datasets/processors/frcnn_processor.py +++ b/mmf/datasets/processors/frcnn_processor.py @@ -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 diff --git a/mmf/models/base_model.py b/mmf/models/base_model.py index 6a7fc8dd1..fd060606d 100644 --- a/mmf/models/base_model.py +++ b/mmf/models/base_model.py @@ -39,7 +39,6 @@ def forward(self, sample_list): return {"scores": scores} """ - import collections import logging import warnings diff --git a/mmf/models/frcnn.py b/mmf/models/frcnn.py index 13058134e..d968b86fd 100644 --- a/mmf/models/frcnn.py +++ b/mmf/models/frcnn.py @@ -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 diff --git a/mmf/models/mmf_bert.py b/mmf/models/mmf_bert.py index f84c1debd..09c06763a 100644 --- a/mmf/models/mmf_bert.py +++ b/mmf/models/mmf_bert.py @@ -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 diff --git a/mmf/models/unit/backbone.py b/mmf/models/unit/backbone.py index 25cc0772c..6518ef982 100644 --- a/mmf/models/unit/backbone.py +++ b/mmf/models/unit/backbone.py @@ -5,6 +5,7 @@ """ Backbone modules. """ + import math from collections import OrderedDict diff --git a/mmf/models/unit/matcher.py b/mmf/models/unit/matcher.py index 89d0968ee..58eb7dfd6 100644 --- a/mmf/models/unit/matcher.py +++ b/mmf/models/unit/matcher.py @@ -5,6 +5,7 @@ """ Modules to compute the matching cost and solve the corresponding LSAP. """ + from typing import Dict, List import torch diff --git a/mmf/modules/losses.py b/mmf/modules/losses.py index 7c34c9d95..2aa260861 100644 --- a/mmf/modules/losses.py +++ b/mmf/modules/losses.py @@ -25,6 +25,7 @@ class CustomLoss(nn.Module): - type: custom - params: {} """ + import collections import warnings from dataclasses import dataclass diff --git a/mmf/modules/poolers.py b/mmf/modules/poolers.py index 019beabc4..c2174a139 100644 --- a/mmf/modules/poolers.py +++ b/mmf/modules/poolers.py @@ -12,6 +12,7 @@ class CustomPool(nn.Module): ... """ + from typing import Any, List import torch diff --git a/mmf/utils/configuration.py b/mmf/utils/configuration.py index 6f23a81c4..256185dd6 100644 --- a/mmf/utils/configuration.py +++ b/mmf/utils/configuration.py @@ -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 diff --git a/mmf/utils/download.py b/mmf/utils/download.py index 7c8556878..6aa7dc734 100644 --- a/mmf/utils/download.py +++ b/mmf/utils/download.py @@ -9,6 +9,7 @@ These can be replaced if your particular file system does not support them. """ + import collections import datetime import hashlib diff --git a/mmf/utils/features/visualizing_image.py b/mmf/utils/features/visualizing_image.py index bb4b3f34e..b9c093162 100644 --- a/mmf/utils/features/visualizing_image.py +++ b/mmf/utils/features/visualizing_image.py @@ -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 diff --git a/mmf/utils/general.py b/mmf/utils/general.py index 6579c3e21..1a023e8db 100644 --- a/mmf/utils/general.py +++ b/mmf/utils/general.py @@ -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 diff --git a/mmf/utils/text.py b/mmf/utils/text.py index 4f6a68b1c..d04f6dd34 100644 --- a/mmf/utils/text.py +++ b/mmf/utils/text.py @@ -14,6 +14,7 @@ - type: greedy - params: {} """ + import os import re from collections import Counter diff --git a/mmf_cli/torchx_entryscript.py b/mmf_cli/torchx_entryscript.py index 1d46ed974..87e29415e 100644 --- a/mmf_cli/torchx_entryscript.py +++ b/mmf_cli/torchx_entryscript.py @@ -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 diff --git a/tests/models/test_mmf_transformer.py b/tests/models/test_mmf_transformer.py index b259b0806..0941061aa 100644 --- a/tests/models/test_mmf_transformer.py +++ b/tests/models/test_mmf_transformer.py @@ -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( diff --git a/tools/scripts/features/frcnn/frcnn_utils.py b/tools/scripts/features/frcnn/frcnn_utils.py index 0fd9fa3ed..228b20952 100644 --- a/tools/scripts/features/frcnn/frcnn_utils.py +++ b/tools/scripts/features/frcnn/frcnn_utils.py @@ -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 diff --git a/tools/scripts/features/frcnn/modeling_frcnn.py b/tools/scripts/features/frcnn/modeling_frcnn.py index 28409cffe..b6cbcee4a 100644 --- a/tools/scripts/features/frcnn/modeling_frcnn.py +++ b/tools/scripts/features/frcnn/modeling_frcnn.py @@ -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 diff --git a/tools/scripts/features/frcnn/processing_image.py b/tools/scripts/features/frcnn/processing_image.py index 1a9b7ce85..148a9cef7 100644 --- a/tools/scripts/features/frcnn/processing_image.py +++ b/tools/scripts/features/frcnn/processing_image.py @@ -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 +""" + from typing import Tuple import torch