OpenBMB / BMTrain

Efficient Training (including pre-training and fine-tuning) for Big Models
Apache License 2.0
560 stars 77 forks source link

model中存在Linear(config.hidden_size, config.vocab_size, bias=False)时候,print_inspect(model, "*")会报错。 #150

Closed jinmin527 closed 1 year ago

jinmin527 commented 1 year ago

Is there an existing issue for this?

Description of the Bug

model = BloomForCausalLM.from_pretrained(path) model = bmt.BMTrainModelWrapper(model) print_inspect(model, "*")

打印报错: File "/work/openBMB/BMTrain/bmtrain/inspect/model.py", line 227, in inspect_model return func(*args, **kwargs) File "/work/openBMB/BMTrain/bmtrain/inspect/model.py", line 227, in inspect_model 'shape': tuple(p.size()), AttributeError'shape': tuple(p.size()),: 'NoneType' object has no attribute 'size'

主要原因bloom模型有self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)。 lm_head weight
tensor([[ 1.3199e-03, 2.2888e-03, -1.2589e-03, ..., 1.3962e-03, -1.2054e-03, -1.0757e-03], [ 8.5449e-04, 2.4872e-03, 3.2783e-06, ..., 5.3711e-03, -6.6223e-03, -2.6855e-03], [ 2.4719e-03, -8.7280e-03, -3.5286e-04, ..., -5.4016e-03, 1.3306e-02, -2.9602e-03], ..., [ 1.3123e-03, 3.7689e-03, -3.9673e-04, ..., 1.3962e-03, -7.5150e-04, -9.9945e-04], [ 1.3123e-03, 3.7689e-03, -3.9673e-04, ..., 1.3962e-03, -7.5150e-04, -9.9945e-04], [ 1.3123e-03, 3.7689e-03, -3.9673e-04, ..., 1.3962e-03, -7.5150e-04, -9.9945e-04]], device='cuda:0') bias
None

Environment Information

GCC version: 9.3.0
Torch version: 1.9.0
Linux system version: Ubuntu 20.04
CUDA version: 11.4
Torch's CUDA version (as per torch.cuda.version()): 11.3

To Reproduce

如描述所述,用BMTrainModelWrapper封装bloom模型,必现

Expected Behavior

Screenshots

No response

Additional Information

No response

Confirmation

zkh2016 commented 1 year ago

你好,问题是因为Linear不使用bias的时候注册了个None,所以触发了bug。#151 已经进行适配。