<commit_before>from .affine import Affine
from ... import describe
from ... import check
from ...describe import Dimension, Synapses, Biases
from ...check import has_shape


class ReLu(Affine):
    @check.arg(1, has_shape(('nB', 'nI')))
    def predict(self, input__BI):
        output__BO = Affine.predict(self, input__BI)
        output__BO = output__BO.copy()
        output__BO = self.ops.relu(output__BO, inplace=True)
        return output__BO

    @check.arg(1, has_shape(('nB', 'nI')))
    def begin_update(self, input__BI, drop=0.0):
        output__BO, finish_affine = Affine.begin_update(self, input__BI, drop=0.)
        output_copy = output__BO.copy()
        output_copy = self.ops.relu(output_copy, inplace=True)
        @check.arg(0, has_shape(('nB', 'nO')))
        def finish_update(gradient, sgd=None):
            gradient = gradient.copy()
            gradient = self.ops.backprop_relu(gradient, output_copy, inplace=True)
            return finish_affine(gradient, sgd)
        output__BO[:] = output_copy
        output__BO, bp_dropout = self.ops.dropout(output__BO, drop, inplace=True)
        return output__BO, bp_dropout(finish_update)<commit_msg>Clean up inplace ops in relu<commit_after>from .affine import Affine
from ... import describe
from ... import check
from ...describe import Dimension, Synapses, Biases
from ...check import has_shape


class ReLu(Affine):
    @check.arg(1, has_shape(('nB', 'nI')))
    def predict(self, input__BI):
        output__BO = Affine.predict(self, input__BI)
        output__BO = self.ops.relu(output__BO, inplace=False)
        return output__BO

    @check.arg(1, has_shape(('nB', 'nI')))
    def begin_update(self, input__BI, drop=0.0):
        output__BO, finish_affine = Affine.begin_update(self, input__BI, drop=0.)
        output__BO = self.ops.relu(output__BO)
        @check.arg(0, has_shape(('nB', 'nO')))
        def finish_update(gradient, sgd=None):
            gradient = self.ops.backprop_relu(gradient, output__BO)
            return finish_affine(gradient, sgd)
        dropped, bp_dropout = self.ops.dropout(output__BO, drop, inplace=False)
        return dropped, bp_dropout(finish_update)
{'fraction_non_alphanumeric': 0.125114995400184, 'fraction_numerical': 0.005519779208831647, 'mean_word_length': 3.3587174348697393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4528284', 'n_tokens_mistral': 741, 'n_tokens_neox': 722, 'n_words': 154}