(self, backward_grads, data_loader: FTLDataLoader, epoch_idx, decay=False)
updating bottom nn model weights using backward gradients
updating bottom nn model weights using backward gradients
updating bottom nn model weights using backward gradients
def update_nn_weights(self, backward_grads, data_loader: FTLDataLoader, epoch_idx, decay=False):

        """
        updating bottom nn model weights using backward gradients
        """

        LOGGER.debug('updating grads at epoch {}'.format(epoch_idx))

        assert len(data_loader.x) == len(backward_grads)

        weight_grads = []
        for i in range(len(data_loader)):
            start, end = data_loader.get_batch_indexes(i)
            batch_x = data_loader.x[start: end]
            batch_grads = backward_grads[start: end]
            batch_weight_grads = self._get_mini_batch_gradient(batch_x, batch_grads)
            if len(weight_grads) == 0:
                weight_grads.extend(batch_weight_grads)
            else:
                for w, bw in zip(weight_grads, batch_weight_grads):
                    w += bw

        if decay:
            new_learning_rate = self.learning_rate_decay(self.learning_rate, epoch_idx)
            self.nn.set_learning_rate(new_learning_rate)
            LOGGER.debug('epoch {} optimizer details are {}'.format(epoch_idx, self.nn.export_optimizer_config()))

        self.nn.apply_gradients(weight_grads)
def update_nn_weights ( self , backward_grads , data_loader : FTLDataLoader , epoch_idx , decay = False ) : LOGGER . debug ( 'updating grads at epoch {}' . format ( epoch_idx ) ) assert len ( data_loader . x ) == len ( backward_grads ) weight_grads = [ ] for i in range ( len ( data_loader ) ) : start , end = data_loader . get_batch_indexes ( i ) batch_x = data_loader . x [ start : end ] batch_grads = backward_grads [ start : end ] batch_weight_grads = self . _get_mini_batch_gradient ( batch_x , batch_grads ) if len ( weight_grads ) == 0 : weight_grads . extend ( batch_weight_grads ) else : for w , bw in zip ( weight_grads , batch_weight_grads ) : w += bw if decay : new_learning_rate = self . learning_rate_decay ( self . learning_rate , epoch_idx ) self . nn . set_learning_rate ( new_learning_rate ) LOGGER . debug ( 'epoch {} optimizer details are {}' . format ( epoch_idx , self . nn . export_optimizer_config ( ) ) ) self . nn . apply_gradients ( weight_grads )