[to #42322933] Fix bug in UT daily

1. Fix bugs in daily test
2. Fix a bug that the updating of lr is before the first time of updating of optimizer
    TODO this will still cause warnings when GA is above 1
3. Remove the judgement of mode in text-classification's preprocessor to fit the base trainer(Bug)
     Update some regression bins to fit the preprocessor
4. Update the regression tool to let outer code modify atol and rtol
5. Add the default metric for text-classification task
6. Remove the useless ckpt conversion method in bert to avoid the requirement of tf when loading modeling_bert
        Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10430764
This commit is contained in:
yuze.zyz
2022-10-20 15:29:34 +08:00
parent 1483c64638
commit acba1786b0
13 changed files with 124 additions and 135 deletions

View File

@@ -16,7 +16,8 @@ from modelscope.trainers.optimizer.child_tuning_adamw_optimizer import \
calculate_fisher
from modelscope.utils.constant import ModelFile, Tasks
from modelscope.utils.data_utils import to_device
from modelscope.utils.regress_test_utils import MsRegressTool
from modelscope.utils.regress_test_utils import (MsRegressTool,
compare_arguments_nested)
from modelscope.utils.test_utils import test_level
@@ -41,6 +42,33 @@ class TestFinetuneSequenceClassification(unittest.TestCase):
def test_trainer_repeatable(self):
import torch # noqa
def compare_fn(value1, value2, key, type):
# Ignore the differences between optimizers of two torch versions
if type != 'optimizer':
return None
match = (value1['type'] == value2['type'])
shared_defaults = set(value1['defaults'].keys()).intersection(
set(value2['defaults'].keys()))
match = all([
compare_arguments_nested(f'Optimizer defaults {key} not match',
value1['defaults'][key],
value2['defaults'][key])
for key in shared_defaults
]) and match
match = (len(value1['state_dict']['param_groups']) == len(
value2['state_dict']['param_groups'])) and match
for group1, group2 in zip(value1['state_dict']['param_groups'],
value2['state_dict']['param_groups']):
shared_keys = set(group1.keys()).intersection(
set(group2.keys()))
match = all([
compare_arguments_nested(
f'Optimizer param_groups {key} not match', group1[key],
group2[key]) for key in shared_keys
]) and match
return match
def cfg_modify_fn(cfg):
cfg.task = 'nli'
cfg['preprocessor'] = {'type': 'nli-tokenizer'}
@@ -98,7 +126,8 @@ class TestFinetuneSequenceClassification(unittest.TestCase):
name=Trainers.nlp_base_trainer, default_args=kwargs)
with self.regress_tool.monitor_ms_train(
trainer, 'sbert-base-tnews', level='strict'):
trainer, 'sbert-base-tnews', level='strict',
compare_fn=compare_fn):
trainer.train()
def finetune(self,