transfer labert model to pytorch
- Dominant language
- Python
- Stars
- 2k
- Forks
- 301
- PR merge metrics
- No merged PRs in 30d
Description
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:

Does anyone know if there's a way to make it work?Thanks a lot!!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided convert_tf_checkpoint_to_pytorch function and the referenced model.ckpt/ and labert_config.json paths, then inspect the error shown in the linked screenshot. Reproduce the conversion and determine what prevents the LABERT TensorFlow checkpoint from loading into BertForPreTraining; done means producing a valid pytorch_model.bin.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100