Vision-RWKV: Efficient and Scalable Visual Perception with RWKV-Like Architectures

## Abstract

Abstract † † * Equal contribution;   🖂 Corresponding author (wangwenhai362@gmail.com) Transformers have revolutionized computer vision and natural language processing, but their high computational complexity limits their application in high-resolution image processing and long-context analysis.
This paper introduces Vision-RWKV (VRWKV), a model adap-ted from the RWKV model used in the NLP field with necessary modifications for vision tasks.
Similar to the Vision Transformer (ViT), our model is designed to efficiently handle sparse inputs and demonstrate robust global processing capabilities, while also scaling up effectively, accommodating both large-scale parameters and extensive datasets.
Its distinctive advantage lies in its reduced spatial aggregation complexity, which renders it exceptionally adept at processing high-resolution images seamlessly, eliminating the necessity for windowing operations.
Our evaluations demonstrate that VRWKV surpasses ViT’s performance in image classification and has significantly faster speeds and lower memory usage processing high-resolution inputs. In dense prediction tasks, it outperforms window-based models, maintaining comparable speeds. These results highlight VRWKV’s potential as a more efficient alternative for visual perception tasks.
Code is released at https://github.com/OpenGVLab/Vision-RWKV .

###### Keywords:

## 1 Introduction

Vision Transformers (ViTs) [, , , , ], renowned for their flexibility and global information processing capabilities, have established new benchmarks in a variety of vision tasks in the past few years.
However, the quadratic computational complexity associated with ViTs limits their ability to efficiently process high-resolution images and lengthy sequences, posing a significant barrier to their broader application.
As a result, the exploration of a vision architecture that integrates the versatility and comprehensive processing strengths of ViTs, while reducing computational demands, has emerged as a crucial area of research.

Figure: Figure 1: Performance and efficiency comparison of Vision-RWKV (VRWKV) and ViT. (a) $\rm AP^{b}$ comparison of VRWKV and ViT [] with window attention and global attention on the COCO [] dataset. (b) Inference speed comparison of VRWKV-T and ViT-T across input resolutions ranging from 224 to 2048. (c) GPU memory comparison of VRWKV-T and ViT-T across input resolutions from 224 to 2048.
Refer to caption: x1.png

In recent developments within natural language processing (NLP), models like RWKV [] and Mamba [] have emerged as popular solutions for achieving heightened efficiency and processing lengthy texts.
These innovative models have demonstrated attributes similar to transformers [, , , , , , , , ] in NLP tasks, including the ability to handle long-range dependencies and parallel processing.
Furthermore, they have also proven to be scalable, performing well with large-scale NLP datasets.
Considering the significant differences between image and text modalities, it remains challenging to envision these methods entirely supplanting ViTs for vision-related tasks.
It is imperative to conduct an in-depth analysis of how these models are applied to vision tasks, examining their scalability concerning data and parameters, their efficiency in handling sparse visual data, such as masked image modeling, and the necessary techniques to ensure model stability during scaling up.

In this work, we introduce Vision-RWKV (VRWKV), which is designed to adapt the RWKV architecture for vision tasks. This adaptation preserves the core structure and benefits of RWKV [] while integrating critical modifications to tailor it for processing visual data.
Specifically, we introduce a quad-directional shift (Q-Shift) tailed for vision tasks and modify the original causal RWKV attention mechanism to a bidirectional global attention mechanism.
The Q-Shift operation expands the semantic range of individual tokens, while the bidirectional attention enables the calculation of global attention within linear computational complexity in an RNN form forward and backward.
We primarily make modifications to the exponent in the RWKV attention mechanism, releasing the limitations of the decay vector and transforming the absolute positional bias into a relative bias. These changes enhance the model’s capability while ensuring scalability and stability.
In this way, our model inherits the efficiency of RWKV in handling global information and sparse inputs, while also being able to model the local concept of vision tasks.
We implement layer scale [] and layer normalization [] where needed to stabilize the model’s output across different scales. These adjustments significantly improve the model’s stability when scaling up to a larger size.

Building on the aforementioned design, we develop a range of VRWKV models with different model scales, spanning from the VRWKV-Tiny (6M) to the VRWKV-Large (335M).
These models are trained using large-scale datasets such as ImageNet-1K [] and ImageNet-22K [].
We train them using both common supervised classification and sparse input MAE methods [] and evaluate their performance on visual perception tasks, including classification, detection, and segmentation.
Under the same settings, VRWKV has comparable performance to ViT in these tasks with lower computational costs while maintaining stable scalability.
This achievement enables VRWKV training parallelism, high flexibility, excellent performance, and low inference cost simultaneously, making it a promising alternative to ViT in a wide range of vision tasks, particularly in high-resolution scenarios.

In this paper, our main contributions are:

(1) We propose VRWKV as a low-cost alternative to ViT, achieving comprehensive substitution with lower computational costs. Our model not only retains the advantages of ViT, including the capability to capture long-range dependencies and flexibility in handling sparse inputs but also reduces complexity to a linear level. This significant reduction eliminates the need for window-based attention in processing high-resolution images, making VRWKV a more efficient and scalable solution for vision tasks.

(2) To adapt to vision tasks, we introduce bidirectional global attention and a novel token shift method called Q-Shift, enabling the achievement of linear complexity in global attention. To ensure stable scalability, we make several efforts, including using a relative positional bias in the attention mechanism to avoid overflow, adopting layer scale in our model, and adding extra layer normalization in the calculation of key matrices.

