ClipCap-Chinese icon indicating copy to clipboard operation
ClipCap-Chinese copied to clipboard

AttributeError: type object 'GPT2LMHeadModel' has no attribute 'from_config'

Open funykatebird opened this issue 2 years ago • 3 comments

raceback (most recent call last): File "ClipCap-Chinese-master/models/model.py", line 75, in init self.gpt2 = GPT2LMHeadModel.from_pretrained(gpt2_path) File "/root/miniconda3/lib/python3.8/site-packages/transformers/modeling_utils.py", line 1222, in from_pretrained raise EnvironmentError( OSError: Error no file named ['pytorch_model.bin', 'tf_model.h5', 'model.ckpt.index', 'flax_model.msgpack'] found in directory pretrain_models/gpt2 or from_tf and from_flax set to False.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/ClipCap-Chinese-master/train.py", line 150, in main(args) File "/ClipCap-Chinese-master/train.py", line 114, in main model = ClipCaptionModel( File "/ClipCap-Chinese-master/models/model.py", line 79, in init self.gpt2 = GPT2LMHeadModel.from_config(config) AttributeError: type object 'GPT2LMHeadModel' has no attribute 'from_config'

funykatebird avatar Nov 21 '22 04:11 funykatebird

可直接修改为加载GPT2LMHeadModel.from_pretrained("uer/gpt2-chinese-cluecorpussmall") 然后下载对应的模型文件 https://huggingface.co/uer/gpt2-chinese-cluecorpussmall/tree/main

funykatebird avatar Nov 21 '22 04:11 funykatebird

一般就是数据和模型一个在cpu,一个在GPU RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu 方法一: args.device = torch.device("cpu")

方法二: 将数据加载到GPU上 images = images.to(args.device) clip_embeds = clip_model.encode_image(images) # clip_embeds = clip_embeds.unsqueeze(1).repeat(1, args.num_generate, 1).view(-1, clip_embeds.size(-1)) clip_embeds = clip_embeds.unsqueeze(1).repeat(1, args.num_generate, 1).view(-1, clip_embeds.size(-1)).float()

funykatebird avatar Nov 22 '22 07:11 funykatebird

顶,好帖子,谢谢楼主

minimumcat avatar May 25 '23 08:05 minimumcat