Visual Prompt Tuning (VPT)

本文提出了一种新的方法,称为VPT,用于微调大规模视觉Transformer模型。VPT在输入空间中引入少量可训练参数,而不是修改模型主干,从而在保持模型性能的同时降低了存储成本。与传统的全微调相比,VPT在某些情况下甚至表现更好,且只需极小比例的参数。研究还对比了适配器和BitFit等方法,表明VPT在视觉任务上的适应性更优。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Abstract

只在输入空间中引入少量(小于1%的模型参数)可训练参数,同时保持模型主干不变。

在许多情况下,VPT甚至超越了模型容量和训练数据规模的全面微调,同时降低了每个任务的存储成本。

Introduction

常用技术:full fine-tuning,这种策略要求为每一个任务存储和部署一个独立的骨干参数副本。这是一个昂贵且通常不可行的命题,特别是对于现代的基于Transformer的体系结构

Fig. 1. Visual-Prompt Tuning (VPT) vs. other transfer learning methods. (a) Current transfer learning protocols are grouped based on the tuning scope: Full fine-tuning, Head-oriented, and Backbone-oriented approaches. (b) VPT instead adds extra parameters in the input space. (c) Performance of different methods on a wide range of downstream classification tasks adapting a pre-trained ViT-B backbone, with mean and standard deviation annotated. VPT outperforms Full fine-tuning 20 out of 24 cases while using less than 1% of all model parameters

(a) 三种传统微调方法:Full fine-tuning, Head-oriented, and Backbone-oriented approaches

(b) VPT: 我们不是修改或微调预先训练的Transformer本身,而是修改对Transformer的输入

我们的方法只在输入空间中引入少量任务特定的可学习参数,而在下游训练时冻结整个预训练的Transformer骨干。在实践中,这些额外的参数只是预先添加到每个Transformer层的输入序列中,并在微调期间与线性头一起学习。

Related work

Adapters [64] and BitFit [5].

适配器[34]在每个Transformer层中插入额外的轻量级模块。一个适配器模块通常由一个线性向下投影、一个非线性激活函数和一个线性向上投影以及一个剩余连接组成[63,64]。[8]没有插入新的模块,而是在对ConvNets进行微调时,提出更新偏置项并冻结其余的骨干参数。BitFit[3]将该技术应用于变压器,并验证了其在LM调谐上的有效性。我们的研究表明,相对于前面提到的NLP中的两种完善的方法,VPT在适应Transformer模型的视觉任务方面提供了更好的性能。

prompt

treat the prompts as task-specific continuous vectors and directly optimize them via gradients during fine-tuning(最近的研究提出将提示符作为任务特定的连续向量,并在微调过程中通过梯度直接对其进行优化,即Prompt Tuning)

与完全微调相比,它获得了类似的性能,但使用了1000×less参数存储。

方法

Fig. 2. Overview of our proposed Visual-Prompt Tuning. We explore two variants: (a) prepend a set of learnable parameters to each Transformer encoder layer’s input (VPT-deep); (b) only insert the prompt parameters to the first layer’s input (VPTshallow). During training on downstream tasks, only the parameters of prompts and linear head are updated while the whole Transformer encoder is frozen.

VPT-Deep变体为Transformer编码器每层的输入预先设置一组可学习的参数;

VPT-Shallow变体则仅将提示参数插入第一层的输入。

两者在下游任务的训练过程中,只有特定于任务的提示和线性头的参数会更新,而整个Transformer编码器被冻结

方法:在原有VIT的基础上增加可学习的token参数P0P_0P0,这部分的参数需要梯度,其余部分全部冻结

给定一个预训练的Transformer模型,我们在Embed层之后的输入空间中引入一组p个维数为d的连续嵌入,即提示符。在微调期间,只有特定于任务的提示被更新,而Transformer主干被冻结。

结论

作者提出了一种新的参数有效的方法,将大规模视觉Transformer模型广泛应用到下游任务,即VPT。它超越了其他的微调方法。

### Prompt Tuning 的概念及其在大模型中的应用 Prompt tuning 是一种轻量级的大规模语言模型微调方法,它通过引入可学习的连续向量(称为 prompts 或 prefix vectors),而不是更新整个模型权重来适应新任务。这种方法显著减少了参数数量,同时保持了良好的性能表现[^1]。 --- #### **Prompt Tuning 的核心原理** Prompt tuning 的基本思想是在输入序列前附加一组可训练的 token embeddings(prompts)。这些 prompts 被视为额外的上下文信息,指导预训练模型更好地理解和生成目标输出。相比于传统的全参数微调,prompt tuning 只需优化少量新增加的参数,因此具有更高的效率和更低的计算成本[^3]。 ```python import torch from transformers import BertModel, BertTokenizer class PromptTuningModel(torch.nn.Module): def __init__(self, model_name, num_prompts=10): super(PromptTuningModel, self).__init__() self.bert = BertModel.from_pretrained(model_name) self.tokenizer = BertTokenizer.from_pretrained(model_name) self.prompts = torch.nn.Parameter(torch.randn(num_prompts, self.bert.config.hidden_size)) def forward(self, input_ids, attention_mask=None): batch_size = input_ids.shape[0] prompt_embeddings = self.prompts.unsqueeze(0).expand(batch_size, -1, -1) inputs_embeds = self.bert.embeddings(input_ids=input_ids) combined_inputs = torch.cat([prompt_embeddings, inputs_embeds], dim=1) if attention_mask is not None: extended_attention_mask = torch.cat( [torch.ones((batch_size, prompt_embeddings.size(1)), dtype=torch.long)], dim=-1 ) attention_mask = torch.cat([extended_attention_mask, attention_mask], dim=-1) outputs = self.bert(inputs_embeds=combined_inputs, attention_mask=attention_mask) return outputs.last_hidden_state[:, :len(prompt_embeddings)] ``` 上述代码展示了一个简单的 prompt tuning 实现框架,其中 `num_prompts` 表示要插入的提示长度,而 `self.prompts` 则是需要训练的部分。 --- #### **Prompt Tuning 在美团业务场景的应用** ##### **1. 商品描述优化** 在电商领域,商品描述通常需要简洁明了且吸引消费者注意。通过 prompt tuning 方法,可以将原始的商品标题或其他元数据作为条件输入,并生成高质量的营销文案。例如,给定一段关于食品成分的文字说明,经过适当设计的 prompts,可以让模型专注于提取关键卖点并重新表述为更易懂的形式[^3]。 --- ##### **2. 客服对话系统改进** 对于在线订餐平台而言,高效的客户支持至关重要。采用基于 prompt tuning 构建的服务机器人不仅可以降低运营成本,还能提升响应速度和服务质量。具体来说,当接收到用户的提问时,先由固定的 templates 提供初步意图识别线索,随后依靠 finetuned LLM 进一步细化答案内容[^5]。 --- ##### **3. 推荐系统中的冷启动问题缓解** 面对新人或新品缺乏足够历史交互记录的情况,传统协同过滤算法往往显得乏力。此时如果结合 NLP 技术,则有可能从文本角度挖掘潜在关联性。比如利用带有特定 domain knowledge encoded into its parameters via prompting mechanism 的 transformer architecture 来预测某类用户可能会喜欢哪一类餐厅风格[^4]。 --- #### **总结与展望** 尽管目前仍处于发展阶段,但随着研究深入和技术成熟度不断提高,相信 future work will continue exploring how to better leverage these techniques across diverse real-world applications including but not limited those mentioned above within Meituan ecosystem. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值