(3) Our model surpasses window-based ViTs and is comparable to global attention ViTs, demonstrating lower FLOPs and faster processing speeds as resolution increases.
Notably, VRWKV-T achieves 75.1% top-1 accuracy trained only on the ImageNet-1K [], outperforming DeiT-T [] by 2.9 points. With large-scale parameters (*i.e*., 335M) and training data (*i.e*., ImageNet-22K),
the top-1 accuracy of VRWKV-L is further boosted to 86.0%, which is higher than ViT-L [] (86.04 **vs*. missing* 85.15). In addition, on COCO [], a challenging downstream benchmark, our best model VRWKV-L achieves 50.6% box mAP, 1.9 points better than ViT-L (50.6 **vs*. missing* 48.7).

## 2 Related Works

### 2.1 Vision Encoder

Recent advances in vision encoders have significantly pushed the boundaries of computer vision, demonstrating remarkable performance across a range of tasks.
Convolutional neural networks (CNNs) served as the foundational model in computer vision. The advancement of computational resources, such as GPUs, has enabled the successful training of stacked convolutional blocks like AlexNet [] and VGG [] on large-scale image classification datasets (*e.g*., ImageNet []). This development paved the way for deeper and more sophisticated convolutional neural architectures, including GoogleNet [], ResNet [], and DenseNet [].

In addition to these innovations, significant advancements have also been made with architectures like SENet [], which introduced a channel attention mechanism to enhance model sensitivity to informative features. Similarly, SKNet [] merged multiple kernel sizes to adjust the receptive field adaptively.
Further extending the CNN paradigm, recent models such as RepLKNet [] and ConvNeXt [] have refined the convolutional layers to improve efficiency and accuracy, while InternImage [] explored the strategies to scale up the convolution-based vision model.

Drawing inspiration from the effectiveness of self-attention layers and transformer architectures in the NLP field, the Vision Transformer (ViT) [] applied a transformer framework on image patches, offering a global receptive field and dynamic spatial aggregation.
Due to the quadratically increasing computational complexity of the vanilla attention mechanism, approaches like PVT [, ] and Linformer [] implemented global attention on down-sampled feature maps, whereas other approaches like Swin [] and HaloNet [, ] introduced sampling techniques to enlarge the receptive field.

Another research direction involved replacing self-attention layers in models with linear complexity layers. Representative works in this domain include LongNet [], RWKV [], RetNet [], and Mamba [], though few have concentrated on vision-related applications. Concurrently, attempts like Vim [] and VMamba [] have sought to integrate these linear attention layers into the vision domain. However, these endeavors have only been experimented with on small-scale models, and it remains uncertain whether their efficiency can scale up to larger models.

### 2.2 Feature Aggregation Mechanism

The research on feature aggregation has received significant attention in the field of artificial intelligence.
For visual data processing, convolutional operators [], known for their parameter sharing and local perception, enabled efficient handling of large-scale data through sliding computation. Despite their advantages, traditional CNN operators faced challenges in modeling long-range dependencies.
To overcome this issue, advanced convolutional operators, such as the deformable convolution [, , ], have improved the flexibility of CNN operators, enhancing their long-range modeling capability.

As for the field of NLP, RNN-based operators [, , ] have historically dominated because of their effectiveness in sequence modeling. RNNs and LSTMs excel in capturing temporal dependencies, making them suitable for tasks requiring an understanding of sequence dynamics.
Subsequently, a significant shift occurred.
The introduction of the transformer architecture [] marked a turning point, with both NLP and computer vision fields shifting focus toward attention-based feature aggregation.
The global attention mechanism overcomes the limitations of CNNs in modeling long-range dependencies and the shortcomings of RNNs in parallel computation while coming at a high computational cost.

To address the high computational cost of attention operators while modeling long sequences, researchers have introduced innovations such as window attention and spatial reduction attention.
Window attention [, , ] restricts the self-attention computation within local windows, drastically reducing the computational complexity while preserving the receptive field through window-level interaction.
Spatial reduction attention [, ], on the other hand, reduces the dimensionality of the feature space before applying the attention mechanism, effectively decreasing the computational requirements without significantly degrading the model’s performance.

In addition to the efforts to optimize the global attention mechanism, various operators with linear complexity [, , , , ] have also been explored. For instance, RWKV [] and RetNet [] employed exponential decay to model global information efficiently while SSMs [, , , ] also exhibited linear complexity concerning sequence length and modification in Mamba [] enable them to be input-dependent. Besides, XCA [] achieved linear complexity by calculating the cross-variance between input tokens. However, the low efficiency of information interaction between tokens makes the need for the assistance of additional modules necessary to complete a comprehensive feature aggregation.
Despite some concurrent efforts [, , ], adapting these NLP-derived techniques to vision tasks remains a challenge in maintaining stable training across larger and more complex vision models.

Figure: Figure 2: Overall architecture of Vision-RWKV (VRWKV). (a) The VRWKV architecture includes $L$ identical VRWKV encoder layers, an average pooling layer, and a linear prediction head. (b) The details of the VRWKV encoder layer. Q-Shift denotes the quad-directional shift method tailed for vision tasks. The “Bi-WKV” module served as a bidirectional RNN cell or a global attention mechanism.
Refer to caption: x2.png

## 3 Vision-RWKV

### 3.1 Overall Architecture

In this section, we propose Vision-RWKV (VRWKV), an efficient vision encoder with a linear complexity attention mechanism.
Our principle is to preserve the advantages of the original RWKV architecture [], making only necessary modifications to enable its flexible application in vision tasks, supporting sparse input, and ensuring the stability of the training process after scaling up.
An overview of our VRWKV is depicted in Fig. 2.

