| | |
| | | from funasr.torch_utils.model_summary import model_summary |
| | | from funasr.torch_utils.pytorch_version import pytorch_cudnn_version |
| | | from funasr.torch_utils.set_all_random_seed import set_all_random_seed |
| | | from funasr.utils import config_argparse |
| | | from funasr.utils.nested_dict_action import NestedDictAction |
| | | from funasr.utils.prepare_data import prepare_data |
| | | from funasr.utils.types import str2bool |
| | | from funasr.utils.types import str_or_none |
| | |
| | | |
| | | |
| | | def get_parser(): |
| | | parser = config_argparse.ArgumentParser( |
| | | parser = argparse.ArgumentParser( |
| | | description="FunASR Common Training Parser", |
| | | ) |
| | | |
| | |
| | | default=False, |
| | | help="Whether to use the find_unused_parameters in " |
| | | "torch.nn.parallel.DistributedDataParallel ", |
| | | ) |
| | | parser.add_argument( |
| | | "--gpu_id", |
| | | type=int, |
| | | default=0, |
| | | help="local gpu id.", |
| | | ) |
| | | |
| | | # cudnn related |
| | |
| | | default=[], |
| | | ) |
| | | parser.add_argument( |
| | | "--train_shape_file", |
| | | type=str, action="append", |
| | | default=[], |
| | | ) |
| | | parser.add_argument( |
| | | "--valid_shape_file", |
| | | type=str, |
| | | action="append", |
| | | default=[], |
| | | ) |
| | | parser.add_argument( |
| | | "--use_preprocessor", |
| | | type=str2bool, |
| | | default=True, |
| | | help="Apply preprocessing to data or not", |
| | | ) |
| | | |
| | | # optimization related |
| | | parser.add_argument( |
| | | "--optim", |
| | | type=lambda x: x.lower(), |
| | | default="adam", |
| | | help="The optimizer type", |
| | | ) |
| | | parser.add_argument( |
| | | "--optim_conf", |
| | | action=NestedDictAction, |
| | | default=dict(), |
| | | help="The keyword arguments for optimizer", |
| | | ) |
| | | parser.add_argument( |
| | | "--scheduler", |
| | | type=lambda x: str_or_none(x.lower()), |
| | | default=None, |
| | | help="The lr scheduler type", |
| | | ) |
| | | parser.add_argument( |
| | | "--scheduler_conf", |
| | | action=NestedDictAction, |
| | | default=dict(), |
| | | help="The keyword arguments for lr scheduler", |
| | | ) |
| | | |
| | | # most task related |
| | |
| | | parser = get_parser() |
| | | args, extra_task_params = parser.parse_known_args() |
| | | if extra_task_params: |
| | | task_args = build_args(args, extra_task_params) |
| | | args = argparse.Namespace(**vars(args), **vars(task_args)) |
| | | args = build_args(args, parser, extra_task_params) |
| | | # args = argparse.Namespace(**vars(args), **vars(task_args)) |
| | | |
| | | # set random seed |
| | | set_all_random_seed(args.seed) |
| | |
| | | torch.backends.cudnn.deterministic = args.cudnn_deterministic |
| | | |
| | | # ddp init |
| | | os.environ['CUDA_VISIBLE_DEVICES'] = str(args.gpu_id) |
| | | args.distributed = args.dist_world_size > 1 |
| | | distributed_option = build_distributed(args) |
| | | |