Save the model every ``n_epochs`` epoch.

        :param epoch_id: number of the processed epoch
422420
def _after_n_epoch(self, epoch_id: int, **_) -> None:
        
        SaveEvery.save_model(model=self._model, name_suffix=str(epoch_id), on_failure=self._on_save_failure)
459342
def on_epoch_end(self, pbar, epoch, last_metrics, **kwargs):
        ""
        if not hasattr(self, 'last_gen') or not self.show_img: return
        data = self.learn.data
        img = self.last_gen[0]
        norm = getattr(data,'norm',False)
        if norm and norm.keywords.get('do_y',False): img = data.denorm(img)
        img = data.train_ds.y.reconstruct(img)
        self.imgs.append(img)
        self.titles.append(f'Epoch {epoch}')
        pbar.show_imgs(self.imgs, self.titles)
        return add_metrics(last_metrics, [getattr(self.smoothenerG,'smooth',None),getattr(self.smoothenerC,'smooth',None)])
635516
def on_epoch_end(self, epoch, logs={}):
        '''
        
        '''
        LOG.debug(logs)
        nni.report_intermediate_result(logs["val_acc"])
1276984
def save!(&block)
      fail StandardError, 'Cannot re-save a flow' if id
      self.id = SecureRandom.uuid
      record_id = redis_id + ':definition'
      self.created_at = Time.now.to_f

      # Actually save the record:
      redis.set record_id, serialize

      # Transition into the first phase:
      add_transition to: current_phase, timestamp: Time.now.utc.to_f

      # Add our id to the list of active flows:
      redis.sadd 'distribot.flows.active', id
      redis.incr('distribot.flows.running')

      # Announce our arrival to the rest of the system:
      Distribot.publish! 'distribot.flow.created', flow_id: id

      wait_for_flow_to_finish(block) if block_given?
      self
    end
1014596
def epoch_info(self, training_info: TrainingInfo, global_idx: int, local_idx: int) -> EpochInfo:
        
        return EpochInfo(
            training_info=training_info,
            global_epoch_idx=global_idx,
            local_epoch_idx=local_idx,
            batches_per_epoch=self._source.train_iterations_per_epoch(),
            optimizer=self._optimizer_instance
        )
1279217
def execute_epoch(self, epoch_info, learner):
        
        for param_group in epoch_info.optimizer.param_groups:
            param_group['lr'] = self.lr

        epoch_result = learner.run_epoch(epoch_info, self._source)

        return epoch_result
1296352
def save
      # If we have an id, just update our fields.
      return update! if id

      from_response client.post("/webhooks", {
        description: description,
        idModel: id_model,
        callbackURL: callback_url
      })
    end
625933
def on_epoch_end(self, epoch, logs=None):
        
        if logs is None:
            logs = dict()
        logger.debug(logs)
        nni.report_intermediate_result(logs["val_acc"])
526393
def create_epochs(self, epoch_length=30, first_second=None):
        
        lg.info('creating epochs of length ' + str(epoch_length))
        if first_second is None:
            first_second = self.first_second
        last_sec = ceil((self.last_second - first_second) /
                        epoch_length) * epoch_length

        stages = self.rater.find('stages')
        for epoch_beg in range(first_second, last_sec, epoch_length):
            epoch = SubElement(stages, 'epoch')

            start_time = SubElement(epoch, 'epoch_start')
            start_time.text = str(epoch_beg)

            end_time = SubElement(epoch, 'epoch_end')
            end_time.text = str(epoch_beg + epoch_length)

            stage = SubElement(epoch, 'stage')
            stage.text = 'Unknown'

            quality = SubElement(epoch, 'quality')
            quality.text = 'Good'
1132951
def epoch(ctx, datetime):
    
    return conversions.to_decimal(str(conversions.to_datetime(datetime, ctx).timestamp()), ctx)
111276
def epoch_info(self, training_info: TrainingInfo, global_idx: int, local_idx: int) -> EpochInfo:
        
        return EpochInfo(training_info, global_epoch_idx=global_idx, local_epoch_idx=local_idx, batches_per_epoch=0)
73172
def on_epoch_end(self):
        
        self.freeze_epoch_result()

        for callback in self.callbacks:
            callback.on_epoch_end(self)

        self.training_info.history.add(self.result)
867206
def load_model_by_id(self, model_id):
        

        with open(os.path.join(self.path, str(model_id) + ".json")) as fin:
            json_str = fin.read().replace("\n", "")

        load_model = json_to_graph(json_str)
        return load_model
256166
def generate_parameters(self, parameter_id):
        
        if not self.history:
            self.init_search()

        new_father_id = None
        generated_graph = None
        if not self.training_queue:
            new_father_id, generated_graph = self.generate()
            new_model_id = self.model_count
            self.model_count += 1
            self.training_queue.append((generated_graph, new_father_id, new_model_id))
            self.descriptors.append(generated_graph.extract_descriptor())

        graph, father_id, model_id = self.training_queue.pop(0)

        # from graph to json
        json_model_path = os.path.join(self.path, str(model_id) + ".json")
        json_out = graph_to_json(graph, json_model_path)
        self.total_data[parameter_id] = (json_out, father_id, model_id)

        return json_out
273916
def save_record(self, agent_id, t_step, key, value):
        '''
        
        '''
        value = self.convert(key, value)
        self._tups.append(Record(agent_id=agent_id,
                                 t_step=t_step,
                                 key=key,
                                 value=value))
        if len(self._tups) > 100:
            self.flush_cache()
933373
def save(self, identifier=None, is_best=False, save_all=False):
        

        def write_checkpoint(state, filename):
            filename = os.path.join(self.save_path, filename)
            logging.info(f'Saving model to {filename}')
            torch.save(state, filename)

        if self.distributed:
            model_state = self.model.module.state_dict()
        else:
            model_state = self.model.state_dict()

        state = {
            'epoch': self.epoch,
            'state_dict': model_state,
            'optimizer': self.optimizer.state_dict(),
            'scheduler': self.scheduler.state_dict(),
            'loss': getattr(self, 'loss', None),
        }
        state = dict(list(state.items()) + list(self.save_info.items()))

        if identifier is not None:
            filename = self.checkpoint_filename % identifier
            write_checkpoint(state, filename)

        if is_best:
            filename = 'model_best.pth'
            write_checkpoint(state, filename)

        if save_all:
            filename = f'checkpoint_epoch_{self.epoch:03d}.pth'
            write_checkpoint(state, filename)
619982
def save_models(self, models_file):
        
        if self.model_parameters_iterations is None:
            raise ValueError("No iterations have been carried out yet and hence no iterations of the BO can be saved")

        iterations = np.array(range(1,self.model_parameters_iterations.shape[0]+1))[:,None]
        results = np.hstack((iterations,self.model_parameters_iterations))
        header = ['Iteration'] + self.model.get_model_parameters_names()

        data = [header] + results.tolist()
        self._write_csv(models_file, data)