HydraViT: Stacking Heads for a Scalable ViT

The architecture of Vision Transformers (ViTs), particularly the Multi-head Attention (MHA) mechanism, imposes substantial hardware demands. Deploying ViTs on devices with varying constraints, such as mobile phones, requires multiple models of different sizes. However, this approach has limitations, such as training and storing each required model separately. This paper introduces HydraViT, a novel approach that addresses these limitations by stacking attention heads to achieve a scalable ViT. By repeatedly changing the size of the embedded dimensions throughout each layer and their corresponding number of attention heads in MHA during training, HydraViT induces multiple subnetworks. Thereby, HydraViT achieves adaptability across a wide spectrum of hardware environments while maintaining performance. Our experimental results demonstrate the efficacy of HydraViT in achieving a scalable ViT with up to 10 subnetworks, covering a wide range of resource constraints. HydraViT achieves up to 5 p.p. more accuracy with the same GMACs and up to 7 p.p. more accuracy with the same throughput on ImageNet-1K compared to the baselines, making it an effective solution for scenarios where hardware availability is diverse or varies over time. Source code available at https://github.com/ds-kiel/HydraViT.

Paper

Similar papers

Peer review

Reviewer aEuL6/10 · confidence 3/52024-06-21

Summary

This study proposes a training scheme called stochastic dropout training, thereby presenting its resulting models, called HydraViT. From the observation that ViT with a smaller version can be understood as a subset of a larger version, the authors propose to sample a subnetwork of a larger ViT. Although this scheme trains the subnetwork of ViT, during inference, the size of ViT can be flexibly chosen considering hardware specs. Experiments demonstrate the validity of the proposed method.

Strengths

I would like to admit good motivation for choosing the subnetwork of ViT for training by slicing its dimension. Further, incorporating order importance can be useful for other purposes during training and inference. The flexible choice of dimension during inference can be useful for several practical scenarios, as described in the manuscript.

Weaknesses

When we change the size of ViT, such as hidden dim, head size, and embedding dim, can we guarantee consistent behavior of ViT? In other words, if several dimensions of ViT change, ViT might exhibit inconsistent behavior. For example, the self-attention operation is defined as $softmax(\frac{Q K}{\sqrt{d_k}})V$ and calibrates its scale using $d_k$, the dimension of the quary and key. I would like to know how the authors incorporated different dimensions into the self-attention layers. The concept of training subnetwork might be similar to Dropout. I would say that though Dropout applies stochastic dropping without order-awareness, the schochastic dropout training proposed in this study incorporates the ordering, starting from the first elements. In this regard, the proposed method can be understood as a special case of Dropout. I am not saying that the contribution is weak due to similarity; however, I would like to know whether the authors adopted a $1/p$ scaling similar to Dropout. Specifically, the Dropout scheme drops elements during training and uses all elements during the test phase. To have consistent output from Dropout, we apply $1/p$ scaling during training. For $p=0.5$, we amplify the output of Dropout by twice. By adopting this practice, we obtain a consistent output scale. In consideration of this, the training subnetwork of ViT may require scale calibration similar to Dropout. Similarly, though the size of ViT can be flexibly chosen during inference, this may require scale calibration with respect to the size of ViT to have consistent behavior of ViT.

Questions

See weaknesses. Although I would like to admit the motivation and novelty of the proposed method, changing demensions of ViT may cause inconsistent behavior of ViT in self-attention or may require scale calibration for an intermediate feature map similar to Dropout. The proposed method may seem plausible at first glance, but technically, we should be careful when changing the dimension of ViT. I would like to know whether the authors addressed these issues.

Rating

6

Confidence

3

Soundness

2

Presentation

3

Contribution

3

Limitations

The authors discussed several limitations as occasion arises.

Reviewer 1s2T7/10 · confidence 4/52024-06-28

Summary

Building on the concept of Matryoshka Representation Learning, the authors propose a novel variant of Vision Transformers (ViT) that improves quality-speed trade-offs. Specifically, the proposed ViT model, trains on subsets of embedding dimensions and associated attention heads, which are ordered by importance. In each training iteration a subset of dimensions is trained. The authors demonstrate in a series of qualitative and quantitative experiments the improved performance.

Strengths

The paper addresses the efficiency of Vision Transformers. With the increasing size of current models and the ongoing trend that larger models perform better, it is of great importance to the research community to improve the quality / size trade-off. I want to particularly highlight the excellent presentation of the paper. The contributions are precisely defined and very clearly communicated and explained. Related to the point above, the paper sports a good discussion of related work and clearly defines the relative positioning of the paper at hand to related work. Another key strength of the paper is the experimental section. The paper includes both good quantitative and qualitative evaluations.

