Qwen-VL icon indicating copy to clipboard operation
Qwen-VL copied to clipboard

[BUG] RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.<title>

Open WeiXuanLi-1024 opened this issue 1 year ago • 9 comments

是否已有关于该错误的issue或讨论? | Is there an existing issue / discussion for this?

  • [X] 我已经搜索过已有的issues和讨论 | I have searched the existing issues / discussions

该问题是否在FAQ中有解答? | Is there an existing answer for this in FAQ?

  • [X] 我已经搜索过FAQ | I have searched FAQ

当前行为 | Current Behavior

[ { "id": "identity_0", "conversations": [ { "from": "user", "value": "你好" }, { "from": "assistant", "value": "我是Qwen-VL,一个支持视觉输入的大模型。" } ] }, { "id": "identity_1", "conversations": [ { "from": "user", "value": "Picture 1: https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg\n图中的狗是什么品种?" }, { "from": "assistant", "value": "图中是一只拉布拉多犬。" }, { "from": "user", "value": "框出图中的格子衬衫" }, { "from": "assistant", "value": "格子衬衫(588,499),(725,789)" } ] }, { "id": "identity_2", "conversations": [ { "from": "user", "value": "Picture 1: assets/mm_tutorial/Chongqing.jpeg\nPicture 2: assets/mm_tutorial/Beijing.jpeg\n图中都是哪" }, { "from": "assistant", "value": "第一张图片是重庆的城市天际线,第二张图片是北京的天际线。" } ] } ] 使用以上数据,使用 finetune_lora_single_gpu.sh 脚本微调出现错误

期望行为 | Expected Behavior

No response

复现方法 | Steps To Reproduce

No response

运行环境 | Environment

- OS:ubuntu22
- Python:3.10
- Transformers:4.32
- PyTorch:2.0.1
- CUDA (`python -c 'import torch; print(torch.version.cuda)'`):11.7

备注 | Anything else?

No response

WeiXuanLi-1024 avatar Oct 16 '23 06:10 WeiXuanLi-1024

Traceback (most recent call last): File "/data/liwx/Qwen-VL/finetune.py", line 379, in train() File "/data/liwx/Qwen-VL/finetune.py", line 371, in train trainer.train() File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/transformers/trainer.py", line 1555, in train return inner_training_loop( File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/transformers/trainer.py", line 1838, in _inner_training_loop tr_loss_step = self.training_step(model, inputs) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/transformers/trainer.py", line 2683, in training_step loss = self.compute_loss(model, inputs) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/transformers/trainer.py", line 2708, in compute_loss outputs = model(**inputs) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/accelerate/utils/operations.py", line 636, in forward return model_forward(*args, **kwargs) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/accelerate/utils/operations.py", line 624, in call return convert_to_fp32(self.model_forward(*args, **kwargs)) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/torch/amp/autocast_mode.py", line 14, in decorate_autocast return func(*args, **kwargs) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/peft/peft_model.py", line 918, in forward return self.base_model( File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/peft/tuners/tuners_utils.py", line 94, in forward return self.model.forward(*args, **kwargs) File "/home/enbo/.cache/huggingface/modules/transformers_modules/Qwen-VL-Chat/modeling_qwen.py", line 848, in forward transformer_outputs = self.transformer( File "/home/enbo/anaconda3/envs/llama2-accessory/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/home/enbo/.cache/huggingface/modules/transformers_modules/Qwen-VL-Chat/modeling_qwen.py", line 657, in forward hidden_states[i][a + 1 : b] = images[idx] RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

WeiXuanLi-1024 avatar Oct 16 '23 06:10 WeiXuanLi-1024

我也遇到了这个问题

doraemon-plus avatar Oct 16 '23 07:10 doraemon-plus

同样遇到这个问题

DZ9 avatar Oct 16 '23 10:10 DZ9

感谢您的尝试,在inplace前先clone()就可以解决这个问题, 可以同步下huggingface上最新的模型代码,可以参考这个https://huggingface.co/Qwen/Qwen-VL-Chat/commit/e71876524333aa79e65b19c557c639175552e689

ShuaiBai623 avatar Oct 16 '23 15:10 ShuaiBai623

在加载Qwen-VL-Chat的绝对路径,使用最新的hugging face上的Qwen-VL-Chat文件,就不报这个错误了

YuanJZhang avatar Nov 07 '23 05:11 YuanJZhang

感谢您的尝试,在inplace前先clone()就可以解决这个问题, 可以同步下huggingface上最新的模型代码,可以参考这个https://huggingface.co/Qwen/Qwen-VL-Chat/commit/e71876524333aa79e65b19c557c639175552e689

但是我修改后,运行 hugginface会冲掉我的修改,这个怎么解决?感谢

JackIRose avatar Jan 30 '24 08:01 JackIRose

感谢您的尝试,在inplace前先clone()就可以解决这个问题, 可以同步下huggingface上最新的模型代码,可以参考这个https://huggingface.co/Qwen/Qwen-VL-Chat/commit/e71876524333aa79e65b19c557c639175552e689

但是我修改后,运行 hugginface会冲掉我的修改,这个怎么解决?感谢 这个问题已经解决了,要修改原来下载的文件内容而不是在.cache/transformer的文件内容,因为前者会覆盖后者的内容,因此在后面的文件改没有用

JackIRose avatar Jan 30 '24 08:01 JackIRose

感谢您的尝试,在inplace前先clone()就可以解决这个问题, 可以同步下huggingface上最新的模型代码,可以参考这个https://huggingface.co/Qwen/Qwen-VL-Chat/commit/e71876524333aa79e65b19c557c639175552e689

但是我修改后,运行 hugginface会冲掉我的修改,这个怎么解决?感谢 这个问题已经解决了,要修改原来下载的文件内容而不是在.cache/transformer的文件内容,因为前者会覆盖后者的内容,因此在后面的文件改没有用

您好 请问一下,我只在 .cache目录下 才能找到这个文件,您说的“原来的文件”是手动下载的吗?

KuruakuMai avatar May 09 '24 03:05 KuruakuMai

感谢您的尝试,在inplace前先clone()就可以解决这个问题, 可以同步下huggingface上最新的模型代码,可以参考这个https://huggingface.co/Qwen/Qwen-VL-Chat/commit/e71876524333aa79e65b19c557c639175552e689

但是我修改后,运行 hugginface会冲掉我的修改,这个怎么解决?感谢 这个问题已经解决了,要修改原来下载的文件内容而不是在.cache/transformer的文件内容,因为前者会覆盖后者的内容,因此在后面的文件改没有用

您好 请问一下,我只在 .cache目录下 才能找到这个文件,您说的“原来的文件”是手动下载的吗?

“原来的文件” 是你模型文件在本地下载好的路径,例如 /home/your_name/models/Qwen-VL-Chat/modeling_qwen.py", 而.cache 是你程序每次运行缓存的路径,会被覆盖,如果你的模型文件是自动下载的,那就修改$HOME/.cache/huggingface/transformers 里的文件

darkpromise98 avatar Jun 11 '24 09:06 darkpromise98