Context manager wrapping the training loop, updates step counters.
427974
def training_loop(self):
    """"""
    if not self.restarting:
      self._write_counters(self._local_step_at_start, self._global_step)

    tf.logging.info(
        "Training %s up to %d, %d to go", self.model_mode,
        self.target_local_step, self.steps_to_go
    )

    yield

    self._write_counters(self.target_local_step, -1)
560101
def run_loop(name, train_input_fn, eval_input_fn, model_column_fn,
             build_estimator_fn, flags_obj, tensors_to_log, early_stop=False):
  """"""
  model_helpers.apply_clean(flags.FLAGS)
  model = build_estimator_fn(
      model_dir=flags_obj.model_dir, model_type=flags_obj.model_type,
      model_column_fn=model_column_fn,
      inter_op=flags_obj.inter_op_parallelism_threads,
      intra_op=flags_obj.intra_op_parallelism_threads)

  run_params = {
      'batch_size': flags_obj.batch_size,
      'train_epochs': flags_obj.train_epochs,
      'model_type': flags_obj.model_type,
  }

  benchmark_logger = logger.get_benchmark_logger()
  benchmark_logger.log_run_info('wide_deep', name, run_params,
                                test_id=flags_obj.benchmark_test_id)

  loss_prefix = LOSS_PREFIX.get(flags_obj.model_type, '')
  tensors_to_log = {k: v.format(loss_prefix=loss_prefix)
                    for k, v in tensors_to_log.items()}
  train_hooks = hooks_helper.get_train_hooks(
      flags_obj.hooks, model_dir=flags_obj.model_dir,
      batch_size=flags_obj.batch_size, tensors_to_log=tensors_to_log)

  # Train and evaluate the model every `flags.epochs_between_evals` epochs.
  for n in range(flags_obj.train_epochs // flags_obj.epochs_between_evals):
    model.train(input_fn=train_input_fn, hooks=train_hooks)

    results = model.evaluate(input_fn=eval_input_fn)

    # Display evaluation metrics
    tf.logging.info('Results at epoch %d / %d',
                    (n + 1) * flags_obj.epochs_between_evals,
                    flags_obj.train_epochs)
    tf.logging.info('-' * 60)

    for key in sorted(results):
      tf.logging.info('%s: %s' % (key, results[key]))

    benchmark_logger.log_evaluation_result(results)

    if early_stop and model_helpers.past_stop_threshold(
        flags_obj.stop_threshold, results['accuracy']):
      break

  # Export the model
  if flags_obj.export_dir is not None:
    export_model(model, flags_obj.model_type, flags_obj.export_dir,
                 model_column_fn)
366294
private void updateInstances(List<InstanceContext> instances, final CountingCompletionHandler<Void> counter) {
    for (final InstanceContext instance : instances) {
      data.put(instance.address(), Contexts.serialize(instance).encode(), new Handler<AsyncResult<String>>() {
        @Override
        public void handle(AsyncResult<String> result) {
          if (result.failed()) {
            counter.fail(result.cause());
          } else {
            counter.succeed();
          }
        }
      });
    }
  }
1169520
def run_training(self, trace: Optional[TrainingTrace]=None) -> None:
        
        for stream_name in [self._train_stream_name] + self._extra_streams:
            self.get_stream(stream_name)

        def training():
            logging.debug('Training started')
            self._epochs_done = 0

            # Zeroth epoch: after_epoch
            if not self._skip_zeroth_epoch:
                logging.info('Evaluating 0th epoch')
                self._run_zeroth_epoch([self._train_stream_name] + self._extra_streams)
                logging.info('0th epoch done\n\n')

            # Training loop: after_epoch, after_epoch_profile
            while True:
                epoch_id = self._epochs_done + 1
                logging.info('Training epoch %s', epoch_id)
                self._epoch_profile.clear()
                epoch_data = self._create_epoch_data()

                with self.get_stream(self._train_stream_name) as stream:
                    self.train_by_stream(stream)

                for stream_name in self._extra_streams:
                    with self.get_stream(stream_name) as stream:
                        self.evaluate_stream(stream)

                with Timer('after_epoch_hooks', self._epoch_profile):
                    for hook in self._hooks:
                        hook.after_epoch(epoch_id=epoch_id, epoch_data=epoch_data)

                for hook in self._hooks:
                    hook.after_epoch_profile(epoch_id=epoch_id, profile=self._epoch_profile,
                                             train_stream_name=self._train_stream_name,
                                             extra_streams=self._extra_streams)
                self._epochs_done = epoch_id
                if trace is not None:
                    trace[TrainingTraceKeys.EPOCHS_DONE] = self._epochs_done
                logging.info('Epoch %s done\n\n', epoch_id)

        self._try_run(training)
570454
def on_batch_end(self, train, **kwargs):
        ""
        if train: self.stats.append(self.hooks.stored)
175374
def _pre_train(self,
                   stop_param_updates,
                   num_epochs,
                   updates_epoch):
        """"""
        # Calculate the total number of updates given early stopping.
        updates = {k: stop_param_updates.get(k, num_epochs) * updates_epoch
                   for k, v in self.params.items()}

        # Calculate the value of a single step given the number of allowed
        # updates.
        single_steps = {k: np.exp(-((1.0 - (1.0 / v)))
                        * self.params[k]['factor'])
                        for k, v in updates.items()}

        # Calculate the factor given the true factor and the value of a
        # single step.
        constants = {k: np.exp(-self.params[k]['factor']) / v
                     for k, v in single_steps.items()}

        return constants
1136819
function updateTrack( newList, oldList, steps,  rawNewValue, oldKeyMap ){
    
    for(var i =0, slen = steps.length; i < slen ;i++){
      var step = steps[i];
      switch( step.mode){
        case 0 : //remove
          removeRange(step.index, step.len, group.children, oldKeyMap);
          break;
        case 1 : //insert
          addRange(step.index, step.index + step.len, newList, rawNewValue, oldKeyMap )
          break;
      }
    }     
    var children = group.children;
    for(var j=1, len = children.length; j < len; j++){
      var child = children[j];
      if( child ){
        child.data[variable] = newList[j-1];
        child.data[indexName] = j-1
      }
    }

    
  }
1162067
def on_step_end(self, step, logs):
        
        if self.info_names is None:
            self.info_names = logs['info'].keys()
        values = [('reward', logs['reward'])]
        if KERAS_VERSION > '2.1.3':
            self.progbar.update((self.step % self.interval) + 1, values=values)
        else:
            self.progbar.update((self.step % self.interval) + 1, values=values, force=True)
        self.step += 1
        self.metrics.append(logs['metrics'])
        if len(self.info_names) > 0:
            self.infos.append([logs['info'][k] for k in self.info_names])
325566
def on_step_end(self, **kwargs):
        ""
        if not self.learn.gan_trainer.gen_mode: self.learn.opt.lr /= self.mult_lr
716293
def _run_train_step(self, train_set):
        
        np.random.shuffle(train_set)

        batches = [_ for _ in utilities.gen_batches(train_set,
                                                    self.batch_size)]
        updates = [self.w_upd8, self.bh_upd8, self.bv_upd8]

        for batch in batches:
            self.tf_session.run(updates,
                                feed_dict=self._create_feed_dict(batch))
194651
def training_status_renderer_context(exercise_names: List[str], renderman: RenderingManager):
    
    renderer = TrainingStatusRenderer(exercise_names, renderman)
    try:
        yield renderer
    finally:
        renderer.clear_screen()
675753
private void transitionToFinalBatchStatus() {
		BatchStatus currentBatchStatus = stepContext.getBatchStatus();
		if (currentBatchStatus.equals(BatchStatus.STARTED)) {
			updateBatchStatus(BatchStatus.COMPLETED);
		} else if (currentBatchStatus.equals(BatchStatus.STOPPING)) {
			updateBatchStatus(BatchStatus.STOPPED);
		} else if (currentBatchStatus.equals(BatchStatus.FAILED)) {
			updateBatchStatus(BatchStatus.FAILED);           // Should have already been done but maybe better for possible code refactoring to have it here.
		} else {
			throw new IllegalStateException("Step batch status should not be in a " + currentBatchStatus.name() + " state");
		}
	}
655990
def train(input_dir, batch_size, max_steps, output_dir, checkpoint):
    """"""
    from google.datalab.utils import LambdaJob

    if checkpoint is None:
      checkpoint = _util._DEFAULT_CHECKPOINT_GSURL

    labels = _util.get_labels(input_dir)
    model = _model.Model(labels, 0.5, checkpoint)
    task_data = {'type': 'master', 'index': 0}
    task = type('TaskSpec', (object,), task_data)
    job = LambdaJob(lambda: _trainer.Trainer(input_dir, batch_size, max_steps, output_dir,
                                             model, None, task).run_training(), 'training')
    return job
1253732
function () {
    var callbacks = this._callbacks;
    var contexts = this._contexts;
    if (callbacks) {
      !(callbacks.length === contexts.length) ? "development" !== 'production' ? invariant(false, 'Mismatched list of contexts in callback queue') : _prodInvariant('24') : void 0;
      this._callbacks = null;
      this._contexts = null;
      for (var i = 0; i < callbacks.length; i++) {
        callbacks[i].call(contexts[i]);
      }
      callbacks.length = 0;
      contexts.length = 0;
    }
  }
684153
@Override
    public void process(Step context) {
        Iterator<Attachment> iterator = context.getAttachments().listIterator();
        while (iterator.hasNext()) {
            Attachment attachment = iterator.next();
            if (pattern.matcher(attachment.getSource()).matches()) {
                deleteAttachment(attachment);
                iterator.remove();
            }
        }

        for (Step step : context.getSteps()) {
            process(step);
        }
    }
547775
def learn(self, steps=1, **kwargs):
        
        # TODO add some housekeeping
        for i in range(steps):
            self.step(**kwargs)
676750
private void updateContext(Container c ,int maxCtx, int ctxSteps, boolean keepCustomValues)
  {

    if(!keepCustomValues)
    {
      c.removeAllItems();
    }
    
    for (Integer i : PREDEFINED_CONTEXTS)
    {
      if (i < maxCtx)
      {
        c.addItem(i);
      }
    }

    for (int step = ctxSteps; step < maxCtx; step += ctxSteps)
    {
      c.addItem(step);
    }

    c.addItem(maxCtx);

  }