Manuscript Offprint
arXiv:2610.02288AdaptViT: Runtime-Adaptive Vision Transformer Deployment on Custom RISC-V
Vishnu PS, Ajay Kumar M, Yike Li, Robert Bogdan Staszewski, Deepu John University College Dublin, Ireland
Abstract—Deploying Vision Transformers (ViTs) on low-power edge devices is challenging due to high computational demands. Conventional pruning frameworks require a separate compiled binary for each sparsity level, increasing storage overhead and limiting runtime adaptability. This paper presents an end-to-end deployment pipeline that transforms pretrained ViTs into a single runtime-configurable binary, enabling dynamic compute-budget switching on embedded CPUs. This is achieved by restructuring generated C kernels with modified loop bounds and binary-mask control logic, allowing execution to switch across discrete sparsity levels via compact external configuration files. Compared to multi-binary deployment, the proposed runtime-adaptive approach reduces on-device storage by up to 4.86×, requiring only 163 MB for ViT-Base instead of nearly 800 MB. To maximize pruning efficiency, we introduce a hardware-aligned block pruning strategy for Multi-Layer Perceptron (MLP) layers. In addition, a custom ISA extension is proposed to exploit input-reuse patterns in linear projection kernels. On a Synopsys TRV32P3FX RISC-V processor, the full system achieves up to 2.8× speedup at 65% MLP and 50% attention-head pruning for ViT-Base. The ISA extension alone provides a 1.56× speedup and 33% lower inference energy, with a 24.7% area overhead in a TSMC 28 nm implementation.
Index Terms—ViT, Runtime pruning, Elastic inference, RISC-V, ASIC.
I. INTRODUCTION
Deploying deep learning models on edge devices requires high computational efficiency without significant loss in accuracy [1]. However, embedded processors are constrained by limited memory and compute resources. Vision Transformers (ViTs) achieve strong performance but incur high computational and memory costs due to Multi-Head Self-Attention (MHSA) and large Feed-Forward Networks (FFNs), limiting their suitability for embedded deployment [2]–[4]. Model pruning is therefore widely used to reduce complexity by trading accuracy for efficiency. However, edge environments are dynamic, with changing constraints due to battery levels, workload changes, or user demands. This motivates the need for multiple operating points with runtime adaptability and minimal overhead. A straightforward solution of storing and switching between multiple pruned binaries is impractical on microcontrollers due to high flash usage and the need to reload models when switching configurations.
Existing approaches can be broadly categorized into dynamic and static methods. Dynamic methods adapt computation at runtime. For instance, token pruning in ViTs [5], [6] removes uninformative tokens per input to reduce attention cost, but introduces irregular execution and memory access patterns that are difficult to optimize on embedded hardware. Static structured pruning methods, such as LPViT [7], apply hardware-aware block pruning to improve efficiency but result in fixed sparsity configurations, limiting runtime switching across operating points. Parikh et al. [8] combine weight pruning with input-adaptive token pruning on FPGA accelerators; however, the weight pruning stage requires retraining and yields a fixed sparsity structure, so each operating point still requires a separately trained model. Once-for-All [9] enables multi-width inference within a single network, but relies on specialized training from scratch and cannot directly leverage pretrained models. SnapViT [10] enables multi-level post-training pruning of pretrained ViTs using importance and correlation scores, generating multiple sparsity configurations without retraining. However, evaluation is limited to Python simulation and does not address embedded deployment, where compiler toolchains generate static C execution paths that make runtime-adaptive pruning difficult to realize efficiently. To address this gap, we propose an end-to-end deployment pipeline that enables runtime-adaptive ViT inference on RISC-V processors starting from pretrained models. Our main contributions are:
• Hardware-aware structured static pruning for ViTs: We extend the SnapViT pruning framework [10] with block-structured MLP pruning, replacing neuron-level pruning to improve hardware efficiency.
• Runtime-configurable inference pipeline: We propose an end-to-end framework that enables runtime-adaptive inference of pretrained ViT on RISC-V processors from a single compiled binary, with minimal overhead.
• ISA-level acceleration: We introduce a custom MAC2 instruction to RISC-V ISA to further accelerate ViT inference.
This work was supported by Taighde Éireann – Research Ireland (22/US/3848, 21/RP-2TF/10019), the National Science Foundation (2315851, 2106634), the Department for the Economy, Northern Ireland (USI-226).

Fig. 1: MLP Pruning Method.
A. C Code Transformation
While dynamic selection of active dimensions is straightforward in high-level environments such as Python, reproducing this behavior in bare-metal C is challenging. During edge deployment, high-level runtime abstractions are removed and TVM generates optimized C code with fixed memory layouts and static loop bounds. Introducing conditional mask checks inside compute-intensive regions adds control-flow overhead, reducing efficiency. Therefore, exploiting sparsity on embedded targets requires a post-compilation transformation that restructures loops to enable safe skipping of computation at coarse-grained block boundaries with minimal overhead.
The TVM compiler maps ViT operations into C kernels across encoder blocks. In the generated code, linear projections (QKV projection, output projection, FC1, and FC2) are implemented as four dense_pack kernel variants, repeated across 12 transformer blocks. Similarly, attention score computation and value aggregation are implemented using two fused_nn_batch_matmul kernels. Profiling on the target RISC-V processor shows these kernels dominate execution, accounting for approximately and of total inference cycles for ViT-Small and ViT-Base, respectively. Since structured pruning targets attention heads and MLP blocks, optimizing only these kernels captures most achievable speedup. We use AugReg ViT-Small (, 6 heads) as the reference model for the remainder of this section.
- Dense Kernel Restructuring: All four dense_pack kernels share the same inner-loop structure, where a single input activation is multiplied with eight weights and accumulated into eight outputs per iteration, defining an 8-output compute granularity. However, the dimension along which sparsity appears differs across kernel types. Table I summarizes tensor layouts across ViT-Small. In QKV projections, the 1152 output channels correspond to concatenated , , and , with each attention head spanning 64 channels. A pruned head therefore removes its associated slices. Although TVM tiles this GEMM into 128-column blocks (two heads per tile), we restructure execution to operate at head granularity, enabling head-wise skipping and saving MACs per pruned head. In the output projection, all heads get fused into a 384-dimensional representation, so each output column depends on all heads and tile-level skipping is not possible. Instead, we decompose the 384-dimension dot product into six 64-dimensional head-aligned segments and skip pruned heads, eliminating MACs per head. For the MLP (FC1/FC2), FC1 expands to 1536 and FC2 projects back. TVM splits FC1 into 3 tiles of 512 columns, further decomposed into 64 groups of 8 MACs matching the inner-loop width. In neuron-level pruning (SnapViT), sparsity is irregular, so even at sparsity only 328/2304 eight-wide MAC groups are fully inactive, forcing execution of most 8-MAC groups and yielding only MAC reduction. In contrast, enforcing group-of-8 structured pruning aligns sparsity with hardware granularity, allowing full group skipping and achieving MAC reduction ( improvement). Since FC1 and FC2 share the same mask, skipped groups propagate across both layers, compounding savings.
TABLE I: Dense and Batch Kernel Tensor Layouts
| Layer | Input X | Weight/Input W | Output Y |
|---|---|---|---|
| QKV Proj. | |||
| Attention 1 | |||
| Attention 2 | |||
| Out Proj. | |||
| FC1 (MLP) | |||
| FC2 (MLP) |
- Batch Matmul Restructuring: This class of kernels performs attention score computation (QK ) and value aggregation (AV), offering a direct opportunity to exploit head-level sparsity. Since pruned heads produce zero-valued Q, K, and V in the preceding stage, their corresponding outputs in both kernels are also zero. We exploit this by introducing a binary head mask at kernel call. Active heads are executed via range-restricted calls, while pruned heads are skipped and their output regions are zero-initialized using a single memset. This preserves exact functional equivalence while eliminating MAC operations per pruned head per kernel.
B. Framework Generalization
Although ViT variants differ in dimensions, the TVM-generated kernel structure and execution order remain consistent. This enables the same post-compilation transformations to be applied across models ViT-Small and ViT-Base. We automate this process via a Python script that extracts loop bounds, tile sizes, and memory offsets for each architecture.
C. ISA Extension
The innermost loop of all four dense_pack kernels performs eight MAC operations per iteration, reusing a single input activation across eight weights. While the baseline TRV32P3FX core supports fused floating-point MACs via the F extension, the quantized workload is dominated by integer operations, requiring 16 instructions (8 mul + 8 add) per iteration. A direct multi-MAC instruction is limited by the five-register operand constraint of the 32-bit RISC-V encoding. However, the input-reuse pattern in the kernel enables a dual-MAC instruction operating on a shared activation , two weights , and two accumulators :
The custom hardware instantiates two parallel MAC pipelines sharing operand , broadcasting it to both multipliers while independently processing and , and writing back and in parallel. This reduces the innermost loop from 16 instructions

