I try to depoly my pytorch model with argparse module.
It seems that the argparse module declared in the app will replace the arguments of gunicorn.
And I have encountered such a problem like this:
usage: gunicorn [-h] [--mode MODE] [--batch_size BATCH_SIZE] [--warmup WARMUP]
[--early_stop EARLY_STOP] [--seed SEED] [--t_total] [--lr LR]
[--lr_decay_epochs LR_DECAY_EPOCHS]
[--lr_decay_rate LR_DECAY_RATE]
[--weight_decay_rate WEIGHT_DECAY_RATE] [--bert_lr BERT_LR]
[--num_epochs NUM_EPOCHS] [--model_dir MODEL_DIR]
[--model_path MODEL_PATH] [--num_workers NUM_WORKERS]
[--train_dataset TRAIN_DATASET] [--eval_dataset EVAL_DATASET]
[--test_dataset TEST_DATASET] [--bert_low_case BERT_LOW_CASE]
[--bert_type BERT_TYPE] [--bert_hidden_size BERT_HIDDEN_SIZE]
[--bert_dropout BERT_DROPOUT]
[--bert_mention_max_len BERT_MENTION_MAX_LEN]
[--bert_max_len BERT_MAX_LEN]
[--bert_char_max_len BERT_CHAR_MAX_LEN]
[--bert_entity_threshold BERT_ENTITY_THRESHOLD]
[--bert_freeze] [--bert_threshold BERT_THRESHOLD]
[--bert_adam] [--enhance_mention] [--interaction]
[--context_dropout CONTEXT_DROPOUT]
[--mention_dropout MENTION_DROPOUT]
[--rnn_hidden_size RNN_HIDDEN_SIZE]
[--rnn_num_layers RNN_NUM_LAYERS] [--rnn_dropout RNN_DROPOUT]
[--rnn_num_dirs RNN_NUM_DIRS]
[--cnn_embedding_dim CNN_EMBEDDING_DIM]
[--cnn_output_dim CNN_OUTPUT_DIM] [--cnn_filters CNN_FILTERS]
[--hierarchy_alpha HIERARCHY_ALPHA]
gunicorn: error: unrecognized arguments: -w 1 -b 0.0.0.0:3101 --reload -t 500 api:app
The hints in the above section are the model parameters in the app.
Thanks~
Can you show how you are creating your application and parsing the CLI with argparse
?
Gunicorn calls parse_args
on its own instance of argparse
. You can implement a custom application that does something else, or you can ensure to mutate sys.argv
, or pass your own arguments to parse_args
, if you call it after Gunicorn starts.
https://docs.python.org/3/library/argparse.html#the-parse-args-method
Can you show how you are creating your application and parsing the CLI with
argparse
?Gunicorn calls
parse_args
on its own instance ofargparse
. You can implement a custom application that does something else, or you can ensure to mutatesys.argv
, or pass your own arguments toparse_args
, if you call it after Gunicorn starts.https://docs.python.org/3/library/argparse.html#the-parse-args-method
Thanks for your reply, I found if I use argparse module in my APP like args = parser.parse_args(sys.argv)
, the arguments of gunicorn may not work.
I try to replace it with args, unknown = parser.parse_known_args()
, everything goes well.
Thanks ~
Can the issue be closed, then? Do you need help to parse your own command line switches and the gunicorn switches together?
Thanks again!
Most helpful comment
Thanks for your reply, I found if I use argparse module in my APP like
args = parser.parse_args(sys.argv)
, the arguments of gunicorn may not work.I try to replace it with
args, unknown = parser.parse_known_args()
, everything goes well.Thanks ~