Weaknesses

This paper does not have many weaknesses. If I had to pick anything, the qualitative gain over the baselines is relatively limited. I can imagine that making stochastic training perform efficiently on modern hardware. It would be great to see an extensive discussion about how to efficiently implement such stochastic training.

Questions

As mentioned in the weaknesses section, I am interested how the stochastic training impacts training time and hardware utilization.

Rating

7

Confidence

4

Soundness

4

Presentation

4

Contribution

3

Limitations

The authors do not address limitations of the paper. I do not see key missing limitations.

Reviewer Yk3V6/10 · confidence 4/52024-07-01

Summary

ViTs that allow users to dynamically select the amount of RAM consumed or latency at deployment are valuable. This paper proposes HydraViT, a training procedure that enables plain ViTs to perform relatively well when attention heads and embedding dimensions are dropped on demand. During training, HydraViT samples the number of attention heads (H), selects the corresponding embedding dimension (H times 64), extracts the subnetwork, and updates the subnetwork's parameters. HydraViT achieves a better trade-off between compute and performance than prior work.

Strengths

1. The paper is well motivated, well presented, and clear. Resource flexibility is often a missing feature of pretrained models and is an important topic of study. 2. The experimental conditions are strong, i.e., the DeiT procedure is used, which is a commonly used recipe for training ViTs from scratch on ImageNet. DeiT III is a superior recipe, however I don’t expect an improved training recipe will change the conclusions of this paper. 3. HydraViT significantly outperforms SortedNet, especially at higher throughputs. And it offers far more flexibility than MatFormer. 4. More heads leading to more compact representations is an interesting finding.

Weaknesses

1. The only reported results are on the ImageNet-1k validation set. There are no segmentation or object detection experiments, or other ImageNet-1k test sets — which are easy to implement and would be a valuable addition to the paper. 2. To me, HydraViT is a straightforward combination of SortedNet (which adjusts embedding dimension) and DynaBERT (which adjusts the number of attention heads and MLP size). 3. Missing comparison to DynaBERT trained from scratch (table 3). Considering DynaBERT is 1 of 3 baseline methods, I expect a direct comparison to it when trained from scratch.

Questions

1. Some experiments initialize models from DeiT-tiny, which has dim=128. How are the weights of the full network, i.e., ViT-B, initialized in this case? Why not initialize from DeiT-B? 2. If one wishes to train 3 models — say ViT-Tiny, ViT-Small, and ViT-Base — do you advise training these three models separately or train a HydraViT with 3 sub-networks of the same size as the independent models?

Rating

6

Confidence

4

Soundness

3

Presentation

4

Contribution

4

Limitations

I don't believe limitations are adequately addressed. Potential limitations include: lack of scaling to larger models and datasets beyond ImageNet-1k.

Reviewer 2Apv7/10 · confidence 4/52024-07-09

Summary

The paper proposes a new training scheme for ViTs to enable creating models with varying sizes (in the terms of the number of attention heads in multi-head attention layers). Full version of the model can be then used when more computational resources are available, and smaller portions of the model (with less attention heads operating sorted via importance) can be used when less computational power is available. The authors perform experiments on ImageNet-1k and compare the results with DeiT and some techniques to obtain more ‘dynamic’ models.

Strengths

- The idea is interesting, simple, straight-forward in interpretation and I believe that it could be useful in some practical applications. - It is a nice direction to treat deep neural networks in a more ‘modular’ manner. - The methodology is clearly described, the authors provide many helpful visualizations.

Weaknesses

- The paper puts a lot of stress on suitability of different subnetworks in their approach and its adaptability for different hardware platforms and mobile devices (e.g. “HydraViT achieves adaptability across a wide spectrum of hardware environments while maintaining performance.”), however they do not test their approach on different hardware platforms (they test their approach on NVIDIA A100 80GB, for which the hard constraints are not valid at all). - The authors do not focus on the memory aspect in the part “during inference, HydraViT can dynamically select the number of heads based on the hardware demands” - while in terms of computation, dynamic reduction of the size can help, I assume that the parameters of the ‘dropped’ heads are still stored on a given hardware platform (therefore, take the disk space). Also, what about the delays caused by dynamic changes of the model architecture in the given example (video streams)? It would be nice to provide some numbers on how much time it takes to rebuild the model. - Although the authors state in the checklist that “Error bars are not reported because it would be too computationally expensive”, it should be stated as a limitation of the experiments, because it decreases the chance to fairly compare the algorithms. At least some smaller portions of the results could be given with error bars to support the findings and increase the soundness. - The authors do not focus on the fact that although DeiT-T is an equivalent of 5.7M parameter HydraViT (which they state), when trained from scratch, HydraViT obtains much lower accuracy (more than 3 p.p. less) compared to the case, in which DeiT’s weights are used as a base. Also, it is difficult to fairly compare some of the results as the setups are not equivalents. - The authors motivate their work by stating that their approach is the answer to building models with different sizes for the same model family “Despite not having a significant accuracy difference, each of these models needs to be individually trained”. In fact, smaller and larger models do exhibit large accuracy differences, which can be even seen in Tab. 2 in this paper (DeiT-T achieves 72.2 accuracy compared to 81.8 for DeiT base).

