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

Function train

modelzoo/dlrm/train.py:498–551  ·  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

496
497
498def train(sess_config,
499 input_hooks,
500 model,
501 data_init_op,
502 steps,
503 checkpoint_dir,
504 tf_config=None,
505 server=None):
506 model.is_training = True
507 hooks = []
508 hooks.extend(input_hooks)
509
510 scaffold = tf.train.Scaffold(
511 local_init_op=tf.group(tf.local_variables_initializer(), data_init_op),
512 saver=tf.train.Saver(max_to_keep=args.keep_checkpoint_max, sharded=True))
513
514 stop_hook = tf.train.StopAtStepHook(last_step=steps)
515 log_hook = tf.train.LoggingTensorHook(
516 {
517 'steps': model.global_step,
518 'loss': model.loss
519 }, every_n_iter=100)
520 hooks.append(stop_hook)
521 hooks.append(log_hook)
522 if args.timeline > 0:
523 hooks.append(
524 tf.train.ProfilerHook(save_steps=args.timeline,
525 output_dir=checkpoint_dir))
526 save_steps = args.save_steps if args.save_steps or args.no_eval else steps
527 '''
528 Incremental_Checkpoint
529 Please add `save_incremental_checkpoint_secs` in 'tf.train.MonitoredTrainingSession'
530 it's default to None, Incremental_save checkpoint time in seconds can be set
531 to use incremental checkpoint function, like `tf.train.MonitoredTrainingSession(
532 save_incremental_checkpoint_secs=args.incremental_ckpt)`
533 '''
534 if args.incremental_ckpt and not args.tf:
535 print("Incremental_Checkpoint is not really enabled.")
536 print("Please see the comments in the code.")
537 sys.exit()
538
539 with tf.train.MonitoredTrainingSession(
540 master=server.target if server else '',
541 is_chief=tf_config['is_chief'] if tf_config else True,
542 hooks=hooks,
543 scaffold=scaffold,
544 checkpoint_dir=checkpoint_dir,
545 save_checkpoint_steps=save_steps,
546 summary_dir=checkpoint_dir,
547 save_summaries_steps=args.save_steps,
548 config=sess_config) as sess:
549 while not sess.should_stop():
550 sess.run([model.loss, model.train_op])
551 print("Training completed.")
552
553
554def 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