aehrc / cvt2distilgpt2

Improving Chest X-Ray Report Generation by Leveraging Warm-Starting
GNU General Public License v3.0
62 stars 5 forks source link

'GPT2Decoder' object has no attribute 'decoder' #4

Open jinghaoliu opened 1 year ago

jinghaoliu commented 1 year ago

Hi Aaron, thank you for your great work. I tried to train for IU X-Ray data. But the program returns this error:

AttributeError 'GPT2Decoder' object has no attribute 'decoder' File "/media/data/cvt2distilgpt2/transmodal/utils.py", line 234, in _getattr return getattr(obj, attr, *args) File "/media/data/cvt2distilgpt2/transmodal/utils.py", line 235, in rgetattr return functools.reduce(_getattr, [obj] + attr.split('.')) File "/media/data/cvt2distilgpt2/transmodal/model.py", line 684, in configure_optimizers named_params = rgetattr(self, k).named_parameters() File "/media/data/lcvt2distilgpt2/main.py", line 48, in objective trainer.fit(transmodal, datamodule=dataset) File "/media/data/cvt2distilgpt2/main.py", line 65, in main objective(config) File "/media/data/cvt2distilgpt2/main.py", line 175, in main(clargs)

I debug the bug, GPT2Decoder only has a similar attribute named 'encoder_decoder'. I suspect the problem is caused by the huggingface checkpoint version not matching your codes. Because the same error also exists in predict mode.

I used your latest repository and installed all needed packages with your pip requirements.txt.

transformers==4.15.0 download CvT2DistilGPT2 checkpoint from your website. download DistilGPT2 checkpoint from huggingface. download CvT-21 Checkpoint from Microsoft download Bert-base-uncased checkpoint from huggingface download chexbert from stanfordmlgroup repository

anicolson commented 1 year ago

Hi jinghaoliu,

I think I know the issue, I'll fix it and then get back to you. Shouldn't take too long.

anicolson commented 1 year ago

There was an error in the configuration file. I've pushed an update, but the error was caused by lines 131 and 140 of https://github.com/aehrc/cvt2distilgpt2/blob/main/config/cvt_21_to_distilgpt2.py (which has been updated).

Thanks for letting me know about this issue. If there are any more issues please let me know.

jinghaoliu commented 1 year ago

Hi Aaron,

I have modified these codes according to your reply. The same codes need to be modified :(https://github.com/aehrc/cvt2distilgpt2/blob/main/task/iu_x_ray_chen/config/cvt_21_to_distilgpt2_scst.py and https://github.com/aehrc/cvt2distilgpt2/blob/main/task/mimic_cxr_jpg_chen/config/cvt_21_to_distilgpt2_scst.py)

The error has been solved by modifying these codes, but I am facing a new error. It still seems to be related to the previous error:

TypeError 'DummyEncoder' object is not callable File "/media/data/cvt2distilgpt2/transmodal/generate.py", line 141, in sample_log_probs outputs = decoder( File "/media/data/cvt2distilgpt2/transmodal/generate.py", line 81, in generate return sample_log_probs( File "/media/data/cvt2distilgpt2/transmodal/network/gpt2decoder.py", line 139, in generate return generate( File "/media/data/cvt2distilgpt2/transmodal/model.py", line 295, in generate outputs = getattr(self, i).generate( File "/media/data/cvt2distilgpt2/transmodal/model.py", line 567, in self_critical_step sample = self.generate( File "/media/data/cvt2distilgpt2/transmodal/model.py", line 352, in training_step return self.self_critical_step(batch, batch_idx) File "/media/data/cvt2distilgpt2/main.py", line 49, in objective trainer.fit(transmodal, datamodule=dataset) File "/media/data/cvt2distilgpt2/main.py", line 66, in main objective(config) File "/media/data/cvt2distilgpt2/main.py", line 176, in main(clargs)

anicolson commented 1 year ago

Hi jinghaoliu,

There were a few issues in:

https://github.com/aehrc/cvt2distilgpt2/blob/main/transmodal/generate.py https://github.com/aehrc/cvt2distilgpt2/blob/main/transmodal/model.py

I updated the code a bit after doing these experiments and did not test everything after the updates (silly me).

I have run the code through to completion, so it should also work for you now.

Please pull the latest version of the repo.

I hope this helps and please let me know if there are any more issues.

jinghaoliu commented 1 year ago

Yes, it is very helpful. Thank you.