VRWKV adopts a block-stacked image encoder design like ViT, where each block consists of a spatial-mix module and a channel-mix module. The spatial-mix module functions as an attention mechanism, performing linear complexity global attention computation while the channel mix module serves as a feed-forward network (FFN), performing feature fusion in the channel dimension. The entire VRWKV includes a patch embedding layer and a stack of $L$ identical VRWKV encoder layers, where each layer maintains the input resolution.

Data Flow.
First, we transform the $H\times W\times 3$ image into $HW/p^{2}$ patches, where $p$ denotes the patch size. The patches after a linear projection add the position embedding to obtain image tokens of shape $T\times C$, where $T=HW/p^{2}$ denotes the total number of tokens. These tokens are then input into the VRWKV encoder with $L$ layers.

In each layer, tokens are first fed into the spatial-mix module which plays the role of a global attention mechanism. Specifically, as shown in Fig. 2(b), the input tokens are first shifted and fed into three parallel linear layers to obtain the matrices $R_{s},K_{s},V_{s}\in\mathbb{R}^{T\times C}$:

$$ $\displaystyle R_{\text{s}}={\rm Q\mbox{-}Shift}_{R}(X)W_{R},~{}~{}~{}~{}K_{ \text{s}}={\rm Q\mbox{-}Shift}_{K}(X)W_{K},~{}~{}~{}~{}V_{\text{s}}={\rm Q \mbox{-}Shift}_{V}(X)W_{V}.$ (1) $$

Here, $K_{\text{s}}$ and $V_{\text{s}}$ are passed to calculate the global attention result $wkv\in\mathbb{R}^{T\times C}$ by a linear complexity bidirectional attention mechanism and multiplied with $\sigma(R)$ which controls the output $O_{\text{s}}$ probability:

$$ $\displaystyle O_{\text{s}}$ $\displaystyle=(\sigma(R_{\text{s}})\odot wkv)W_{O},$ (2) $\displaystyle\text{where}\ wkv$ $\displaystyle=\mathrm{Bi\mbox{-}WKV}(K_{\text{s}},V_{\text{s}}).$ $$

Operator $\sigma$ denotes the sigmoid function, and $\odot$ means an element-wise multiplication is applied. The $\rm Q\mbox{-}Shift$ is a token shift function specially designed for the adaption of vision tasks.
After an output linear projection, features are then stabilized using layer normalization [].

Subsequently, the tokens are passed into the channel-mix module for a channel-wise fusion. $R_{\text{c}}$, $K_{\text{c}}$ are obtained in a similar manner as spatial-mix:

$$ $\displaystyle R_{\text{c}}={\rm Q\mbox{-}Shift}_{R}(X)W_{R},~{}~{}~{}~{}K_{ \text{c}}={\rm Q\mbox{-}Shift}_{K}(X)W_{K}.$ (3) $$

Here, $V_{\text{c}}$ is a linear projection of $K$ after the activation function and the output $O_{\text{c}}$ is also controlled by a gate mechanism $\sigma(R_{\text{c}})$ before the output projection:

$$ $\displaystyle O_{\text{c}}$ $\displaystyle=(\sigma(R_{\text{c}})\odot V_{\text{c}})W_{O},$ (4) $\displaystyle\text{where}\ V_{\text{c}}$ $\displaystyle=\mathrm{SquaredReLU}(K_{\text{c}})W_{V}.$ $$

Simultaneously, residual connections [] are established from the tokens to each normalization layer to ensure that training gradients do not vanish in deep networks.

### 3.2 Linear Complexity Bidirectional Attention

Different from the vanilla RWKV [], we make the following modifications to its original attention mechanism to adapt it to vision tasks:
(1) Bidirectional attention: We extend the upper limit of original RWKV attention from $t$ (the current token) to $T-1$ (the last token) in the summation formula to ensure that all tokens are mutually visible in the calculation of each result. Thus, the original causal attention transforms into bidirectional global attention.
(2) Relative bias: We compute the absolute value of the time difference $t-i$ and divide it by the total number of tokens (denoted as $T$) to represent the relative bias of tokens in images of different sizes.
(3) Flexible decay: We no longer restrict the learnable decay parameter $w$ to be positive in the exponential term allowing the exponential decay attention to focus on tokens further away from the current token in different channels.
The simple yet necessary modification achieves global attention calculation and maximizes the preservation of RWKV’s low complexity and adaptability to vision tasks.

Similar to the attention in RWKV, our bidirectional attention can also be equivalently expressed in a summation form (for the sake of clarity) and an RNN form (in practical implementation).

Summation Form.
The attention calculation result for the $t$-th token is given by the following formula:

$$ $\displaystyle wkv_{t}=\mathrm{Bi\mbox{-}WKV}(K,V)_{t}=\frac{\sum^{T-1}_{i=0,i \neq t}e^{-(|t-i|-1)/T\cdot w+k_{i}}v_{i}+e^{u+k_{t}}v_{t}}{\sum^{T-1}_{i=0,i \neq t}e^{-(|t-i|-1)/T\cdot w+k_{i}}+e^{u+k_{t}}}.$ (5) $$

Here, $T$ represents the total number of tokens, equal to $HW/p^{2}$, $w$ and $u$ are two $C$-dimensional learnable vectors that represent channel-wise spatial decay and the bonus indicating the current token, respectively. $k_{t}$ and $v_{t}$ denotes $t$-th feature of $K$ and $V$.