Fig. 2: Accuracy vs. pruning level

Fig. 3: Acceleration with pruning and ISA extension
to 4. While general-purpose vector (RVV) or packed-SIMD (RVP) extensions could offer higher flexibility, they introduce significant area and architectural complexity. In contrast, the proposed MAC2 provides SIMD-like acceleration tailored to dominant projection kernels with substantially lower hardware overhead.
III. RESULTS
Pruning mask generation across multiple sparsity levels, quantization, and C code generation using TVM (v0.14.dev273) are performed offline on an NVIDIA A100 GPU in Google Colab. Evaluation is conducted on the Oxford-IIIT Pet dataset (37 classes). For each pruning configuration, linear probing is performed, with backbone frozen and top-1 accuracy reported on the test set. The generated C code is post-processed locally and compiled for the TRV32P3FX RISC-V core using Synopsys ASIP Designer (W-2024.12). TRV32P3FX is a 32-bit, 3-stage in-order RISC-V core with single-precision floating-point support, 2-way instruction-level parallelism, and hardware loops. Compilation uses -O3, and latency is measured via instruction-accurate (IA) simulation on both base and ISA-extended cores. RISC-V results are validated against PyTorch quantized inference, confirming identical top-1 predictions. The implementation code will be released as a GitHub repository to support reproducibility.
A. Accuracy Impact
Fig. 2 shows accuracy across six pruning configurations for two ViT variants. The x-axis denotes runtime settings as X/Y, where X and Y represent MLP group and attention head pruning ratios, respectively. Each configuration is evaluated under three execution modes. The first corresponds to FP32

