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

Adding hiera #30356

Merged
merged 146 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
0cd30ee
initialized Structure
Feb 16, 2024
ba8a870
Merge branch 'huggingface:main' into main
Namangarg110 Feb 16, 2024
ec4111f
Updated variable names
Feb 16, 2024
8d27d82
Merge branch 'main' of https://github.com/namangarg110/transformers i…
Feb 16, 2024
77d2591
Merge branch 'huggingface:main' into main
Namangarg110 Feb 16, 2024
126de18
Added Config class, basic HF setup, convert_to_hf
Feb 16, 2024
479bfdc
Merge branch 'huggingface:main' into main
Namangarg110 Feb 16, 2024
75a3440
Fixed Convert function, added hiera to HF files, Initilized test files
Feb 16, 2024
2e2e638
Merge branch 'huggingface:main' into main
Namangarg110 Feb 16, 2024
5569dad
better naming for x in forward pass
Feb 16, 2024
11017c6
Moved utils to hiera
Feb 17, 2024
ad959d4
Change hiera -> hiera_model
Namangarg110 Feb 17, 2024
fac7b23
Fixed integration into tranformers
Namangarg110 Feb 17, 2024
866ffc7
Fix: Convert Checkpoint
Namangarg110 Feb 17, 2024
deba4fc
Merge branch 'huggingface:main' into main
Namangarg110 Feb 17, 2024
b3828e1
added documentation for hiera
Namangarg110 Feb 17, 2024
82672b2
added documentation for hiera
Namangarg110 Feb 17, 2024
00478b6
added Docstings to models, Transformers based changes
Namangarg110 Feb 17, 2024
4144fe8
make style and quality
Namangarg110 Feb 18, 2024
d23a70d
make style and quality
Namangarg110 Feb 18, 2024
c677783
Integration & Block tests running
Namangarg110 Feb 26, 2024
9cee5e2
Merge branch 'huggingface:main' into main
Namangarg110 Feb 26, 2024
419ccf8
Merge branch 'huggingface:main' into main
Namangarg110 Feb 28, 2024
130b55b
Fixed bugs
Namangarg110 Feb 28, 2024
733c59e
initialized Structure
Feb 16, 2024
86a43ed
Updated variable names
Feb 16, 2024
1433a7c
Added Config class, basic HF setup, convert_to_hf
Feb 16, 2024
46d495c
Fixed Convert function, added hiera to HF files, Initilized test files
Feb 16, 2024
a25a3a7
better naming for x in forward pass
Feb 16, 2024
51d11f5
Moved utils to hiera
Feb 17, 2024
ea872fe
Change hiera -> hiera_model
Namangarg110 Feb 17, 2024
fa570f3
Fixed integration into tranformers
Namangarg110 Feb 17, 2024
7e41f49
Fix: Convert Checkpoint
Namangarg110 Feb 17, 2024
f47d06a
added documentation for hiera
Namangarg110 Feb 17, 2024
9d249e0
added documentation for hiera
Namangarg110 Feb 17, 2024
7cff186
added Docstings to models, Transformers based changes
Namangarg110 Feb 17, 2024
c4a4168
make style and quality
Namangarg110 Feb 18, 2024
01e4662
make style and quality
Namangarg110 Feb 18, 2024
cc2c623
Integration & Block tests running
Namangarg110 Feb 26, 2024
f172b74
Fixed bugs
Namangarg110 Feb 28, 2024
9536140
Merge branch 'add_model_hiera' of https://github.com/namangarg110/tra…
Namangarg110 Feb 28, 2024
35b3720
Removed tim dependency
Namangarg110 Feb 28, 2024
5f90a25
added HieraBlock
Namangarg110 Feb 28, 2024
ebde8c8
fixed: Model name
Namangarg110 Feb 28, 2024
772e421
added tests for HieraModel, HieraBlock
Namangarg110 Feb 28, 2024
850350e
fixed imports
Namangarg110 Feb 28, 2024
20f3bc0
fixed quality & copies
Namangarg110 Feb 28, 2024
12ef68a
Fixes
Namangarg110 Feb 28, 2024
3faf1e7
Update docs/source/en/model_doc/hiera.md
Namangarg110 Feb 29, 2024
7debb8d
Update docs/source/en/model_doc/hiera.md
Namangarg110 Feb 29, 2024
942e8e9
Update docs/source/en/model_doc/hiera.md
Namangarg110 Feb 29, 2024
4e9ddd4
Update src/transformers/models/hiera/configuration_hiera.py
Namangarg110 Feb 29, 2024
c9e7704
Update src/transformers/models/hiera/configuration_hiera.py
Namangarg110 Feb 29, 2024
d8e8b73
Update src/transformers/models/hiera/modeling_hiera.py
Namangarg110 Feb 29, 2024
6027674
Update src/transformers/models/hiera/modeling_hiera.py
Namangarg110 Feb 29, 2024
0e3a0e5
Fixed formatting
Namangarg110 Feb 29, 2024
e9a4126
Code quality & Import differences
Namangarg110 Feb 29, 2024
b057d91
quality and repo-consistency fix
Namangarg110 Feb 29, 2024
d7210cc
fixed no torch error
Namangarg110 Feb 29, 2024
10dfa68
Docstring fix
Namangarg110 Feb 29, 2024
f81fa76
Docstring fix
Namangarg110 Feb 29, 2024
5951e58
doc string fix
Namangarg110 Feb 29, 2024
9b194a4
fixed example usage
Namangarg110 Feb 29, 2024
dd3da8f
Resolved issues in modeling_hiera
Namangarg110 Mar 7, 2024
3475b2d
Removed Hiera MAE
Namangarg110 Mar 7, 2024
5ba0aaf
Added test and resolved bug
Namangarg110 Mar 15, 2024
3adb788
fixed doc string
Namangarg110 Mar 15, 2024
c69df92
First commit
EduardoPach Mar 28, 2024
2e1f8d4
Finished conversion script and model forward working
EduardoPach Mar 29, 2024
5924b6c
Resolved all issues
Namangarg110 Mar 31, 2024
8360db8
nits
EduardoPach Apr 1, 2024
9651854
Improving tests
EduardoPach Apr 1, 2024
88f81d0
Nits
EduardoPach Apr 1, 2024
10b74a7
More nits
EduardoPach Apr 1, 2024
4700ba9
Improving HieraForMaskedImageModeling
EduardoPach Apr 1, 2024
0c544b0
Merge remote-tracking branch 'upstream/main' into adding-hiera
EduardoPach Apr 1, 2024
be26de4
More improvements and nits
EduardoPach Apr 1, 2024
ff2ea88
Fixed docstrings of outputs
EduardoPach Apr 1, 2024
4463fb0
More fixes
EduardoPach Apr 1, 2024
b92081d
More imrpovments
EduardoPach Apr 2, 2024
e38b25d
Updated conversion script
EduardoPach Apr 3, 2024
00283b1
Fixed docstrings
EduardoPach Apr 3, 2024
b72cc8e
Improved tests
EduardoPach Apr 3, 2024
707484f
Fixed attentou outputs test
EduardoPach Apr 3, 2024
cc04cc3
All tests green
EduardoPach Apr 4, 2024
35350fe
Merge remote-tracking branch 'upstream/main' into adding-hiera
EduardoPach Apr 4, 2024
7682df3
Merge remote-tracking branch 'upstream/main' into adding-hiera
EduardoPach Apr 18, 2024
4a6c6b9
Merge remote-tracking branch 'upstream/main' into adding-hiera
EduardoPach Apr 19, 2024
601c83a
Merge branch 'adding-hiera' into adding-hiera-cont
EduardoPach Apr 19, 2024
219024f
Removed unnecessary file
EduardoPach Apr 19, 2024
aedaab9
contribution attribution
EduardoPach Apr 23, 2024
1d30a29
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Apr 23, 2024
29126fd
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Apr 24, 2024
381116b
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Apr 25, 2024
8b7d5f7
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Apr 26, 2024
d48c7b5
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Apr 29, 2024
3dc48d1
Resolved a few issues
Namangarg110 May 8, 2024
22ad148
Resolved Comments
Namangarg110 May 9, 2024
aab41dc
Updated model repo id and fixed bugs
Namangarg110 May 9, 2024
be45286
Removed loss print
Namangarg110 May 9, 2024
de97157
Make tests green
EduardoPach May 9, 2024
ae9fa03
Updated docstrings
EduardoPach May 9, 2024
761f9e9
Fix style
EduardoPach May 9, 2024
b30718a
Fixed num_heads in config
EduardoPach May 12, 2024
1d8fed9
Removed unnecessary video checkpoint related code in the conversion s…
EduardoPach May 12, 2024
d736e56
Fix style
EduardoPach May 12, 2024
fc34d3e
Changed atol in conversion script
EduardoPach May 12, 2024
d1a8c82
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach May 12, 2024
a9a29b3
HieraConfig
EduardoPach May 12, 2024
3525f1c
Fix copies
EduardoPach May 12, 2024
c83de0a
Fixed typo
EduardoPach May 13, 2024
ed73189
Resolved few issues
Namangarg110 May 21, 2024
7f5d27c
make
Namangarg110 May 21, 2024
cedc6e8
converted conv_nd -> nn.Module
Namangarg110 May 21, 2024
f4a343c
Removed video complexities
Namangarg110 May 23, 2024
6c65b30
Removed video complexities
Namangarg110 May 23, 2024
7a6a99e
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach May 27, 2024
73980d0
fix style
EduardoPach May 27, 2024
48a17dc
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach May 27, 2024
267bf7d
Addressing comments
EduardoPach May 27, 2024
41d6081
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach May 28, 2024
0ba0290
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach May 28, 2024
3a7ab67
Update src/transformers/models/hiera/modeling_hiera.py
EduardoPach Jun 11, 2024
c35fb3f
Update src/transformers/models/hiera/modeling_hiera.py
EduardoPach Jun 11, 2024
660d0b1
Update src/transformers/models/hiera/modeling_hiera.py
EduardoPach Jun 11, 2024
cc259de
Fix style
EduardoPach Jun 11, 2024
80dc2cb
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Jun 11, 2024
20951c1
Fixed tests
EduardoPach Jun 11, 2024
48a317e
Fixed typo
EduardoPach Jun 11, 2024
192d7db
Fixed interpolate test
EduardoPach Jun 11, 2024
cafae1b
Made torch fx compatible
EduardoPach Jun 12, 2024
c54100e
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Jun 12, 2024
75fd1c2
Made sure imageprocesor is correct
EduardoPach Jun 12, 2024
7e42e01
Addressed comments
EduardoPach Jun 12, 2024
776d2e2
Noise directly as torch
EduardoPach Jun 12, 2024
ad09194
Remove unnecesary attr
EduardoPach Jun 12, 2024
14a686b
Added return_dit
EduardoPach Jun 12, 2024
ef2ea02
Update src/transformers/models/hiera/__init__.py
EduardoPach Jul 7, 2024
190c662
Updated checkpoints
EduardoPach Jul 7, 2024
ec0ad99
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Jul 7, 2024
d76183e
[run_slow] hiera
Namangarg110 Jul 9, 2024
c67bacf
Fixed device mismatch
Namangarg110 Jul 10, 2024
ec2c480
[run_slow] hiera
Namangarg110 Jul 10, 2024
7b840d8
Merge remote-tracking branch 'upstream/main' into adding-hiera-cont
EduardoPach Jul 11, 2024
834bc8e
Fixed GPU tests
EduardoPach Jul 11, 2024
0a06b4d
[run_slow] hiera
EduardoPach Jul 11, 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
4 changes: 4 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@
title: FocalNet
- local: model_doc/glpn
title: GLPN
- local: model_doc/hiera
title: Hiera
- local: model_doc/imagegpt
title: ImageGPT
- local: model_doc/levit
Expand Down Expand Up @@ -680,6 +682,8 @@
title: CLAP
- local: model_doc/encodec
title: EnCodec
- local: model_doc/hiera
title: Hiera
- local: model_doc/hubert
title: Hubert
- local: model_doc/mctct
Expand Down
1 change: 1 addition & 0 deletions docs/source/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Flax), PyTorch, and/or TensorFlow.
| [Grounding DINO](model_doc/grounding-dino) | ✅ | ❌ | ❌ |
| [GroupViT](model_doc/groupvit) | ✅ | ✅ | ❌ |
| [HerBERT](model_doc/herbert) | ✅ | ✅ | ✅ |
| [Hiera](model_doc/hiera) | ✅ | ❌ | ❌ |
| [Hubert](model_doc/hubert) | ✅ | ✅ | ❌ |
| [I-BERT](model_doc/ibert) | ✅ | ❌ | ❌ |
| [IDEFICS](model_doc/idefics) | ✅ | ✅ | ❌ |
Expand Down
48 changes: 48 additions & 0 deletions docs/source/en/model_doc/hiera.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--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.

⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.

-->

# Hiera

## Overview

Hiera was proposed in [Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles](https://arxiv.org/abs/2306.00989) by Chaitanya Ryali, Yuan-Ting Hu, Daniel Bolya, Chen Wei, Haoqi Fan, Po-Yao Huang, Vaibhav Aggarwal, Arkabandhu Chowdhury, Omid Poursaeed, Judy Hoffman, Jitendra Malik, Yanghao Li, Christoph Feichtenhofer

The paper introduces "Hiera," a hierarchical Vision Transformer that simplifies the architecture of modern hierarchical vision transformers by removing unnecessary components without compromising on accuracy or efficiency. Unlike traditional transformers that add complex vision-specific components to improve supervised classification performance, Hiera demonstrates that such additions, often termed "bells-and-whistles," are not essential for high accuracy. By leveraging a strong visual pretext task (MAE) for pretraining, Hiera retains simplicity and achieves superior accuracy and speed both in inference and training across various image and video recognition tasks. The approach suggests that spatial biases required for vision tasks can be effectively learned through proper pretraining, eliminating the need for added architectural complexity.

The abstract from the paper is the following:

*Modern hierarchical vision transformers have added several vision-specific components in the pursuit of supervised classification performance. While these components lead to effective accuracies and attractive FLOP counts, the added complexity actually makes these transformers slower than their vanilla ViT counterparts. In this paper, we argue that this additional bulk is unnecessary. By pretraining with a strong visual pretext task (MAE), we can strip out all the bells-and-whistles from a state-of-the-art multi-stage vision transformer without losing accuracy. In the process, we create Hiera, an extremely simple hierarchical vision transformer that is more accurate than previous models while being significantly faster both at inference and during training. We evaluate Hiera on a variety of tasks for image and video recognition. Our code and models are available at https://github.com/facebookresearch/hiera.*

This model was a joint contibution by [EduardoPacheco](https://huggingface.co/EduardoPacheco) and [namangarg110](https://huggingface.co/namangarg110). The original code can be found [here] (https://github.com/facebookresearch/hiera).

## HieraConfig

[[autodoc]] HieraConfig

## HieraModel

[[autodoc]] HieraModel
- forward

## HieraForPreTraining

[[autodoc]] HieraForPreTraining
- forward

## HieraForImageClassification

[[autodoc]] HieraForImageClassification
- forward
18 changes: 18 additions & 0 deletions src/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
"GroupViTVisionConfig",
],
"models.herbert": ["HerbertTokenizer"],
"models.hiera": ["HieraConfig"],
"models.hubert": ["HubertConfig"],
"models.ibert": ["IBertConfig"],
"models.idefics": ["IdeficsConfig"],
Expand Down Expand Up @@ -2284,6 +2285,15 @@
"GroupViTVisionModel",
]
)
_import_structure["models.hiera"].extend(
[
"HieraBackbone",
"HieraForImageClassification",
"HieraForPreTraining",
"HieraModel",
"HieraPreTrainedModel",
]
)
_import_structure["models.hubert"].extend(
[
"HubertForCTC",
Expand Down Expand Up @@ -5111,6 +5121,7 @@
GroupViTVisionConfig,
)
from .models.herbert import HerbertTokenizer
from .models.hiera import HieraConfig
from .models.hubert import HubertConfig
from .models.ibert import IBertConfig
from .models.idefics import (
Expand Down Expand Up @@ -6794,6 +6805,13 @@
GroupViTTextModel,
GroupViTVisionModel,
)
from .models.hiera import (
HieraBackbone,
HieraForImageClassification,
HieraForPreTraining,
HieraModel,
HieraPreTrainedModel,
)
from .models.hubert import (
HubertForCTC,
HubertForSequenceClassification,
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 @@ -105,6 +105,7 @@
grounding_dino,
groupvit,
herbert,
hiera,
hubert,
ibert,
idefics,
Expand Down
2 changes: 2 additions & 0 deletions src/transformers/models/auto/configuration_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
("graphormer", "GraphormerConfig"),
("grounding-dino", "GroundingDinoConfig"),
("groupvit", "GroupViTConfig"),
("hiera", "HieraConfig"),
("hubert", "HubertConfig"),
("ibert", "IBertConfig"),
("idefics", "IdeficsConfig"),
Expand Down Expand Up @@ -403,6 +404,7 @@
("grounding-dino", "Grounding DINO"),
("groupvit", "GroupViT"),
("herbert", "HerBERT"),
("hiera", "Hiera"),
("hubert", "Hubert"),
("ibert", "I-BERT"),
("idefics", "IDEFICS"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/image_processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
("glpn", ("GLPNImageProcessor",)),
("grounding-dino", ("GroundingDinoImageProcessor",)),
("groupvit", ("CLIPImageProcessor",)),
("hiera", ("BitImageProcessor",)),
("idefics", ("IdeficsImageProcessor",)),
("idefics2", ("Idefics2ImageProcessor",)),
("imagegpt", ("ImageGPTImageProcessor",)),
Expand Down
5 changes: 5 additions & 0 deletions src/transformers/models/auto/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
("graphormer", "GraphormerModel"),
("grounding-dino", "GroundingDinoModel"),
("groupvit", "GroupViTModel"),
("hiera", "HieraModel"),
("hubert", "HubertModel"),
("ibert", "IBertModel"),
("idefics", "IdeficsModel"),
Expand Down Expand Up @@ -295,6 +296,7 @@
("gpt2", "GPT2LMHeadModel"),
("gpt_bigcode", "GPTBigCodeForCausalLM"),
("gptsan-japanese", "GPTSanJapaneseForConditionalGeneration"),
("hiera", "HieraForPreTraining"),
("ibert", "IBertForMaskedLM"),
("idefics", "IdeficsForVisionText2Text"),
("idefics2", "Idefics2ForConditionalGeneration"),
Expand Down Expand Up @@ -535,6 +537,7 @@
("efficientnet", "EfficientNetModel"),
("focalnet", "FocalNetModel"),
("glpn", "GLPNModel"),
("hiera", "HieraModel"),
("imagegpt", "ImageGPTModel"),
("levit", "LevitModel"),
("mobilenet_v1", "MobileNetV1Model"),
Expand Down Expand Up @@ -610,6 +613,7 @@
),
("efficientnet", "EfficientNetForImageClassification"),
("focalnet", "FocalNetForImageClassification"),
("hiera", "HieraForImageClassification"),
("imagegpt", "ImageGPTForImageClassification"),
(
"levit",
Expand Down Expand Up @@ -1258,6 +1262,7 @@
("dinat", "DinatBackbone"),
("dinov2", "Dinov2Backbone"),
("focalnet", "FocalNetBackbone"),
("hiera", "HieraBackbone"),
("maskformer-swin", "MaskFormerSwinBackbone"),
("nat", "NatBackbone"),
("pvt_v2", "PvtV2Backbone"),
Expand Down
59 changes: 59 additions & 0 deletions src/transformers/models/hiera/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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,
)


_import_structure = {"configuration_hiera": ["HieraConfig"]}

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_hiera"] = [
"HieraForImageClassification",
"HieraForPreTraining",
"HieraBackbone",
"HieraModel",
"HieraPreTrainedModel",
]

if TYPE_CHECKING:
from .configuration_hiera import HieraConfig

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_hiera import (
HieraBackbone,
HieraForImageClassification,
HieraForPreTraining,
HieraModel,
HieraPreTrainedModel,
)

else:
import sys

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