The summation formula indicates that the output $wkv_{t}$ is a weighted sum of $V$ along the token dimension from 0 0 to $T-1$, resulting in a $C$-dimensional vector. It represents the result obtained by applying the attention operation to the t-th token. The weight is determined by the spatial decay vector $w$, the relative bias between tokens $(|t-i|-1)/T$, and $k_{i}$ collectively.

RNN Form.
In the practical implementation, the above Eq. 5 can be transformed into a recursive formula in the form of RNN that the result of each token can be obtained through a fixed number of FLOPs.
By splitting the summation term of the denominator and numerator in Eq. 5 with $t$ as the boundary, we can obtain 4 hidden states:

$$ $\displaystyle a_{t-1}=$ $\displaystyle\sum^{t-1}_{i=0}e^{-(|t-i|-1)/T\cdot w+k_{i}}v_{i},$ $\displaystyle b_{t-1}=$ $\displaystyle\sum^{T-1}_{i=t+1}e^{-(|t-i|-1)/T\cdot w+k_{i}}v_{i},$ (6) $\displaystyle c_{t-1}=$ $\displaystyle\sum^{t-1}_{i=0}e^{-(|t-i|-1)/T\cdot w+k_{i}},$ $\displaystyle d_{t-1}=$ $\displaystyle\sum^{T-1}_{i=t+1}e^{-(|t-i|-1)/T\cdot w+k_{i}},$ $$

that can be recursively computed. The update of hidden states only requires adding or subtracting one summation term and multiplying or dividing $e^{-w/T}$.
Then the $t$-th result can be given as:

$$ $\displaystyle wkv_{t}$ $\displaystyle=\frac{a_{t-1}+b_{t-1}+e^{k_{t}+u}v_{t}}{c_{t-1}+d_{t-1}+e^{k_{t} +u}}.$ (7) $$

Each update step yields an attention result (*i.e*., $wkv_{t}$) for a token, so the entire $wkv$ matrix requires $T$ steps.

When the input $K$ and $V$ are matrices with the shape of $T\times C$, the computational cost of calculating the $wkv$ matrix is given by:

$$ $\text{FLOPs}(\text{Bi\mbox{-}WKV}(K,V))=13\times T\times C.\vspace{-0.5em}$ (8) $$

Here, the number 13 is approximately from the updates of $(a,b,c,d)$, the computation of the exponential, and the calculation of $wkv_{t}$. $T$ is the total number of update steps and is equal to the number of image tokens.
The above approximation shows that the complexity of the forward process is $O(TC)$. The backward propagation of the operator can still be represented as a more complex RNN form, with a computational complexity of $O(TC)$. The specific formula for backward propagation is provided in the Appendix.

### 3.3 Quad-Directional Token Shift

By introducing an exponential decay mechanism, the complexity of global attention can be reduced from quadratic to linear, greatly enhancing the computational efficiency of the model in high-resolution images. However, the one-dimensional decay does not align with the neighboring relationships in two-dimensional images. Therefore, we introduce a quad-directional token shift (Q-Shift) in the first step of each spatial-mix and channel-mix module. The Q-Shift operation allows all tokens shifted and linearly interpolated with their neighboring tokens as follows:

$$ $\displaystyle{\rm Q\mbox{-}Shift}_{(*)}(X)$ $\displaystyle=X+(1-\mu_{\text{(*)}})X^{\dagger},$ (9) $\displaystyle\text{where}\ X^{{\dagger}}[h,w]$ $\displaystyle=\mathrm{Concat}(X[h-1,w,0:C/4],X[h+1,w,C/4:C/2],$ $\displaystyle\ \ \ \ \ \ \ \ \ \ \ \ \ \ X[h,w-1,C/2:3C/4],X[h,w+1,3C/4:C]).$ $$

Subscript $(*)\in\{R,K,V\}$ denotes 3 interpolation of $X$ and $X^{\dagger}$ controlled by the learnable vectors $\mu_{(*)}$ for the later calculation of $R,K,V$, respectively. $h$ and $w$ denote the row and column index of token $X$, “:” is a slicing operation excluded the end index. The Q-Shift makes the attention mechanism of different channels obtain the prior of focusing on neighboring tokens internally without introducing many additional FLOPs.
The Q-Shift operation also increases the receptive field of each token which greatly enhances the coverage of the token in the posterior layers.

### 3.4 Scale Up Stability

Both the number of model layers increasing and the accumulation in the exponent term during the recursion can lead to instability in the model output and affect the stability of the training process.
To mitigate the instability, we employ two simple but effective modifications to stabilize the scale-up of the model.
(1) Bounded exponential:
As the input resolution increases, both exponential decay and growth quickly exceed the range of floating-point numbers. Therefore, we divide the exponential term by the number of tokens (such as $\mathrm{exp}(-(|t-i|-1)/T\cdot w$)), making the maximum decay and growth bounded.
(2) Extra layer normalization:
When the model gets deeper, we directly add layer normalization [] after the attention mechanism and Squared ReLU operation to prevent the model’s output from overflowing.
The two modifications enable stable scaling of both input resolution and model depth, allowing large models to train and converge stably. We also introduce layer scale [] which contributes to the stability of the models as they scale up.

**Table 1: Default settings for Vision-RWKV of different scales. We report the embedding dimension, hidden dimension, and model depth for VRWKV-T/S/B/L. “Extra Norm” means additional layer normalization layers are used to stabilize the model’s outputs. “#Param” denotes the number of parameters.**
| Model | Emb Dim | Hidden Dim | Depth | Extra Norm | #Param |
| --- | --- | --- | --- | --- | --- |
| VRWKV-T | 192 | 768 | 12 | ✕ | 6.2M |
| VRWKV-S | 384 | 1536 | 12 | ✕ | 23.8M |
| VRWKV-B | 768 | 3072 | 12 | ✕ | 93.7M |
| VRWKV-L | 1024 | 4096 | 24 | ✓ | 334.9M |

### 3.5 Model Details

Following ViT, the hyper-parameters for variants of VRWKV, including embedding dimension, hidden dimension in linear projection, and depth, are specified in Tab. 1.
Due to the increased depth of the VRWKV-L model, additional layer normalizations as discussed in Sec. 3.4, are incorporated at appropriate positions to ensure output stability.

## 4 Experiments

We comprehensively evaluate the substitutability of our VRWKV method for ViT in performance, scalability, flexibility, and efficiency.
We validate the effectiveness of our model on the widely-used image classification dataset ImageNet []. For downstream dense prediction tasks, we select detection tasks on the COCO [] dataset and semantic segmentation on the ADE20K [] dataset.

**Table 2: Validation results on ImageNet-1K. VRWKV-T/S/B are trained from scratch using ImageNet-1K, while VRWKV-L is pre-trained on Imagenet-22K and fine-tuned on Imagenet-1K. “#Param” denotes the number of parameters, and “FLOPs” means the computational workload for processing an image at the resolution specified in the “Size” column. “$\star$” denotes Bamboo-47K [] is used in the pre-training.**
|  | Method | Size | #Param | FLOPs | Top-1 Acc |
| --- | --- | --- | --- | --- | --- |
| hierarchical | ResNet-18 [] | $224^{2}$ | 11.7M | 1.8G | 69.9 |
| PVT-T [] | $224^{2}$ | 13.2M | 1.9G | 75.1 |  |
| ResNet-50 [] | $224^{2}$ | 25.6M | 4.1G | 76.6 |  |
| Swin-T [] | $224^{2}$ | 28.3M | 4.4G | 81.2 |  |
| PVT-M [] | $224^{2}$ | 44.2M | 6.7G | 81.2 |  |
| ResNet-101 [] | $224^{2}$ | 44.6M | 7.9G | 78.0 |  |
| Swin-S [] | $224^{2}$ | 49.6M | 8.7G | 83.0 |  |
| PVT-L [] | $224^{2}$ | 61.4M | 9.8G | 81.7 |  |
| Swin-B [] | $224^{2}$ | 87.8M | 15.1G | 83.4 |  |
| DeiT-T [] | $224^{2}$ | 5.7M | 1.3G | 72.2 |  |
|  | DeiT-S [] | $224^{2}$ | 22.1M | 4.6G | 79.9 |
|  | XCiT-S12 [] | $224^{2}$ | 26.0M | 4.8G | 82.0 |
|  | DeiT-B [] | $224^{2}$ | 86.6M | 17.6G | 81.8 |
|  | XCiT-L24 [] | $224^{2}$ | 189.0M | 36.1G | 82.9 |
|  | ViT-L [] | $384^{2}$ | 309.5M | 191.1G | 85.2 |
|  | VRWKV-T | $224^{2}$ | 6.2M | 1.2G | 75.1 |
|  | VRWKV-S | $224^{2}$ | 23.8M | 4.6G | 80.1 |
|  | VRWKV-B | $224^{2}$ | 93.7M | 18.2G | 82.0 |
|  | VRWKV-L | $384^{2}$ | 334.9M | 189.5G | 86.0 |
| non-hierarchical | VRWKV-L${}^{\star}$ | $384^{2}$ | 334.9M | 189.5G | 86.5 |

### 4.1 Image Classification

Settings.
For -Tiny/Small/Base models, we conduct supervised training from scratch on ImageNet-1K []. Following the training strategy and data augmentation of DeiT [], we use a batch size of 1024, AdamW [] with a base learning rate of 5e-4, weight decay of 0.05, and cosine annealing schedule []. Images are cropped to the resolution of $224\times 224$ for training and validation. For the -Large models, we first pre-train them for 90 epochs on ImageNet-22K with a batch size of 4096 and resolution of $192\times 192$, and then fine-tune them for 20 epochs on ImageNet-1K to a higher resolution of $384\times 384$.

Results.
We compare the results of our VRWKV with other hierarchical and non-hierarchical backbones on the ImageNet-1K validation dataset. As shown in Tab. 2, with the same number of parameters, computational complexity, and training/testing resolutions, VRWKV achieves better results than ViT.
For example, when VRWKV-T has slightly lower FLOPs than DeiT-T(1.2G *vs*. 1.3G), our VRWKV-T achieves a 2.9 point higher than DeiT-T on top-1 accuracy.
When the model size scales up, VRWKV still demonstrates higher baseline performance.
In the case of large models, VRWKV-L achieves a 0.8 point higher top-1 accuracy of 86.0% at the resolution of $384\times 384$ than ViT-L, with a slightly reduced computational cost.
The superior performance from tiny to large-size models demonstrates that the VRWKV model possesses the scalability as ViT.
Additionally, after using Bamboo-47K [] in the pre-train process, the performance of VRWKV-L can be further boosted to 86.5%, indicating that our VRWKV also possesses the ability like ViT to benefit from pre-training on large-scale datasets.
The exploration of VRWKV in classification tasks demonstrates its potential to be a viable alternative to traditional ViT models.

### 4.2 Object Detection

**Table 3: Object detection and instance segmentation on COCO val2017. All models adopt the ViT-Adapter [] to generate multi-scale features for detection heads. -T/S/B models are initialized with ImageNet-1K pre-trained weights, and all -L models with ImageNet-22K weights. “#Param” denotes the number of backbone parameters. “FLOPs” denotes the computational workload of the backbone with an input image of $1333\times 800$. “$\dagger$” means window attention is adopted in ViT layers.**
| Method | #Param | FLOPs | $\rm AP^{b}$ | $\rm AP^{m}$ |
| --- | --- | --- | --- | --- |
| ViT-T${}^{\dagger}$ [] | 8.0M | 95.4G | 41.1 | 37.5 |
| ViT-T [] | 8.0M | 147.1G | 41.6 | 37.9 |
| VRWKV-T (ours) | 8.4M | 67.9G | 41.7 | 38.0 |
| ViT-S${}^{\dagger}$ [] | 27.5M | 241.2G | 44.6 | 39.7 |
| ViT-S [] | 27.5M | 344.5G | 44.9 | 40.1 |
| VRWKV-S (ours) | 29.3M | 189.9G | 44.8 | 40.2 |
| ViT-B${}^{\dagger}$ [] | 99.5M | 686.7G | 46.2 | 41.5 |
| ViT-B [] | 99.5M | 893.3G | 46.8 | 41.8 |
| VRWKV-B (ours) | 106.6M | 599.0G | 46.8 | 41.7 |
| ViT-L${}^{\dagger}$ [] | 327.0M | 1799.3G | 48.7 | 43.3 |
| VRWKV-L (ours) | 351.9M | 1730.6G | 50.6 | 44.9 |

Settings.
In the detection tasks, we adopt Mask R-CNN [] as the detection head. For the -Tiny/Small/Base models, the backbones use weights pre-trained on ImageNet-1K for 300 epochs. For the -Large model, weights pre-trained on ImageNet-22K are used. All models use a 1$\times$ training schedule (*i.e*., 12 epochs) with a batch size of 16, and AdamW [] optimizer with an initial learning rate of 1e-4 and weight decay of 0.05.

Results.
In Tab. 3, we report the detection results on the COCO val [] dataset using VRWKV and ViT as backbones. As the results showed in Fig. 1 (a) and Tab. 3, due to the use of window attention in dense prediction tasks, VRWKV with global attention can achieve better performance than ViT with lower FLOPs. For example, VRWKV-T has approximately 30% lower backbone FLOPs compared to ViT-T${}^{\dagger}$, with an improvement of $\mathrm{AP^{b}}$ by 0.6 points. Similarly, VRWKV-L achieves a 1.9-point increase in $\mathrm{AP^{b}}$ with lower FLOPs compared to ViT-L${}^{\dagger}$.
Additionally, we compare the performance of VRWKV and ViT using global attention. For instance, VRWKV-S achieves similar performance to ViT-S with 45% lower FLOPs. This demonstrates the effectiveness of VRWKV’s global attention mechanism in dense prediction tasks and the advantage of lower computational complexity compared to the original attention mechanism.

### 4.3 Semantic Segmentation

**Table 4: Semantic segmentation on the ADE20K val set. All models used ViT-Adapter [] for multi-scale feature generation and are trained with UperNet [] as the segmentation heads. For consistency in comparison, all -T/S/B models are initialized using ImageNet-1K pre-training, whereas -L models utilize ImageNet-22K pre-training. “#Param” refers to the number of parameters of the backbone. We report the FLOPs of backbones with the input size of $512\times 512$.**
| Method | #Param | FLOPs | mIoU |
| --- | --- | --- | --- |
| ViT-T [] | 8.0M | 20.9G | 42.6 |
| VRWKV-T (ours) | 8.4M | 16.6G | 43.3 |
| ViT-S [] | 27.5M | 54.0G | 46.2 |
| VRWKV-S (ours) | 29.3M | 46.3G | 47.2 |
| ViT-B [] | 99.5M | 157.9G | 48.8 |
| VRWKV-B (ours) | 106.6M | 146.0G | 49.2 |
| ViT-L [] | 327.0M | 446.8G | 53.4 |
| VRWKV-L (ours) | 351.9M | 421.9G | 53.5 |

Settings.
In the semantic segmentation task, we use UperNet [] as the segmentation head. Specifically, all ViT models use global attention in the segmentation task.
For the -Tiny/Small/Base models, the backbones use weights pre-trained on ImageNet-1K. And for the -Large model, weights pre-trained on ImageNet-22K are used. We employ the AdamW optimizer with an initial learning rate of 6e-5 for the -Small/Base/Large models and 12e-5 for the -Tiny model, a batch size of 16, and a weight decay of 0.01.
All models are trained for 160k iterations on the training set of the ADE20K dataset [].

Results.
As shown in Tab. 4, when using UperNet for semantic segmentation, models based on VRWKV consistently outperform those based on ViT with global attention, while also being more efficient.
For example, VRWKV-S achieves 1 point higher than ViT-S with a 14% FLOPs decrease. VRWKV-L creates a result of 53.5 mIoU similar to ViT-L while the computation of the backbone has a 25G FLOPs lower.
These results demonstrate that our VRWKV backbones can extract better features for semantic segmentation compared to ViT backbones while also being more efficient, benefiting from the linear complexity attention mechanism.

### 4.4 Ablation Study

Settings.
We conduct ablation studies of the tiny-size VRWKV on ImageNet-1K [] to validate the effectiveness of various key components like Q-Shift and bidirectional attention. The experimental settings are consistent with Sec. 4.1.

