马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from transformers import AutoModel
#定义debert模型
class LLMModel(nn.Module):
def __init__(self, cfg, config_path=None, pretrained=False):
super().__init__()
self.cfg = cfg
if config_path is None:
self.config = AutoConfig.from_pretrained(cfg.model, output_hidden_states=True)#
self.config.hidden_dropout = 0.
self.config.hidden_dropout_prob = 0.
self.config.attention_dropout = 0.
self.config.attention_probs_dropout_prob = 0.
self.config.add_pooling_layer = False
else:
self.config = torch.load(config_path)
if pretrained:
self.model = AutoModel.from_pretrained(cfg.model, config=self.config)
else:
self.model = AutoModel.from_config(self.config)
model = LLMModel(CFG, config_path=config_path,pretrained=False)
模型参数如下DebertaConfig {
"_name_or_path": "microsoft/deberta-xlarge",
"add_pooling_layer": false,
"attention_dropout": 0.0,
"attention_probs_dropout_prob": 0.0,
"hidden_act": "gelu",
"hidden_dropout": 0.0,
"hidden_dropout_prob": 0.0,
"hidden_size": 1024,
"initializer_range": 0.02,
"intermediate_size": 4096,
"layer_norm_eps": 1e-07,
"max_position_embeddings": 512,
"max_relative_positions": -1,
"model_type": "deberta",
"num_attention_heads": 16,
"num_hidden_layers": 48,
"output_hidden_states": true,
"pad_token_id": 0,
"pooler_dropout": 0,
"pooler_hidden_act": "gelu",
"pooler_hidden_size": 1024,
"pos_att_type": [
"c2p",
"p2c"
],
"position_biased_input": false,
"relative_attention": true,
"transformers_version": "4.45.1",
"type_vocab_size": 0,
"vocab_size": 50265
}
报错如下/tmp/ipykernel_31/3171944020.py:15: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
self.config = torch.load(config_path)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[42], line 1
----> 1 model = LLMModel(CFG, config_path=config_path,pretrained=False)
Cell In[40], line 19, in LLMModel.__init__(self, cfg, config_path, pretrained)
17 self.model = AutoModel.from_pretrained(cfg.model, config=self.config)
18 else:
---> 19 self.model = AutoModel.from_config(self.config)
21 self.model.resize_token_embeddings(len(tokenizer))#
22 if self.cfg.gradient_checkpointing:#使用梯度检查点技术时,模型不会保存前向传播计算的中间结果,减少占用内存
File /opt/conda/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:440, in _BaseAutoModelClass.from_config(cls, config, **kwargs)
438 elif type(config) in cls._model_mapping.keys():
439 model_class = _get_model_class(config, cls._model_mapping)
--> 440 return model_class._from_config(config, **kwargs)
442 raise ValueError(
443 f"Unrecognized configuration class {config.__class__} for this kind of AutoModel: {cls.__name__}.\n"
444 f"Model type should be one of {', '.join(c.__name__ for c in cls._model_mapping.keys())}."
445 )
File /opt/conda/lib/python3.10/site-packages/transformers/modeling_utils.py:1494, in PreTrainedModel._from_config(cls, config, **kwargs)
1490 dtype_orig = cls._set_default_torch_dtype(torch_dtype)
1492 config = copy.deepcopy(config) # We do not want to modify the config inplace in _from_config.
-> 1494 if config._attn_implementation_internal is not None:
1495 # In this case, the config has been created with the attn_implementation set by the user, which we
1496 # should respect.
1497 attn_implementation = config._attn_implementation_internal
1498 else:
File /opt/conda/lib/python3.10/site-packages/transformers/configuration_utils.py:202, in PretrainedConfig.__getattribute__(self, key)
200 if key != "attribute_map" and key in super().__getattribute__("attribute_map"):
201 key = super().__getattribute__("attribute_map")[key]
--> 202 return super().__getattribute__(key)
AttributeError: 'DebertaConfig' object has no attribute '_attn_implementation_internal'
|