Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ venv.bak/
.mypy_cache/

# custom
/data
.vscode
.idea
*.pkl
Expand Down
2 changes: 2 additions & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 1 addition & 1 deletion mmpretrain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .version import __version__

mmcv_minimum_version = '2.0.0'
mmcv_maximum_version = '2.4.0'
mmcv_maximum_version = '3.0.0'
mmcv_version = digit_version(mmcv.__version__)

mmengine_minimum_version = '0.8.3'
Expand Down
2 changes: 1 addition & 1 deletion mmpretrain/apis/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get_model(model: Union[str, Config],
pretrained = metainfo.weights
else:
raise TypeError('model must be a name, a path or a Config object, '
f'but got {type(config)}')
f'but got {type(model)}')

if pretrained is True:
warnings.warn('Unable to find pre-defined checkpoint of the model.')
Expand Down
33 changes: 12 additions & 21 deletions mmpretrain/models/multimodal/blip/language_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,18 @@
import torch.nn as nn
from torch import Tensor, device

try:
from transformers.activations import ACT2FN
from transformers.modeling_outputs import (
BaseModelOutputWithPastAndCrossAttentions,
BaseModelOutputWithPoolingAndCrossAttentions,
CausalLMOutputWithCrossAttentions)
from transformers.modeling_utils import (PreTrainedModel,
apply_chunking_to_forward,
find_pruneable_heads_and_indices,
prune_linear_layer)
from transformers.models.bert.configuration_bert import BertConfig
except:
ACT2FN = None
BaseModelOutputWithPastAndCrossAttentions = None
BaseModelOutputWithPoolingAndCrossAttentions = None
CausalLMOutputWithCrossAttentions = None
PreTrainedModel = None
apply_chunking_to_forward = None
find_pruneable_heads_and_indices = None
prune_linear_layer = None
BertConfig = None
from transformers.activations import ACT2FN
from transformers.modeling_outputs import (
BaseModelOutputWithPastAndCrossAttentions,
BaseModelOutputWithPoolingAndCrossAttentions,
CausalLMOutputWithCrossAttentions)
from transformers.modeling_utils import PreTrainedModel
from transformers.pytorch_utils import (
apply_chunking_to_forward,
find_pruneable_heads_and_indices,
prune_linear_layer,
)
from transformers.models.bert.configuration_bert import BertConfig

from mmpretrain.registry import MODELS

Expand Down
2 changes: 1 addition & 1 deletion mmpretrain/models/multimodal/blip2/Qformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
BaseModelOutputWithPastAndCrossAttentions,
BaseModelOutputWithPoolingAndCrossAttentions,
CausalLMOutputWithCrossAttentions)
from transformers.modeling_utils import apply_chunking_to_forward
from transformers.pytorch_utils import apply_chunking_to_forward
from transformers.models.bert.configuration_bert import BertConfig
from transformers.utils import logging

Expand Down
4 changes: 2 additions & 2 deletions mmpretrain/models/multimodal/ofa/ofa_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from mmengine.utils import digit_version
from transformers.modeling_outputs import (
BaseModelOutputWithPastAndCrossAttentions, ModelOutput, Seq2SeqLMOutput)
from transformers.modeling_utils import (GenerationConfig, GenerationMixin,
PretrainedConfig)
from transformers.generation import GenerationConfig, GenerationMixin
from transformers.modeling_utils import PretrainedConfig

from mmpretrain.registry import MODELS
from ...backbones.resnet import Bottleneck, ResNet
Expand Down
9 changes: 5 additions & 4 deletions mmpretrain/models/multimodal/ram/bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
BaseModelOutputWithPastAndCrossAttentions,
BaseModelOutputWithPoolingAndCrossAttentions,
CausalLMOutputWithCrossAttentions)
from transformers.modeling_utils import (PreTrainedModel,
apply_chunking_to_forward,
find_pruneable_heads_and_indices,
prune_linear_layer)
from transformers.modeling_utils import PreTrainedModel
from transformers.pytorch_utils import (
apply_chunking_to_forward,
find_pruneable_heads_and_indices,
prune_linear_layer)
from transformers.models.bert.configuration_bert import BertConfig
from transformers.utils import logging

Expand Down
190 changes: 190 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
[project]
name = "mmpretrain"
version = "1.2.0"
description = "OpenMMLab Model Pretraining Toolbox and Benchmark"
readme = "README.md"
license = "Apache-2.0"
classifiers = [
'Development Status :: 4 - Beta',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
]
authors = [
{ name = "OpenMMLab", email = "[email protected]" },
]
requires-python = ">=3.10,<3.12"
dependencies = [
"albumentations==1.4.4",
"elasticdeform",
"ftfy",
"einops",
"open-clip-torch",
"requests",
"scikit-learn",
"regex",
"rich",
"timm",
"mmengine>=0.10.7",
"numpy<2",
"matplotlib>=3.10.1",
"seaborn>=0.13.2",
"torchmetrics",
"ninja>=1.11.1.4",
"transformers>=4.28.0",
"pycocotools",
"importlib-metadata>=8.7.0",
"modelindex>=0.0.2",
"mat4py>=0.6.0",
]

