运行模型后提示Traceback (most recent call last): File "E:\data\ChatGPT\ChatGPT_Test.py", line 9, in <module> model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium",padding_side="left") File "C:\Users\MIS_L\AppData\Roaming\Python\Python311\site-packages\transformers\models\auto\auto_factory.py", line 471, in from_pretrained return model_class.from_pretrained( File "C:\Users\MIS_L\AppData\Roaming\Python\Python311\site-packages\transformers\modeling_utils.py", line 2498, in from_pretrained model = cls(config, *model_args, **model_kwargs) TypeError: GPT2LMHeadModel.__init__() got an unexpected keyword argument 'padding_side',需要如何修改
时间: 2023-05-27 09:01:30 浏览: 183
根据提示信息,GPT2LMHeadModel并不支持padding_side参数,因此需要修改AutoModelForCausalLM.from_pretrained()中的padding_side参数为其他可用的参数,如padding_mode或pad_token_id等。例如:
```
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium", padding_mode="left")
```
相关问题
运行模型后提示Traceback (most recent call last): File "E:\data\ChatGPT\ChatGPT_Test.py", line 9, in <module> model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium",padding_mode="left") File "C:\Users\MIS_L\AppData\Roaming\Python\Python311\site-packages\transformers\models\auto\auto_factory.py", line 471, in from_pretrained return model_class.from_pretrained( File "C:\Users\MIS_L\AppData\Roaming\Python\Python311\site-packages\transformers\modeling_utils.py", line 2498, in from_pretrained model = cls(config, *model_args, **model_kwargs) TypeError: GPT2LMHeadModel.__init__() got an unexpected keyword argument 'padding_mode',需要如何修改
这个错误提示是由于参数padding_mode是在AutoModelForCausalLM的构造函数中被传递给GPT2LMHeadModel的构造函数,但是GPT2LMHeadModel的构造函数中并没有定义这个参数。
解决这个问题,可以直接在调用GPT2LMHeadModel时,将padding_mode参数从参数列表中去除。
修改前的代码:
```python
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium", padding_mode="left")
```
修改后的代码:
```python
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
```
这样就可以避免这个错误了。
Traceback (most recent call last): File "D:\162040229\2023DataFusion\network_test.py", line 100, in <module> output = mynet(image) TypeError: 'collections.OrderedDict' object is not callable
这个错误通常是因为你在代码中使用了一个 `collections.OrderedDict` 对象,然而你将其当做了一个函数来调用。你需要检查一下你的代码,看看是否在 `mynet` 中的某个地方调用了一个字典对象。
如果 `mynet` 是一个类,你可能需要在类中添加一个 `__call__` 方法来使得该类实例能够被调用,例如:
```python
class MyNet(nn.Module):
def __init__(self):
super(MyNet, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2),
)
self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
self.classifier = nn.Sequential(
nn.Linear(128 * 7 * 7, 512),
nn.ReLU(inplace=True),
nn.Linear(512, 10),
)
def forward(self, x):
x = self.features(x)
x = self.avgpool(x)
x = torch.flatten(x, 1)
x = self.classifier(x)
return x
def __call__(self, x):
return self.forward(x)
```
如果 `mynet` 是一个函数,那么你需要确保在函数定义中没有使用和 `mynet` 相同的变量名。例如:
```python
def mynet(x):
features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2),
)
avgpool = nn.AdaptiveAvgPool2d((7, 7))
classifier = nn.Sequential(
nn.Linear(128 * 7 * 7, 512),
nn.ReLU(inplace=True),
nn.Linear(512, 10),
)
x = features(x)
x = avgpool(x)
x = torch.flatten(x, 1)
x = classifier(x)
return x
```
希望这些信息能帮到你解决问题!
阅读全文