The entry point of running LMDeploy CLI.
()
| 8 | |
| 9 | |
| 10 | def run(): |
| 11 | """The entry point of running LMDeploy CLI.""" |
| 12 | args = sys.argv[1:] |
| 13 | CLI.add_parsers() |
| 14 | SubCliServe.add_parsers() |
| 15 | SubCliLite.add_parsers() |
| 16 | parser = CLI.parser |
| 17 | args = parser.parse_args() |
| 18 | |
| 19 | if hasattr(args, 'model_name'): |
| 20 | # if `model_name` is not specified, use the model_path instead. The |
| 21 | # 'model_path' could be a a local path, or a repo id from hub |
| 22 | args.model_name = args.model_name if args.model_name else \ |
| 23 | args.model_path |
| 24 | |
| 25 | if 'run' in dir(args): |
| 26 | from lmdeploy.utils import get_model |
| 27 | model_path = getattr(args, 'model_path', None) |
| 28 | revision = getattr(args, 'revision', None) |
| 29 | download_dir = getattr(args, 'download_dir', None) |
| 30 | if model_path is not None and not os.path.exists(args.model_path): |
| 31 | args.model_path = get_model(args.model_path, download_dir=download_dir, revision=revision) |
| 32 | model_path_or_server = getattr(args, 'model_path_or_server', None) |
| 33 | if model_path_or_server is not None and (':' not in model_path_or_server |
| 34 | and not os.path.exists(model_path_or_server)): |
| 35 | args.model_path_or_server = get_model(args.model_path_or_server, |
| 36 | download_dir=download_dir, |
| 37 | revision=revision) |
| 38 | |
| 39 | args.run(args) |
| 40 | else: |
| 41 | try: |
| 42 | args.print_help() |
| 43 | except AttributeError: |
| 44 | command = args.command |
| 45 | if command == 'serve': |
| 46 | SubCliServe.parser.print_help() |
| 47 | elif command == 'lite': |
| 48 | SubCliLite.parser.print_help() |
| 49 | else: |
| 50 | parser.print_help() |
no test coverage detected