Beispiel #1
0
 def __init__(self, config: Union[Dict[str, Any], Callable[..., None]],
              **kwargs):
     super().__init__()
     if isinstance(config, Dict):
         config = builder.build_config(config)
     self.config = config
     self.weights_name = "model_pt.bin"
Beispiel #2
0
 def setup_class(cls):
     cls.config_file_path = "/workspace/models/nlp/chinese_wwm_ext/bert_config.json"
     cls.tf_checkpoint_path = "/workspace/models/nlp/chinese_wwm_ext/bert_model.ckpt"
     cls.huggingface_model_path = "/workspace/models/nlp/chinese_wwm_ext"
     cls.model_path = "/workspace/models/nlp/chinese_wwm_ext/bert_model_ms.ckpt"
     model_cfg = dict(
         type="MSBertForPreTraining",
         config=dict(type="ConfigBase", json_file=cls.config_file_path),
     )
     cls.config = build_config(model_cfg["config"])
     cls.model_tf = build_ms_models(model_cfg)
     cls.model_hf = build_ms_models(model_cfg)
     cls.model_base = transformers.BertModel.from_pretrained(
         cls.huggingface_model_path, config=cls.config_file_path)
     cls.model_base.eval()
     # cls.model_base_mlm = transformers.BertForPreTraining.from_pretrained(
     #     cls.huggingface_model_path, config=cls.config_file_path
     # )
     # cls.model_base_mlm.eval()
     model_cfg.update({"model_path": cls.model_path})
     cls.model = build_ms_models(model_cfg)
     cls.batch_size = 4
     cls.seq_length = 10
     cls.tokens_tensor = {
         "input_ids":
         ops.uniform(
             shape=(cls.batch_size, cls.seq_length),
             minval=Tensor(1, mindspore.int32),
             maxval=Tensor(100, mindspore.int32),
             dtype=mindspore.int32,
         ),
         "attention_mask":
         ops.uniform(
             shape=(cls.batch_size, cls.seq_length),
             minval=Tensor(0, mindspore.int32),
             maxval=Tensor(2, mindspore.int32),
             dtype=mindspore.int32,
         ),
         "token_type_ids":
         ops.uniform(
             shape=(cls.batch_size, cls.seq_length),
             minval=Tensor(0, mindspore.int32),
             maxval=Tensor(2, mindspore.int32),
             dtype=mindspore.int32,
         ),
         "position_ids":
         ops.uniform(
             shape=(cls.batch_size, cls.seq_length),
             minval=Tensor(0, mindspore.int32),
             maxval=Tensor(cls.seq_length, mindspore.int32),
             dtype=mindspore.int32,
         ),
     }
Beispiel #3
0
 def setup_class(cls):
     cls.config_file_path = "/workspace/models/nlp/chinese_wwm_ext/bert_config.json"
     cls.tf_checkpoint_path = "/workspace/models/nlp/chinese_wwm_ext/bert_model.ckpt"
     cls.huggingface_model_path = "/workspace/models/nlp/chinese_wwm_ext"
     cls.model_path = "/workspace/models/nlp/chinese_wwm_ext/bert_model_pd.bin"
     model_cfg = dict(
         type="PDBertForPreTraining",
         config=dict(type="ConfigBase", json_file=cls.config_file_path),
     )
     cls.config = build_config(model_cfg["config"])
     cls.model_tf = build_pd_models(model_cfg)
     cls.model_hf = build_pd_models(model_cfg)
     cls.model_base = transformers.BertModel.from_pretrained(
         cls.huggingface_model_path)
     cls.model_base.eval()
     cls.model_base_mlm = transformers.BertForPreTraining.from_pretrained(
         cls.huggingface_model_path)
     cls.model_base_mlm.eval()
     model_cfg.update({"model_path": cls.model_path})
     cls.model = build_pd_models(model_cfg)
     cls.model.eval()
     cls.batch_size = 4
     cls.seq_length = 10
     cls.tokens_tensor = {
         "input_ids":
         paddle.randint(
             low=1,
             high=100,
             shape=(cls.batch_size, cls.seq_length),
             dtype=paddle.int64),
         "attention_mask":
         paddle.randint(
             low=0,
             high=2,
             shape=(cls.batch_size, cls.seq_length),
             dtype=paddle.int64),
         "token_type_ids":
         paddle.randint(
             low=0,
             high=2,
             shape=(cls.batch_size, cls.seq_length),
             dtype=paddle.int64),
         "position_ids":
         paddle.randint(
             low=0,
             high=cls.seq_length,
             shape=(cls.batch_size, cls.seq_length),
             dtype=paddle.int64,
         ),
     }
Beispiel #4
0
 def setup_class(cls):
     cls.config_file_path = "/workspace/models/nlp/uncased_L-12_H-768_A-12/bert_config.json"
     cls.tf_checkpoint_path = "/workspace/models/nlp/uncased_L-12_H-768_A-12/bert_model.ckpt"
     cls.huggingface_model_path = "/workspace/models/nlp/uncased_L-12_H-768_A-12"
     cls.model_path = "/workspace/models/nlp/uncased_L-12_H-768_A-12/bert_model_pt.bin"
     model_cfg = dict(
         type="BertForPreTraining",
         config=dict(type="ConfigBase", json_file=cls.config_file_path),
     )
     cls.config = build_config(model_cfg["config"])
     cls.model_tf = build_torch_models(model_cfg)
     cls.model_hf = build_torch_models(model_cfg)
     cls.model_base = transformers.BertModel.from_pretrained(
         cls.huggingface_model_path, return_dict=True)
     cls.model_base.eval()
     cls.model_base_mlm = transformers.BertForPreTraining.from_pretrained(
         cls.huggingface_model_path, return_dict=True)
     cls.model_base_mlm.eval()
     model_cfg.update({"model_path": cls.model_path})
     cls.model = build_torch_models(model_cfg)
     cls.model.eval()
     cls.batch_size = 4
     cls.seq_length = 10
     cls.tokens_tensor = {
         "input_ids":
         torch.randint(low=1,
                       high=100,
                       size=(cls.batch_size, cls.seq_length),
                       dtype=torch.long),
         "attention_mask":
         torch.randint(low=0,
                       high=1,
                       size=(cls.batch_size, cls.seq_length),
                       dtype=torch.long),
         "token_type_ids":
         torch.randint(low=0,
                       high=1,
                       size=(cls.batch_size, cls.seq_length),
                       dtype=torch.long),
         "position_ids":
         torch.randint(low=0,
                       high=cls.batch_size,
                       size=(cls.batch_size, cls.seq_length),
                       dtype=torch.long),
     }