alibaba / AliceMind

ALIbaba's Collection of Encoder-decoders from MinD (Machine IntelligeNce of Damo) Lab
Apache License 2.0
1.97k stars 291 forks source link

transfer labert model to pytorch #23

Open Echo0117 opened 3 years ago

Echo0117 commented 3 years ago

Hi, I'm trying to transfer the labert model to pytorch, I used the code online :

path="./chinese_labert-base-std-512/"
tf_checkpoint_path = path + "model.ckpt/"#自己BERT模型文件夹下的ckpt文件(共3个一组)
bert_config_file = path + "labert_config.json" #自己BERT模型文件夹下的config
pytorch_dump_path = path + "pytorch_model.bin" 

def convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path):
    # Initialise PyTorch model
    config = BertConfig.from_json_file(bert_config_file)
    print(f"Building PyTorch model from configuration: {config}")
    model = BertForPreTraining(config)

    # Load weights from tf checkpoint
    load_tf_weights_in_bert(model, config, tf_checkpoint_path)

    # Save pytorch-model
    print(f"Save PyTorch model to {pytorch_dump_path}")
    torch.save(model.state_dict(), pytorch_dump_path)

convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path)

But I got this:

1633691584(1)

Does anyone know if there's a way to make it work?Thanks a lot!!

RobinLaw120 commented 2 years ago

same