Token Shift.
We compare the performance of not using token shift, using the original shift method in RWKV [], and our Q-Shift.
As shown in Tab. 5, the variation in the shift method shows performance differences. Variant 1 without token shift leads to a poor performance of 71.5, which is 3.6 points lower than our model. Even with the use of our global attention, the model using the original token shift still has a 0.7-point gap with our model.

Bidirectional Attention.
The bidirectional attention mechanism enables the model to achieve global attention while the original RWKV attention has a causal mask internally. The result of Variant 3 shows that the global attention mechanism brings a 2.3 points increase in the top-1 accuracy.

**Table 5: Ablation on key components of the proposed VRWKV. All models are trained from scratch on ImageNet-1K. The “original” means the original token shift in RWKV [] which mixes the token in a single direction is used.**
| Method | Token Shift | Bidirectional | Top-1 Acc |
| --- | --- | --- | --- |
| Attention |  |  |  |
| RWKV [] | original | ✕ | 71.1 (-4.0) |
| Variant 1 | none | ✓ | 71.5 (-3.6) |
| Variant 2 | original | ✓ | 74.4 (-0.7) |
| Variant 3 | Q-Shift | ✕ | 72.8 (-2.3) |
| VRWKV-T (ours) | Q-Shift | ✓ | 75.1 |

Effective Receptive Field (ERF).
We analyze the impact of different designs on the ERF of models based on [] and visualize it in Fig. 3(a). We visualize the ERF of the central pixel with an input size of 1024 × 1024. In  Fig. 3(a), “No Shift” represents the absence of the token shift method (Q-Shift), and “RWKV Attn” indicates using the original RWKV attention mechanism without our modifications for vision tasks.
From the comparison in the figure, all models except the “RWKV Attn” one achieved global attention while the global capacity of the VRWKV-T model is better than that of ViT-T. Despite the assistance of Q-Shift, the central pixel in “RWKV Attn” still cannot attend to the pixels on the bottom of the image due to the large input resolution. The results of “No Shift” and Q-Shift show that the Q-Shift method expands the core range of the receptive field, enhancing the inductive bias of global attention.

Efficiency Analysis.
We gradually increase the input resolution from $224\times 224$ to $2048\times 2048$ and compare the inference and memory efficiency of VRWKV-T and ViT-T. The results were tested on an Nvidia A100 GPU, as shown in Fig. 1. From the curves presented in Fig. 1(b), it is observed that at lower resolutions, such as $224\times 224$ with around 200 image tokens, VRWKV-T and ViT-T exhibit comparable memory usage, though VRWKV-T has a slightly lower FPS compared to ViT-T.
However, with increasing resolution, VRWKV-T’s FPS rapidly exceeds that of ViT-T, thanks to its linear attention mechanism. Additionally, VRWKV-T’s RNN-like computational framework ensures a slow increase in memory usage. By the time the resolution hits $2048\times 2048$ (equivalent to 16384 tokens), VRWKV-T’s inference speed is 10 times faster than ViT-T, and its memory consumption is reduced by 80% compared to ViT-T.

We also compare the speed of our ${\rm Bi\mbox{-}WKV}$ and flash attention [], reported in Fig. 3(b). Flash attention is highly efficient at low resolutions yet plagued by quadratic complexity, its speed decreases rapidly as the resolution increases. In high-resolution scenarios, our linear operator ${\rm Bi\mbox{-}WKV}$ demonstrates a significant speed advantage. For instance, when the input is $2048\times 2048$ (*i.e*., 16384 tokens) with the channel and head number settings according to ViT-B and VRWKV-B, our ${\rm Bi\mbox{-}WKV}$ operator is $2.8\times$ faster than flash attention in inference runtime and $2.7\times$ faster in the combined forward and backward pass.

MAE Pre-training.
Similar to ViT, our VRWKV model can handle sparse inputs and benefits from the MAE pre-training []. By simply modifying the Q-Shift to perform a bidirectional shift operation, VRWKV can be pre-trained using MAE. The pre-trained weights can be directly fine-tuned for other tasks using a Q-Shift manner. Following the same MAE pre-training setting as ViT, and subsequent classification training similar to Sec. 4.1, our VRWKV-L achieves a top-1 accuracy improvement from 86.0% to 86.2% on ImageNet-1K val, showing the ability to acquire visual prior from masked image modeling.

Figure: Figure 3: Comparison of effective receptive field (ERF) and attention runtime. (a) ERF for ViT and VRWKV in different settings. “No Shift” means no shift is used in spatial-mix and channel-mix modules. “RWKV Attn” means the original RWKV attention [] without our modifications. Our VRWKV with Q-Shift and Bi-WKV has a more comprehensive ERF than other counterparts. (b) Attention runtime of inference (left) and forward $+$ backward (right) tested on an Nvidia A100 GPU.
Refer to caption: x3.png

## 5 Conclusion

We propose Vision-RWKV (VRWKV), a vision encoder with a linear computational complexity attention mechanism. We demonstrate its capability to be an alternative backbone to ViT in comprehensive vision tasks including classification, dense predictions, and masked image modeling pre-training. With comparable performance and scalability, VRWKV exhibits lower computational complexity and memory consumption. Benefiting from its low complexity, VRWKV can achieve better performance in the tasks that ViT
struggling to afford the high computational overhead of global attention. We hope VRWKV will be an efficient and low-cost alternative to ViT, showcasing the powerful potential of linear complexity transformers in vision fields.

## Peer Reviews

confidence: 2
contribution: 2
initial_rating: 6
presentation: 4
questions: see weaknesses
soundness: 4
strengths: 1.The paper is well-written and easy to follow;