Questions

- “We also show that training HydraViT for more epochs can further improve accuracy.” - isn’t it caused among others by the fact that not all images are seen by all attention maps during each epoch (as a result of subnetwork sampling)? - What possible impacts on generalization of the minimum and larger subnetworks can have the proposed sampling technique? The first part is always used in the subnetwork sampling procedure and the last attention heads are trained the least often.These aspects should be discussed more thoroughly. - Tab. 3: What is the reason for the large difference between a network trained from scratch and initialized with DeiT-T for the smallest model? They should be equivalents, as the first 3 attention maps are used in each training step. - Why are the results for HydraViT trained from scratch not given in Tab. 3? - How much time does it take to rebuild the model? Is it suitable for the example application mentioned in the paper - video streams?

Rating

7

Confidence

4

Soundness

3

Presentation

3

Contribution

3

Limitations

The limitations could be better discussed. While the authors state in the checklist that "while we did not include a separate section, we do discuss limitations for every result.", it would be nice to squeeze it somewhere in the last section to make it more visible and transparent. I mention some example limitations below: - E.g. not having the error bars and comparing the performance of the models (Especially those trained from scratch) based on single runs can be perceived as a limitation. Although the authors state in the checklist (which is a plus) that “Error bars are not reported because it would be too computationally expensive”, it would be nice to state it as a limitation. - Also, the authors do not discuss what possible impacts on learning/generalization/overfitting of the minimum subnetworks/maximum subnetworks can have increasing the number of epochs significantly. - The authors do not discuss the limitations of applying the dynamic model rebuilding in practice.

Reviewer aEuL2024-08-09

Thank you for response.

Thank you for your detailed response and clarification. Now I understand that the proposed method is free of the inconsistency issues I mentioned, such as $d_k$. I raised my rating (4->6). I hope that the authors add these clarifications in the next version of this manuscript. Good luck!

Authorsrebuttal2024-08-09

New results: HydraViT from scratch 800 epochs

**UPDATE.** As promised, we have completed the from-scratch training for HydraViT-800e. The results are as follows and will be added to Table 3 and 4 in the revised version of the paper. The results for HydraViT-800e initialized with DeiT-T has already been reported in Table 3 of the paper. | Model | Accuracy from scratch |:-:|:-:| | HydraViT-3H | **68.78** | HydraViT-4H | 74.83 | HydraViT-5H | 78.07 | HydraViT-6H | **79.84** | HydraViT-7H | 80.98 | HydraViT-8H | 81.54 | HydraViT-9H | 81.73 | HydraViT-10H| 81.84 | HydraViT-11H| 81.90 | HydraViT-12H| **81.93** When HydraViT was trained for 300 epochs, none of its submodels reached their best local optima. Therefore, incorporating a pre-trained DeiT-T model during this phase enhanced accuracy across all submodels. However, with 800 epochs of training, the submodels had sufficient time to move towrad their best possible local optima. In this extended training scenario, adding a pre-trained DeiT-T model provided initial guidance for smaller submodels, such as HydraViT-3H, which improved their accuracy. This initialization, however, resulted in a slight decrease in accuracy for larger submodels, such as HydraViT-12H, favoring smaller submodels, see Table 3.

Reviewer Yk3V2024-08-11

Final Review

I thank the authors for their rebuttal. I am very familiar with SortedNet but not DynaBERT, so I appreciate the explanation. I also appreciate the added evaluations, I believe it strengthens the paper. Overall, I think the core contribution of this paper is simple — it splits the model along the embedding dimension, reducing the number of heads. Although this can be seen as a "straightforward" innovation over SortedNet, I like it and believe it could be very useful to the community. I will increase my score from 5 to 6.

Reviewer 2Apv2024-08-12

Thank you for your very thorough response to my comments. I hope that the authors will add these additional results and discussions to their manuscript. As the authors have done a lot of work to improve the paper, I am changing my rating from 6 to 7, good luck!

Reviewer 1s2T2024-08-12

Final Review

I would like to thank the authors for their exhaustive response to both my questions and the questions by the follow reviewers. I keep my positive score and remain a proponent of this paper.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC