hnluo
2023-06-29 c2dee5e3c29eba79e591d9e9caebaef15ea4e56b
funasr/bin/train.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
#  MIT License  (https://opensource.org/licenses/MIT)
import argparse
import logging
@@ -272,8 +274,8 @@
    parser.add_argument(
        "--init_param",
        type=str,
        action="append",
        default=[],
        nargs="*",
        help="Specify the file path used for initialization of parameters. "
             "The format is '<file_path>:<src_key>:<dst_key>:<exclude_keys>', "
             "where file_path is the model file path, "
@@ -299,7 +301,7 @@
        "--freeze_param",
        type=str,
        default=[],
        nargs="*",
        action="append",
        help="Freeze parameters",
    )
@@ -333,6 +335,12 @@
        type=str,
        default="validation",
        help="dev dataset",
    )
    parser.add_argument(
        "--data_file_names",
        type=str,
        default="wav.scp,text",
        help="input data files",
    )
    parser.add_argument(
        "--speed_perturb",
@@ -513,6 +521,12 @@
        dtype=getattr(torch, args.train_dtype),
        device="cuda" if args.ngpu > 0 else "cpu",
    )
    for t in args.freeze_param:
        for k, p in model.named_parameters():
            if k.startswith(t + ".") or k == t:
                logging.info(f"Setting {k}.requires_grad = False")
                p.requires_grad = False
    optimizers = build_optimizer(args, model=model)
    schedulers = build_scheduler(args, optimizers)