[dependency-groups] # optional (not shipped)
dev = [
"coverage",
"interrogate",
"ipdb>=0.13.13",
"jupyterlab>=4.3.5",
"pytest>=8.3.4",
"ruff>=0.9.6",
]

[project.optional-dependencies]
docs = [
"sphinx>=6.1.3",
"sphinx-rtd-theme>=2.0.0",
"sphinxcontrib-bibtex>=2.4.0",
"sphinxcontrib-mermaid>=0.9.0",
"sphinxcontrib-openapi>=0.8.1",
"sphinxcontrib-serializinghtml>=1.1.5",
"pytorch-sphinx-theme",
"nbsphinx>=0.8.9",
"jupyter-sphinx>=0.4.3",
"tabulate>=0.9.0",
]
cu118 = [
"torch==2.4.1",
"torchvision==0.19.1",
"torchaudio==2.4.1",
"mmcv==2.2.0",
"grad-cam<1.5.0",
]
cu121 = [
"torch==2.4.1",
"torchvision==0.19.1",
"torchaudio==2.4.1",
"mmcv==2.2.0",
"grad-cam<1.5.0",
]

[tool.uv]
conflicts = [
[
{ extra = "cu118" },
{ extra = "cu121" },
],
]

[tool.uv.sources]
torch = [
{ index = "pytorch-cu118", extra = "cu118" },
{ index = "pytorch-cu121", extra = "cu121" },
]
torchvision = [
{ index = "pytorch-cu118", extra = "cu118" },
{ index = "pytorch-cu121", extra = "cu121" },
]
torchaudio = [
{ index = "pytorch-cu118", extra = "cu118" },
{ index = "pytorch-cu121", extra = "cu121" },
]
mmcv = [
{ index = "mmcv-cu118", extra = "cu118" },
{ index = "mmcv-cu121", extra = "cu121" },
]
clip = { git = "https://github.com/openai/CLIP.git" }
pyedgeeval = { git = "https://github.com/haruishi43/py-edge-eval.git" }
pytorch-sphinx-theme = { git = "https://github.com/mzr1996/pytorch_sphinx_theme.git" }

[[tool.uv.index]]
name = "pytorch-cu118"
url = "https://download.pytorch.org/whl/cu118"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu121"
url = "https://download.pytorch.org/whl/cu121"
explicit = true

[[tool.uv.index]]
name = "mmcv-cu118"
url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.4/index.html"
format = "flat"
explicit = true

[[tool.uv.index]]
name = "mmcv-cu121"
url = "https://download.openmmlab.com/mmcv/dist/cu121/torch2.4/index.html"
format = "flat"
explicit = true

[tool.setuptools.packages.find] # custom discovery
include = ["mmpretrain*"] # pick the library
exclude = [
"data*", "configs*", "projects*", "notebooks*", "work_dirs*", "pretrained*", "third_party*",
]

[build-system]
requires = [
"setuptools>=65.5.1",
"wheel>=0.40.0",
"torch==2.4.1",
]
build-backend = "setuptools.build_meta"

[tool.ruff]
exclude = [".git", ".mypy_cache", ".ruff_cache", ".venv", "data", "splits", "tests/data", "work_dirs", "pretrained"]
line-length = 80
target-version = "py310"

[tool.ruff.lint]
# https://docs.astral.sh/ruff/rules/
fixable = ["ALL"]
unfixable = []
select = [
"A", # flake8-builtin
"B", # flake8-bugbear
"E", # pycodestyle error
"F", # Pyflakes
"I", # isort
"N", # pep8-naming
"W", # pycodestyle warning
"PL", # Pylint
"UP", # pyupgrade
]
ignore = [
"B006", # Do not use mutable data structures for arugment defaults
"B905", # Zip-without-explicit-strict
"E501", # Line too long
"E741", # Ambiguous variable name
"F403", # Unable to detect undefined names
"F722", # Checks for forward annotations
"F821", # Checks for uses of undefined names
"N801", # Class name should use CapWords convention
"N802", # Function name should be lowercase
"N803", # Function name should be lowercase
"N806", # Variable in function should be lowercase
"N812", # Lowercase imported as non-lowercase
"N814", # Camelcase imported as constant
"N999", # Invalid module name
"PLR0402", # import alias
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements (>50)
"PLR2004", # Magic value used in comparison
"PLW2901", # for loop variable overwritten by assignment target
]

[tool.ruff.format]
quote-style = "double"
line-ending = "auto"
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion requirements/mminstall.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mmcv>=2.0.0,<2.4.0
mmcv>=2.0.0,<3.0.0
mmengine>=0.8.3,<1.0.0
33 changes: 0 additions & 33 deletions setup.cfg

This file was deleted.

Loading