"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "57e9c8321385dfd31bda33df144a4ac849206e06"
Commit 968c1b44 authored by Chris's avatar Chris
Browse files

added file to convert pytorch->tf

parent 96c2b77f
...@@ -21,26 +21,6 @@ import numpy as np ...@@ -21,26 +21,6 @@ import numpy as np
from pytorch_pretrained_bert.modeling import BertConfig, BertModel from pytorch_pretrained_bert.modeling import BertConfig, BertModel
# def __get_var_names(config):
#
# models = {
# 'BertModel': BertModel(config),
# 'BertForMaskedLM': BertForMaskedLM(config),
# 'BertForPreTraining': BertForPreTraining(config),
# 'BertForMultipleChoice': BertForMultipleChoice(config, num_choices=100),
# 'BertForNextSentencePrediction': BertForNextSentencePrediction(config),
# 'BertForSequenceClassification': BertForSequenceClassification(config, num_labels=100),
# 'BertForQuestionAnswering': BertForQuestionAnswering(config)
# }
#
# for name, model in models.items():
# state_dict = model.state_dict()
# torch_vars = []
# for var_ in state_dict:
# torch_vars.append(var_ + ', ' + str(tuple(state_dict[var_].shape)))
# json.dump(torch_vars, fp=open('torch_var_names_{}.json'.format(name), 'w'), indent=3)
def convert_hf_checkpoint_to_tf(model:BertModel, ckpt_dir:str): def convert_hf_checkpoint_to_tf(model:BertModel, ckpt_dir:str):
...@@ -58,8 +38,7 @@ def convert_hf_checkpoint_to_tf(model:BertModel, ckpt_dir:str): ...@@ -58,8 +38,7 @@ def convert_hf_checkpoint_to_tf(model:BertModel, ckpt_dir:str):
N BertForQuestionAnswering N BertForQuestionAnswering
Note: Note:
TF isn't & shouldn't be a package-level requirement; this To keep TF out of package-level requirements, tf is imported locally.
feature is requested enough to warrant a local import.
""" """
import tensorflow as tf import tensorflow as tf
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment