Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'to' #5

Open
yult0821 opened this issue Mar 4, 2025 · 2 comments
Open

AttributeError: 'NoneType' object has no attribute 'to' #5

yult0821 opened this issue Mar 4, 2025 · 2 comments

Comments

@yult0821
Copy link

yult0821 commented Mar 4, 2025

在尝试对Llama-2-7b-hf进行压缩时,报错如下:

Traceback (most recent call last):
  File "/home/xxx/projects/JSQ/main.py", line 53, in <module>
    main(args)
  File "/home/xxx/projects/JSQ/main.py", line 15, in main
    light_model = joint_pq(args, model, tokenizer)
  File "/home/xxx/projects/JSQ/jsq/prune.py", line 45, in joint_pq
    inps, outs, attention_mask, position_ids = inps.to(dev), outs.to(dev), attention_mask.to(
AttributeError: 'NoneType' object has no attribute 'to'

初步分析,是在执行inps, outs, attention_mask, position_ids = prepare_calibration_input(model, args, dataloader, device)时,将attention_mask赋值为None类型。四个变量的值打印出来如下所示:

torch.Size([128, 2048, 4096]) torch.bfloat16
torch.Size([128, 2048, 4096]) torch.bfloat16
None
tensor([[   0,    1,    2,  ..., 2045, 2046, 2047]], device='cuda:0')

请问是否知道可能的错误原因及解决方式呢?谢谢~

@catalyticcc
Copy link

catalyticcc commented Mar 4, 2025

1小时前我和你遇到了一样的错误,原因是在utils.py文件的Catcher类中会将Llama-2-7b-hf识别为非CHATGLM属性,因此会执行cache['attention_mask'] = kwargs['attention_mask'],但这一项在Llama类model中不存在。这一错误在更换成文章中推荐的chatglm3-6b模型即可解决。若仍然要使用llama2,建议根据Llama类model的属性重写Catcher类以获得正确的inps, outs, attention_mask, position_ids四元组,期待你的解决方案~

@yult0821
Copy link
Author

yult0821 commented Mar 5, 2025

1小时前我和你遇到了一样的错误,原因是在utils.py文件的Catcher类中会将Llama-2-7b-hf识别为非CHATGLM属性,因此会执行cache['attention_mask'] = kwargs['attention_mask'],但这一项在Llama类model中不存在。这一错误在更换成文章中推荐的chatglm3-6b模型即可解决。若仍然要使用llama2,建议根据Llama类model的属性重写Catcher类以获得正确的inps, outs, attention_mask, position_ids四元组,期待你的解决方案~

谢谢你的回答

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants