Skip to content

Commit 19ed671

Browse files
zhangyimixyzhou-puck
authored andcommitted
add check before using cuda and change default config (PaddlePaddle#2726)
1 parent 460e543 commit 19ed671

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

PaddleNLP/similarity_net/config/cnn_pairwise.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"optimizer": {
1616
"class_name": "AdamOptimizer",
17-
"learning_rate": 0.001,
17+
"learning_rate": 0.2,
1818
"beta1": 0.9,
1919
"beta2": 0.999,
2020
"epsilon": 1e-08

PaddleNLP/similarity_net/run_classifier.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@
7373
"When task_mode is pairwise, lamda is the threshold for calculating the accuracy."
7474
)
7575

76-
parser.add_argument('--enable_ce', action='store_true', help='If set, run the task with continuous evaluation logs.')
76+
parser.add_argument(
77+
'--enable_ce',
78+
action='store_true',
79+
help='If set, run the task with continuous evaluation logs.')
7780

7881
args = parser.parse_args()
7982

@@ -280,9 +283,9 @@ def valid_and_test(program, feeder, reader, process, mode="test"):
280283
except:
281284
logging.info("ce info err!")
282285
print("kpis\teach_step_duration_%s_card%s\t%s" %
283-
(args.task_name, card_num, ce_time))
286+
(args.task_name, card_num, ce_time))
284287
print("kpis\ttrain_loss_%s_card%s\t%f" %
285-
(args.task_name, card_num, ce_loss))
288+
(args.task_name, card_num, ce_loss))
286289

287290
if args.do_test:
288291
if args.task_mode == "pairwise":
@@ -454,6 +457,15 @@ def main(conf_dict, args):
454457

455458
if __name__ == "__main__":
456459
utils.print_arguments(args)
460+
try:
461+
if fluid.is_compiled_with_cuda() != True and args.use_cuda == True:
462+
print(
463+
"\nYou can not set use_cuda = True in the model because you are using paddlepaddle-cpu.\nPlease: 1. Install paddlepaddle-gpu to run your models on GPU or 2. Set use_cuda = False to run models on CPU.\n"
464+
)
465+
466+
sys.exit(1)
467+
except Exception as e:
468+
pass
457469
utils.init_log("./log/TextSimilarityNet")
458470
conf_dict = config.SimNetConfig(args)
459471
main(conf_dict, args)

0 commit comments

Comments
 (0)