update the content in yml

This commit is contained in:
namezhenzhang 2022-07-29 21:24:20 +08:00
parent 617955e08e
commit 3ed54465af
3 changed files with 52 additions and 4 deletions

View File

@ -4,6 +4,8 @@ def create_hub_repo_name(root = "DeltaHub",
dataset = None,
delta_type = None,
model_name_or_path = None,
center_value_only_tags = None,
center_key_value_tags = None
):
r"""Currently, it's only a simple concatenation of the arguments.
"""
@ -14,6 +16,9 @@ def create_hub_repo_name(root = "DeltaHub",
repo_name.append(f"{model_name_or_path}")
repo_name.append(f"{dataset}")
repo_name.extend(list(center_value_only_tags) if center_value_only_tags else [None])
repo_name.extend([f"{k}-{v}" for k,v in center_key_value_tags.items()] if center_key_value_tags else [None])
repo_name = "_".join(repo_name)
repo_name = root+"/"+repo_name

View File

@ -19,7 +19,10 @@ from transformers.file_utils import (
)
from transformers.utils.dummy_pt_objects import PreTrainedModel
import hashlib
from DeltaCenter import OssClient
try:
from DeltaCenter import OssClient
except:
pass
import yaml
from dataclasses import dataclass, field, fields
import datetime
@ -107,6 +110,7 @@ class SaveLoadMixin(PushToHubMixin):
list_tags: Optional[List] = None,
dict_tags: Optional[Dict] = None,
delay_push: bool = False,
test_result = None
):
r"""
Save a model and its configuration file to a directory, so that it can be re-loaded using the
@ -174,8 +178,12 @@ class SaveLoadMixin(PushToHubMixin):
final_center_args = self.create_delta_center_args(center_args=center_args,
center_args_pool=center_args_pool)
state_dict_total_params = sum(p.numel() for p in state_dict.values())
other_tags={}
other_tags.update({'state_dict_total_params(M)':state_dict_total_params/1024/1024})
other_tags.update({'test_result':test_result})
if push_to_dc:
self.create_yml(save_directory, final_center_args, list_tags, dict_tags)
self.create_yml(save_directory, final_center_args, list_tags, dict_tags,other_tags)
if not delay_push:
OssClient.upload(base_dir=save_directory)
@ -187,11 +195,13 @@ class SaveLoadMixin(PushToHubMixin):
# get absolute path of saved_directory,
def create_yml(self, save_dir, config, list_tags=None, dict_tags=None):
def create_yml(self, save_dir, config, list_tags=None, dict_tags=None,other_tags=None):
f = open("{}/config.yml".format(save_dir), 'w')
config_dict = vars(config)
config_dict['dict_tags'] = dict_tags if dict_tags is not None else {}
config_dict['list_tags'] = list_tags if list_tags is not None else []
if other_tags is not None:
config_dict.update(other_tags)
yaml.safe_dump(config_dict, f)
f.close()

View File

@ -3,6 +3,29 @@ import copy
import opendelta.utils.logging as logging
from opendelta.utils.visualization import Visualization
logger = logging.get_logger(__name__)
opt_mapping = {
"model.decoder.embed_tokens": {"__name__":"embeddings"},
"model.decoder.embed_positions": {"__name__":""},
"model.decoder.project_out": {"__name__":""},
"model.decoder.project_in": {"__name__":""},
"model.decoder": {"__name__":"decoder",
"layer": {"__name__":"block",
"$": {"__name__":"$",
"self_attn": {"__name__":"attn",
"q_proj": {"__name__":"q"},
"k_proj": {"__name__":"k"},
"v_proj": {"__name__":"v"},
"out_proj": {"__name__":"proj"}
},
"self_attn_layer_norm": {"__name__":"layer_norm"},
"fc1": {"__name__":"ff.w1"},
"fc2": {"__name__":"ff.w2"},
"final_layer_norm": {"__name__":"layer_norm"},
}
}
}
}
t5_mapping = {
"shared": {"__name__":"embeddings"},
"encoder": {"__name__":"encoder",
@ -269,6 +292,14 @@ def mapping_for_ConditionalGeneration(mapping, type):
raise NotImplementedError
return mapping
def mapping_for_CausalLM(mapping, type):
mapping = copy.deepcopy(mapping)
if type == "opt":
mapping["lm_head"] = {"__name__":"lm_head.proj"}
else:
raise NotImplementedError
return mapping
class _LazyLoading(OrderedDict):
def __init__(self, mapping):
self._mapping_string = mapping
@ -298,7 +329,9 @@ class CommonStructureMap(object):
"BertForMaskedLM": "bert_mapping",
"BertForSequenceClassification": """mapping_for_SequenceClassification(bert_mapping, "bert")""",
"T5ForConditionalGeneration": """mapping_for_ConditionalGeneration(t5_mapping, "t5")""",
"DebertaV2ForSequenceClassification": """mapping_for_SequenceClassification(debertav2_mapping, "deberta")"""
"DebertaV2ForSequenceClassification": """mapping_for_SequenceClassification(debertav2_mapping, "deberta")""",
"CLIPModel":"""""",
"OPTForCausalLM":"""mapping_for_CausalLM(opt_mapping,"opt")"""
})
SpecialModelInverseMaps = {