MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / train

Function train

modelzoo/dssm/train.py:469–522  ·  view source on GitHub ↗
(sess_config,
          input_hooks,
          model,
          data_init_op,
          steps,
          checkpoint_dir,
          tf_config=None,
          server=None)

Source from the content-addressed store, hash-verified

467
468
469def train(sess_config,
470 input_hooks,
471 model,
472 data_init_op,
473 steps,
474 checkpoint_dir,
475 tf_config=None,
476 server=None):
477 model.is_training = True
478 hooks = []
479 hooks.extend(input_hooks)
480
481 scaffold = tf.train.Scaffold(
482 local_init_op=tf.group(tf.local_variables_initializer(), data_init_op),
483 saver=tf.train.Saver(max_to_keep=args.keep_checkpoint_max, sharded=True))
484
485 stop_hook = tf.train.StopAtStepHook(last_step=steps)
486 log_hook = tf.train.LoggingTensorHook(
487 {
488 'steps': model.global_step,
489 'loss': model.loss
490 }, every_n_iter=100)
491 hooks.append(stop_hook)
492 hooks.append(log_hook)
493 if args.timeline > 0:
494 hooks.append(
495 tf.train.ProfilerHook(save_steps=args.timeline,
496 output_dir=checkpoint_dir))
497 save_steps = args.save_steps if args.save_steps or args.no_eval else steps
498 '''
499 Incremental_Checkpoint
500 Please add `save_incremental_checkpoint_secs` in 'tf.train.MonitoredTrainingSession'
501 it's default to None, Incremental_save checkpoint time in seconds can be set
502 to use incremental checkpoint function, like `tf.train.MonitoredTrainingSession(
503 save_incremental_checkpoint_secs=args.incremental_ckpt)`
504 '''
505 if args.incremental_ckpt and not args.tf:
506 print("Incremental_Checkpoint is not really enabled.")
507 print("Please see the comments in the code.")
508 sys.exit()
509
510 with tf.train.MonitoredTrainingSession(
511 master=server.target if server else '',
512 is_chief=tf_config['is_chief'] if tf_config else True,
513 hooks=hooks,
514 scaffold=scaffold,
515 checkpoint_dir=checkpoint_dir,
516 save_checkpoint_steps=save_steps,
517 summary_dir=checkpoint_dir,
518 save_summaries_steps=args.save_steps,
519 config=sess_config) as sess:
520 while not sess.should_stop():
521 sess.run([model.loss, model.train_op])
522 print("Training completed.")
523
524
525def eval(sess_config, input_hooks, model, data_init_op, steps, checkpoint_dir):

Callers 1

mainFunction · 0.70

Calls 6

exitMethod · 0.80
extendMethod · 0.45
groupMethod · 0.45
appendMethod · 0.45
should_stopMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected