This repository was archived by the owner on Sep 10, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +6
-33
lines changed Expand file tree Collapse file tree 5 files changed +6
-33
lines changed Original file line number Diff line number Diff line change @@ -80,12 +80,6 @@ def _add_arguments_common(parser):
80
80
help = "Model name for well-known models" ,
81
81
)
82
82
83
-
84
- def add_arguments (parser ):
85
- # TODO: Refactor this so that only common options are here
86
- # and command-specific options are inside individual
87
- # add_arguments_for_generate, add_arguments_for_export etc.
88
-
89
83
parser .add_argument (
90
84
"--chat" ,
91
85
action = "store_true" ,
@@ -301,10 +295,10 @@ def add_arguments(parser):
301
295
302
296
303
297
def arg_init (args ):
304
- if Path (args .quantize ).is_file ():
298
+ if hasattr ( args , 'quantize' ) and Path (args .quantize ).is_file ():
305
299
with open (args .quantize , "r" ) as f :
306
300
args .quantize = json .loads (f .read ())
307
301
308
- if args .seed :
302
+ if hasattr ( args , 'seed' ) and args .seed :
309
303
torch .manual_seed (args .seed )
310
304
return args
Original file line number Diff line number Diff line change 20
20
21
21
from build .model import Transformer
22
22
from build .utils import set_precision
23
- from cli import add_arguments , add_arguments_for_eval , arg_init
23
+ from cli import add_arguments_for_eval , arg_init
24
24
from generate import encode_tokens , model_forward
25
25
26
26
torch ._dynamo .config .automatic_dynamic_shapes = True
@@ -289,7 +289,6 @@ def main(args) -> None:
289
289
290
290
if __name__ == "__main__" :
291
291
parser = argparse .ArgumentParser (description = "torchchat eval CLI" )
292
- add_arguments (parser )
293
292
add_arguments_for_eval (parser )
294
293
args = parser .parse_args ()
295
294
args = arg_init (args )
Original file line number Diff line number Diff line change 19
19
)
20
20
21
21
from build .utils import set_backend , set_precision
22
- from cli import add_arguments , add_arguments_for_export , arg_init , check_args
22
+ from cli import add_arguments_for_export , arg_init , check_args
23
23
from export_aoti import export_model as export_model_aoti
24
24
25
25
try :
@@ -104,7 +104,6 @@ def main(args):
104
104
105
105
if __name__ == "__main__" :
106
106
parser = argparse .ArgumentParser (description = "torchchat export CLI" )
107
- add_arguments (parser )
108
107
add_arguments_for_export (parser )
109
108
args = parser .parse_args ()
110
109
check_args (args , "export" )
Original file line number Diff line number Diff line change 25
25
)
26
26
from build .model import Transformer
27
27
from build .utils import device_sync , set_precision
28
- from cli import add_arguments , add_arguments_for_generate , arg_init , check_args
28
+ from cli import add_arguments_for_generate , arg_init , check_args
29
29
30
30
logger = logging .getLogger (__name__ )
31
31
@@ -767,7 +767,6 @@ def main(args):
767
767
768
768
if __name__ == "__main__" :
769
769
parser = argparse .ArgumentParser (description = "torchchat generate CLI" )
770
- add_arguments (parser )
771
770
add_arguments_for_generate (parser )
772
771
args = parser .parse_args ()
773
772
check_args (args , "generate" )
Original file line number Diff line number Diff line change 10
10
import sys
11
11
12
12
from cli import (
13
- add_arguments ,
14
13
add_arguments_for_browser ,
15
14
add_arguments_for_chat ,
16
15
add_arguments_for_download ,
30
29
# Initialize the top-level parser
31
30
parser = argparse .ArgumentParser (
32
31
prog = "torchchat" ,
33
- description = "Welcome to the torchchat CLI!" ,
34
32
add_help = True ,
35
33
)
36
- # Default command is to print help
37
- parser .set_defaults (func = parser .print_help ())
38
34
39
- add_arguments (parser )
40
35
subparsers = parser .add_subparsers (
41
36
dest = "command" ,
42
37
help = "The specific command to run" ,
43
38
)
39
+ subparsers .required = True
44
40
45
41
parser_chat = subparsers .add_parser (
46
42
"chat" ,
90
86
)
91
87
add_arguments_for_remove (parser_remove )
92
88
93
- # Move all flags to the front of sys.argv since we don't
94
- # want to use the subparser syntax
95
- flag_args = []
96
- positional_args = []
97
- i = 1
98
- while i < len (sys .argv ):
99
- if sys .argv [i ].startswith ("-" ):
100
- flag_args += sys .argv [i : i + 2 ]
101
- i += 2
102
- else :
103
- positional_args .append (sys .argv [i ])
104
- i += 1
105
- sys .argv = sys .argv [:1 ] + flag_args + positional_args
106
-
107
89
# Now parse the arguments
108
90
args = parser .parse_args ()
109
91
args = arg_init (args )
You can’t perform that action at this time.
0 commit comments