AliceMind icon indicating copy to clipboard operation
AliceMind copied to clipboard

transfer labert model to pytorch

Open Echo0117 opened this issue 3 years ago • 1 comments

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!!

Echo0117 avatar Oct 08 '21 11:10 Echo0117

same

RobinLaw120 avatar Nov 24 '21 09:11 RobinLaw120