Fig. 4: Trade-off between energy efficiency and INT8 accuracy.
per-neuron pruning. The second is FP32 inference with our group-of-8 structured pruning, introducing hardware-aligned sparsity, but resulting in an average accuracy drop of 2.12% over baseline. The third applies INT8 quantization, leading to an additional 5.07% drop relative to FP32. At the cost of this small degradation, INT8 significantly reduces memory and compute cost, making it suitable for embedded deployment.
B. Storage Requirement Analysis
Let , , , and denote the embedding dimension, MLP dimension, number of transformer blocks, and bytes per weight. Each block contains attention parameters () and MLP parameters () with total size (using and fixed split , ). For pruning configuration , with MLP-pruning ratio and head-pruning ratio , the retained weight fraction and corresponding storage are: , . In the conventional approach, each pruning level is stored as a separate model, leading to total storage for N pruning levels, plus a small code-size overhead due to separate kernel layouts. In the proposed method, a single full model is stored once and shared across all configurations. Runtime adaptability is enabled via lightweight per-variant metadata: (i) pruning masks and (ii) a classifier head. With denoting the number of attention heads per block, the MLP and head masks contain and entries respectively; stored in FP32, this gives mask overhead . Each variant also stores a classifier consisting of a INT16 weight matrix and a -dimensional FP32 bias, where is the number of output classes for the downstream task, giving . Hence, for configurations: . Overall, across ViT-Small and ViT-Base, the proposed approach reduces on-device storage by up to over separate per-pruning-level binaries, requiring only 41.18 MB vs 198.45 MB and 163.37 MB vs 793.80 MB respectively.
C. Runtime Switching Overhead
Switching between pruning configurations incurs minimal overhead. The same executable and shared weight tensor are reused across all operating points. Pruning masks are passed at runtime as references to external stored buffers, and kernel-level skip logic uses these masks to determine active computation. Thus, switching configurations reduces to redirecting pointers to the corresponding mask buffers. The only remaining overhead is classifier handling, where the weight matrix and
https://github.com/psvishnu1/AdaptViT
TABLE II: Hardware Overhead of the Extended Processor
| Metric | Base | Extended |
|---|---|---|
| FPGA Implementation (ZCU102 @ 65 MHz) | ||
| LUT / FF | 10570 / 2186 | 14931 / 2236 |
| DSP / Power | 6 / 0.186 W | 12 / 0.208 W |
| ASIC Synthesis (TSMC 28 nm @ 100 MHz) | ||
| Area () | 21104 | 26315 |
| Power (mW) | 0.3901 | 0.4100 |
| Normalized ADP | 1.00 | 0.79 |
bias are currently copied into a fixed memory location during switching. This cost is negligible compared to full model reload or reinitialization and does not affect real-time execution. The switching costs cycles for ViT-Small / Base, respectively, accounting for less than of single inference cycles. It can be fully eliminated by storing classifier heads as pre-allocated buffers and accessing them via pointers, consistent with the mask mechanism; this is left as future work.
D. Inference Speedup Evaluation
Fig. 3 shows speedup across pruning levels for ViT-Small and ViT-Base (DINO), across two settings. The first captures pruning-only speedup on the baseline RISC-V core relative to the unpruned model. The second includes both pruning and the proposed ISA extension, normalized to the unpruned model on the un-extended core. An all-ones mask (0/0) run isolates runtime control overhead, which remains below 5%, confirming negligible skip-logic cost. The MAC2 instruction provides up to speedup for the unpruned model, leading to a combined speedup of up to at the highest pruning level for ViT-Base. Fig. 4 presents energy and accuracy trends across pruning levels on the extended RISC-V, relative to the unpruned baseline. Energy per inference is calculated as , where P denotes ASIC synthesis estimated power, C the IA simulation cycle count, and f the operating frequency. At zero pruning, the observed 33% energy reduction is solely due to the MAC2 extension. Additional pruning progressively reduces energy consumption due to lower MAC operations. The INT8 accuracy curve shows the corresponding drop under increasing sparsity. Together, these trends highlight the energy–accuracy trade-off, allowing selection of operating points based on application constraints. ViT-Small shows larger accuracy degradation due to lower redundancy compared to ViT-Base.
E. Hardware Overhead
The hardware synthesis results in Table II show that FPGA implementation adds 6 DSPs with higher dynamic power over the base core. ASIC results (Synopsys Design Compiler v2024.09, typical corner, default switching activity) indicate area and power overhead. To evaluate area-delay efficiency, we report normalized Area-Delay Product (ADP) with respect to the baseline, where delay is measured using unpruned ViT-Base execution time; lower ADP implies better overall efficiency. As shown, the extended core achieves a lower ADP than the baseline.
IV. CONCLUSION
This work presents an end-to-end framework for runtime-adaptive Vision Transformer (ViT) inference on embedded RISC-V processors. We combine post-training structured pruning with a hardware-aligned group-of-8 scheme and mask-based skip logic, enabling a single compiled binary to support multiple sparsity levels without recompilation. To further improve efficiency, we introduce a custom MAC2 ISA extension that exploits input reuse pattern in dominant linear projection kernels. On the target RISC-V, the proposed system achieves up to inference speedup, energy reduction, and up to storage savings. While there is an inherent trade-off between accuracy and efficiency across pruning levels, the proposed framework enables low-overhead switching between operating points during inference based on application requirements. Overall, aligning structured sparsity with hardware execution granularity, together with lightweight ISA support, enables efficient and flexible ViT deployment on edge devices. Future work will extend mask-based skipping to nonlinear layers and explore heterogeneous acceleration using vector or matrix compute engines.
ACKNOWLEDGMENT
The authors would like to thank Prof. Lizy K. John (University of Texas at Austin) for the valuable feedbacks and insightful discussions on this work.
REFERENCES
[1] D. Liu, H. Kong, X. Luo, W. Liu, and R. Subramaniam, “Bringing ai to edge: From deep learning’s perspective,” Neurocomputing, vol. 485, pp. 297–320, 2022.
[2] A. Dosovitskiy, L. Beyer, A. Kolesnikov, D. Weissenborn, X. Zhai, T. Unterthiner, M. Dehghani, M. Minderer, G. Heigold, S. Gelly, J. Uszkoreit, and N. Houlsby, “An image is worth 16x16 words: Transformers for image recognition at scale,” in International Conference on Learning Representations, 2021.
[3] H. Kaneko and L. Meng, “Analysis towards deployment and acceleration for vit on a lightweight risc-v processor,” in 6th International Conference on Industrial Artificial Intelligence (IAI). IEEE, 2024, pp. 1–6.
[4] F. Chen, Z. Luo, L. Zhou, X. Pan, and Y. Jiang, “Comprehensive survey of model compression and speed up for vision transformers,” arXiv preprint arXiv:2404.10407, 2024.
[5] Y. Rao, W. Zhao, B. Liu, J. Lu, J. Zhou, and C.-J. Hsieh, “Dynamicvit: Efficient vision transformers with dynamic token sparsification,” Advances in neural information processing systems, vol. 34, pp. 13937–13949, 2021.
[6] P. Dong, M. Sun, A. Lu, Y. Xie, K. Liu, Z. Kong, X. Meng, Z. Li, X. Lin, Z. Fang et al., “Heatvit: Hardware-efficient adaptive token pruning for vision transformers,” in 2023 IEEE International Symposium on High-Performance Computer Architecture (HPCA). IEEE, 2023, pp. 442–455.
[7] K. Xu, Z. Wang, C. Chen, X. Geng, J. Lin, X. Yang, M. Wu, X. Li, and W. Lin, “Lpvit: Low-power semi-structured pruning for vision transformers,” in European Conference on Computer Vision. Springer, 2024, pp. 269–287.
[8] D. Parikh, S. Li, B. Zhang, R. Kannan, C. Busart, and V. Prasanna, “Accelerating vit inference on fpga through static and dynamic pruning,” in 32nd Annual International Symposium on Field-Programmable Custom Computing Machines (FCCM). IEEE, 2024, pp. 78–89.
[9] H. Cai, C. Gan, T. Wang, Z. Zhang, and S. Han, “Once-for-all: Train one network and specialize it for efficient deployment,” arXiv preprint arXiv:1908.09791, 2019.
[10] W. Simoncini, M. Dorkenwald, T. Blankevoort, C. G. Snoek, and Y. M. Asano, “Elastic vits from pretrained models without retraining,” arXiv preprint arXiv:2510.17700, 2025.
[11] A. Or, A. Jain, D. Vega-Myhre, J. Cai, C. D. Hernandez, Z. Zheng, D. Guessous, V. Kuznetsov, C. Puhrsch, M. Saroufim et al., “Torchao: Pytorch-native training-to-serving model optimization,” arXiv preprint arXiv:2507.16099, 2025.