2.Extensive empirical evidence supports the effectiveness of the model, indicating its practical application potential;

3.The adaptation of RWKV for visual tasks goes beyond mere transfer, incorporating modifications that enhance its suitability for image processing.
summary: The paper introduces a new network architecture, VISION-RWKV, a vision-adapted version of the RWKV network from the NLP community, which employs an RNN-based linear attention mechanism. The authors have made necessary adaptations to the RWKV to better suit visual tasks, recognizing the differences between vision and language processing tasks.
weaknesses: Major：Although the paper discusses RWKV and mamba as prominent RNN-based linear attention models transitioning from NLP to computer vision, it lacks a direct comparison with the mamba (vision) model. Such a comparison would be valuable for assessing the respective strengths and weaknesses of each model in the field of computer vision.

Minor：From an innovation perspective, the approach of adapting other domains' mature architectures to computer vision, similar to what was done post-transformer, appears somewhat incremental.

---

confidence: 3
contribution: 2
initial_rating: 5
presentation: 4
questions: Clarifying the practical benefit from their proposed approach and why not simply use vanilla ViTs considering the current gains are not that considerable when looking at Tables 2 and 4. Hence, the reason I am leaning towards a marginal reject but since the method seems to provide interesting direction and their results for detection seems sufficiently good I am not going lower.
soundness: 3
strengths: - Comprehensive results across three tasks.
- Interesting direction to replace ViTs with other efficient techniques that provide on-par or better performance.
summary: Authors propose an approach that adapts NLP models for RWKV to vision tasks, termed as V-RWKV. Their proposed method could be looked upon as a cost effective solution than ViTs. They propose Quad-directional Shift and change the causal attention to bidirectional one towards learning locl concepts that are more relevant in vision rather than simple text. They evaluate their approach on the image classification, object detection and semantic segmentation tasks.
weaknesses: - The gains in efficiency seem to be relatively minor, i.e., it is not an order of magnitude which still brings the question whether it is worth exploring these type of models to replace ViTs to begin with or not.

 For example, in Table 2 ViT-L vs. VRWKV-L 191.1 vs 189.5G FLOPS and parameters at 309.5M vs. 334.9M respectively. I think the reduction in FLOPS when scaling to Large variant seems to be around 3G. Similarly in Table 4, FLOPS 446.8 vs. 421.9G with the expense of an increase in the number of parameters. I am not expert in such type of methods focused on improving efficiency but I do not see the results are impressive enough to show the benefit from the V-RWKV design, especially that it is increasing the parameters.

---

confidence: 3
contribution: 3
initial_rating: 8
presentation: 3
questions: - Can you please clarify what you meant in line 527-528 by task fine-tuning using Q-shift manner?
soundness: 3
strengths: - Novel contribution for quad-directional token shifting called Q-shift. This essentially increases the models range of semantic understanding
- Authors expanded causal RWKV to a bidirectional global RWKV. They modified the exponent in the RWKV attention that leads to transforming the absolution positional bias to relative bias.
- Well written paper with through experimentation including MAE pretraining
summary: The authors describe a Vision-RWKV architecture that employs novel techniques like bi-directional RWKV, quad token shifting method Q-shift etc. These techniques helps Vision-RWKV  architecture surpass window-based ViTs and comparable to global attention ViTs along with lower FLOPs, lower GPU memory cost and faster processing as shown in Figure 1. Although the MAE finetuning is not as straightforward as typical finetuning on downstream task, overall this paper has a good contribution for the vision research community.
weaknesses: - The authors implemented a bidirectional shift operation that removed the vertical shift in Q-shift, thereby enabling for MAE pretraining. IMO this is a source of complexity. As a result, MAE finetuning needs to be done in Q-shift manner

Meta-review: (a) Scientific Claims and Findings

The paper presents VISION-RWKV, an adaptation of the RWKV network from NLP to vision tasks, incorporating an RNN-based linear attention mechanism. Reviewer QwNu notes that the authors have made necessary modifications to suit visual tasks, while cUXV highlights the introduction of Quad-directional Shift and bidirectional attention to better capture local concepts in vision. weiY emphasizes the novel techniques like bi-directional RWKV and quad token shifting, which help the architecture surpass window-based ViTs in efficiency and performance.

(b) Strengths

The paper is well-written and provides extensive empirical evidence supporting the model's effectiveness, as noted by QwNu. cUXV appreciates the comprehensive results across multiple tasks and the exploration of efficient alternatives to ViTs. weiY highlights the novel contributions, such as the quad-directional token shifting and the expansion of causal RWKV to a bidirectional global RWKV, which enhance the model's semantic understanding and efficiency.

(c) Weaknesses

A major weakness identified by QwNu is the lack of direct comparison with the mamba (vision) model, which would help assess the model's strengths and weaknesses in computer vision. cUXV points out that the efficiency gains are relatively minor, questioning whether the model is a worthwhile replacement for ViTs given the modest reduction in FLOPs and increase in parameters. weiY mentions the complexity introduced by the bidirectional shift operation, which complicates MAE finetuning.

(d) Decision Reasons

The decision to accept the paper is based on its novel contributions to adapting NLP models for vision tasks and the comprehensive empirical validation provided. Despite some concerns about the incremental nature of the approach and the modest efficiency gains, the paper offers a promising direction for efficient vision models, as highlighted by all reviewers. The strengths in presentation, empirical results, and novel techniques outweigh the weaknesses, leading to an overall positive assessment.

Decision: Accept (Spotlight)