Skip to content

Commit

Permalink
apply import merging for fbcode (10 of 11)
Browse files Browse the repository at this point in the history
Summary:
Applies new import merging and sorting from µsort v1.0.

When merging imports, µsort will make a best-effort to move associated
comments to match merged elements, but there are known limitations due to
the diynamic nature of Python and developer tooling. These changes should
not produce any dangerous runtime changes, but may require touch-ups to
satisfy linters and other tooling.

Note that µsort uses case-insensitive, lexicographical sorting, which
results in a different ordering compared to isort. This provides a more
consistent sorting order, matching the case-insensitive order used when
sorting import statements by module name, and ensures that "frog", "FROG",
and "Frog" always sort next to each other.

For details on µsort's sorting and merging semantics, see the user guide:
https://usort.readthedocs.io/en/stable/guide.html#sorting

Reviewed By: lisroach

Differential Revision: D36402249

fbshipit-source-id: 93618434ae891f091dde1e067c67a3c19445653b
  • Loading branch information
amyreese authored and facebook-github-bot committed May 15, 2022
1 parent 0f8c5e9 commit 668eabf
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 35 deletions.
4 changes: 2 additions & 2 deletions examples/flava/data/datamodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from pytorch_lightning import LightningDataModule
from transformers import (
BertTokenizer,
DefaultDataCollator,
DataCollatorForLanguageModeling,
DataCollatorForWholeWordMask,
DefaultDataCollator,
TRANSFORMERS_CACHE,
)
from transformers.data.data_collator import torch_default_data_collator
Expand All @@ -27,10 +27,10 @@
default_torchvision_transforms,
encode_text_batch,
pad_batch,
VLTransform,
TEXT_DEFAULT_TOKENIZER,
TEXT_WHOLE_WORD_MASK_TOKENIZER,
VL_MAX_LENGTH_DEFAULT,
VLTransform,
)
from .utils import build_datasets_from_info, fetch_images

Expand Down
2 changes: 1 addition & 1 deletion examples/flava/data/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import random
import warnings
from functools import partial
from typing import List, Tuple, Optional, Callable, Any, Union
from typing import Any, Callable, List, Optional, Tuple, Union

import numpy as np
import torch
Expand Down
2 changes: 1 addition & 1 deletion examples/flava/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import List

import requests
from datasets import load_dataset, concatenate_datasets
from datasets import concatenate_datasets, load_dataset
from datasets.utils.file_utils import get_datasets_user_agent
from definitions import HFDatasetInfo
from PIL import Image, UnidentifiedImageError
Expand Down
2 changes: 1 addition & 1 deletion examples/flava/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# LICENSE file in the root directory of this source tree.

from dataclasses import dataclass, field
from typing import Any, Dict, Optional, List, Tuple
from typing import Any, Dict, List, Optional, Tuple

from omegaconf import MISSING

Expand Down
7 changes: 2 additions & 5 deletions examples/flava/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from data import (
TorchVisionDataModule,
TextDataModule,
)
from data import TextDataModule, TorchVisionDataModule
from data.datamodules import VLDataModule
from definitions import FLAVAArguments
from model import FLAVAClassificationLightningModule
from omegaconf import OmegaConf
from pytorch_lightning import Trainer, seed_everything
from pytorch_lightning import seed_everything, Trainer
from pytorch_lightning.callbacks import LearningRateMonitor
from utils import build_config, build_datamodule_kwargs

Expand Down
9 changes: 2 additions & 7 deletions examples/flava/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
# LICENSE file in the root directory of this source tree.

from callbacks.multimodal_eval import MultimodalEvalCallback
from data import (
ImageDataModule,
MLMDataModule,
MultiDataModule,
VLDataModule,
)
from data import ImageDataModule, MLMDataModule, MultiDataModule, VLDataModule
from definitions import FLAVAArguments
from model import FLAVAPreTrainingLightningModule
from omegaconf import OmegaConf
from pytorch_lightning import Trainer, seed_everything
from pytorch_lightning import seed_everything, Trainer
from pytorch_lightning.callbacks import LearningRateMonitor
from utils import build_config, build_datamodule_kwargs

Expand Down
2 changes: 1 addition & 1 deletion examples/flava/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from definitions import FLAVAArguments, DatasetInfo, TrainingArguments
from definitions import DatasetInfo, FLAVAArguments, TrainingArguments
from hydra.utils import instantiate
from omegaconf import OmegaConf

Expand Down
2 changes: 1 addition & 1 deletion test/models/test_flava.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import torch
from torchmultimodal.models.flava import (
flava_model_for_pretraining,
flava_model_for_classification,
flava_model_for_pretraining,
)


Expand Down
2 changes: 1 addition & 1 deletion test/modules/layers/test_mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import partial

import torch
from test.test_utils import set_rng_seed, assert_expected
from test.test_utils import assert_expected, set_rng_seed
from torchmultimodal.modules.layers.mlp import MLP


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
import torch.multiprocessing as mp
import torch.nn as nn
import torch.optim as optim
from test.test_utils import (
gpu_test,
init_distributed_on_file,
with_temp_files,
)
from test.test_utils import gpu_test, init_distributed_on_file, with_temp_files
from torch import distributed as dist
from torchmultimodal.modules.losses.contrastive_loss_with_temperature import (
ContrastiveLossWithTemperature,
Expand Down
2 changes: 1 addition & 1 deletion test/transforms/test_clip_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import unittest

import torch
from test.test_utils import get_asset_path, set_rng_seed, assert_expected
from test.test_utils import assert_expected, get_asset_path, set_rng_seed
from torchmultimodal.transforms.clip_transform import CLIPTransform
from torchvision.transforms import ToPILImage

Expand Down
6 changes: 3 additions & 3 deletions torchmultimodal/models/flava.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import torch
from packaging import version
from torch import nn, Tensor, device
from torch import device, nn, Tensor
from torchmultimodal.modules.layers.mlp import MLP
from torchmultimodal.modules.layers.normalizations import Fp32LayerNorm
from torchmultimodal.modules.losses.flava import (
FLAVAPretrainingLoss,
FLAVAPretrainingLossOutput,
Pooler,
FLAVAPretrainingLoss,
)
from torchmultimodal.utils.common import PretrainedMixin, ModelOutput
from torchmultimodal.utils.common import ModelOutput, PretrainedMixin


EMBEDDING_OPTIONS = Literal["image", "text", "mm"]
Expand Down
2 changes: 1 addition & 1 deletion torchmultimodal/modules/layers/quantisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# LICENSE file in the root directory of this source tree.

import torch
from torch import nn, Tensor, Size
from torch import nn, Size, Tensor


class Quantisation(nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion torchmultimodal/modules/losses/flava.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from torch import nn, Tensor
from torchmultimodal.modules.layers.normalizations import Fp32LayerNorm
from torchmultimodal.modules.losses.contrastive_loss_with_temperature import (
ContrastiveLossOutput,
contrastive_loss_with_temperature,
ContrastiveLossOutput,
)
from torchmultimodal.utils.common import ModelOutput

Expand Down
5 changes: 1 addition & 4 deletions torchmultimodal/utils/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

def _get_path_manager():
try:
from torchmultimodal.fb.utils.file_io import (
register_handlers,
FBPathManager,
)
from torchmultimodal.fb.utils.file_io import FBPathManager, register_handlers

pm = FBPathManager()
register_handlers(pm)
Expand Down

0 comments on commit 668eabf

Please sign in to comment.