Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Florence2 support #31506

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b7e3311
add florence2 config
D4ve-R Jun 20, 2024
3adc633
add florence2 processing
D4ve-R Jun 20, 2024
b4cb3d6
fix florence2 processing, add image_utils.ChannelDimension
D4ve-R Jun 20, 2024
73041ba
fix florence2 processing, add missing tokenizers
D4ve-R Jun 20, 2024
1ce7813
add florence2 modeling
D4ve-R Jun 20, 2024
c2221a2
add florence2 __init__.py
D4ve-R Jun 20, 2024
6d1606e
make fixup
D4ve-R Jun 20, 2024
eaa2e7b
fix florence2 modeling, rm einops.rearrange dep
D4ve-R Jun 20, 2024
492d30f
fix florence2 config, make fixup
D4ve-R Jun 20, 2024
5b2737b
fix florence2 processing, make fixup
D4ve-R Jun 20, 2024
7cef9d9
fix florence2 processing, make repo-consistency
D4ve-R Jun 20, 2024
8875899
fix processing, add PILImageResampling
D4ve-R Jun 20, 2024
86d0862
fix import of optional dependencies
D4ve-R Jun 20, 2024
3765e73
add florence2 to models.__init__
D4ve-R Jun 20, 2024
3f915bd
add florence2 to transformers.__init__
D4ve-R Jun 20, 2024
bdb3706
make fix-copies
D4ve-R Jun 20, 2024
2d81135
fix formatting & typo
D4ve-R Jun 20, 2024
e9f86d0
fix __init__s & dummies
D4ve-R Jun 20, 2024
172a1dd
add tests florence2 processing
D4ve-R Jun 20, 2024
087ef0e
add tests florence2 modeling
D4ve-R Jun 20, 2024
fb234ef
fix tests florence2 processign vocabfile
D4ve-R Jun 20, 2024
0a615ba
fix rm import Florence2PostProcessor
D4ve-R Jun 21, 2024
26e1c23
fix rm unnecessary imports
D4ve-R Jun 21, 2024
f11c993
fix processing PILImageResampling
D4ve-R Jun 21, 2024
311da9c
fix make repo-consistency error
D4ve-R Jun 21, 2024
b429814
update tests
D4ve-R Jun 22, 2024
3d67beb
rename folders
D4ve-R Jun 22, 2024
8b88ca7
fix folder renaming
D4ve-R Jun 22, 2024
299670b
fix florence2 modeling, copy DropPath from beit
D4ve-R Jun 23, 2024
689ad98
update Florence2DropPath
D4ve-R Jun 25, 2024
6b7feb6
update Florence2Sequential
D4ve-R Jun 25, 2024
3addc02
update modeling_florence2, add model-prefix
D4ve-R Jun 25, 2024
0f624ac
update modeling_florence2, add DaViT prefixes
D4ve-R Jun 25, 2024
880811f
fix base_model_prefix
D4ve-R Jun 25, 2024
4069145
fix missing variables
D4ve-R Jun 26, 2024
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
24 changes: 24 additions & 0 deletions src/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@
"FlavaMultimodalConfig",
"FlavaTextConfig",
],
"models.florence2": [
"Florence2Config",
"Florence2VisionConfig",
],
"models.fnet": ["FNetConfig"],
"models.focalnet": ["FocalNetConfig"],
"models.fsmt": [
Expand Down Expand Up @@ -1130,6 +1134,7 @@
_import_structure["models.dpt"].extend(["DPTFeatureExtractor", "DPTImageProcessor"])
_import_structure["models.efficientnet"].append("EfficientNetImageProcessor")
_import_structure["models.flava"].extend(["FlavaFeatureExtractor", "FlavaImageProcessor", "FlavaProcessor"])
_import_structure["models.florence2"].extend(["Florence2Processor"])
_import_structure["models.fuyu"].extend(["FuyuImageProcessor", "FuyuProcessor"])
_import_structure["models.glpn"].extend(["GLPNFeatureExtractor", "GLPNImageProcessor"])
_import_structure["models.grounding_dino"].extend(["GroundingDinoImageProcessor"])
Expand Down Expand Up @@ -2119,6 +2124,14 @@
"FlavaTextModel",
]
)
_import_structure["models.florence2"].extend(
[
"Florence2ForConditionalGeneration",
"Florence2PreTrainedModel",
"Florence2VisionModel",
"Florence2VisionModelWithProjection",
]
)
_import_structure["models.fnet"].extend(
[
"FNetForMaskedLM",
Expand Down Expand Up @@ -5013,6 +5026,10 @@
FlavaMultimodalConfig,
FlavaTextConfig,
)
from .models.florence2 import (
Florence2Config,
Florence2VisionConfig,
)
from .models.fnet import FNetConfig
from .models.focalnet import FocalNetConfig
from .models.fsmt import (
Expand Down Expand Up @@ -5751,6 +5768,7 @@
FlavaImageProcessor,
FlavaProcessor,
)
from .models.florence2 import Florence2Processor
from .models.fuyu import FuyuImageProcessor, FuyuProcessor
from .models.glpn import GLPNFeatureExtractor, GLPNImageProcessor
from .models.grounding_dino import GroundingDinoImageProcessor
Expand Down Expand Up @@ -6593,6 +6611,12 @@
FlavaPreTrainedModel,
FlavaTextModel,
)
from .models.florence2 import (
Florence2ForConditionalGeneration,
Florence2PreTrainedModel,
Florence2VisionModel,
Florence2VisionModelWithProjection,
)
from .models.fnet import (
FNetForMaskedLM,
FNetForMultipleChoice,
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
fastspeech2_conformer,
flaubert,
flava,
florence2,
fnet,
focalnet,
fsmt,
Expand Down
84 changes: 84 additions & 0 deletions src/transformers/models/florence2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# 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.
from typing import TYPE_CHECKING

from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_torch_available,
is_vision_available,
)


_import_structure = {
"configuration_florence2": [
"Florence2Config",
"Florence2VisionConfig",
],
}

try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["processing_florence2"] = ["Florence2Processor"]


try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_florence2"] = [
"Florence2ForConditionalGeneration",
"Florence2PreTrainedModel",
"Florence2VisionModel",
"Florence2VisionModelWithProjection",
]


if TYPE_CHECKING:
from .configuration_florence2 import (
Florence2Config,
Florence2VisionConfig,
)

try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .processing_florence2 import Florence2Processor

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_florence2 import (
Florence2ForConditionalGeneration,
Florence2PreTrainedModel,
Florence2VisionModel,
Florence2VisionModelWithProjection,
)

else:
import sys

sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure)
Loading