<commit_before>local TemporalConvolution, parent = torch.class('nn.TemporalConvolution', 'nn.Module')

function TemporalConvolution:__init(inputFrameSize, outputFrameSize, kW, dW)
   parent.__init(self)

   dW = dW or 1

   self.inputFrameSize = inputFrameSize
   self.outputFrameSize = outputFrameSize
   self.kW = kW
   self.dW = dW

   self.weight = torch.Tensor(outputFrameSize, inputFrameSize*kW)
   self.bias = torch.Tensor(outputFrameSize)
   self.gradWeight = torch.Tensor(outputFrameSize, inputFrameSize*kW)
   self.gradBias = torch.Tensor(outputFrameSize)
   
   self:reset()
end

function TemporalConvolution:reset(stdv)
   if stdv then
      stdv = stdv * math.sqrt(3)
   else
      stdv = 1/math.sqrt(self.kW*self.inputFrameSize)
   end
   self.weight:apply(function()
                        return random.uniform(-stdv, stdv)
                     end)
   self.bias:apply(function()
                      return random.uniform(-stdv, stdv)
                   end)   
end

function TemporalConvolution:forward(input)
   return input.nn.TemporalConvolution_forward(self, input)
end

function TemporalConvolution:backward(input, gradOutput)
   if self.gradInput then
      return input.nn.TemporalConvolution_backward(self, input, gradOutput)
   end
end

function TemporalConvolution:accGradParameters(input, gradOutput, scale)
   scale = scale or 1
   input.nn.TemporalConvolution_accGradParameters(self, input, gradOutput, scale)
end

-- function TemporalConvolution:accUpdateGradParameters(input, gradOutput, lr)
--    print('using slow version')
--    self:zeroGradParameters()
--    self:accGradParameters(input, gradOutput)
--    self:updateParameters(lr)
-- end<commit_msg>faster shared TemporalConvolution<commit_after>local TemporalConvolution, parent = torch.class('nn.TemporalConvolution', 'nn.Module')

function TemporalConvolution:__init(inputFrameSize, outputFrameSize, kW, dW)
   parent.__init(self)

   dW = dW or 1

   self.inputFrameSize = inputFrameSize
   self.outputFrameSize = outputFrameSize
   self.kW = kW
   self.dW = dW

   self.weight = torch.Tensor(outputFrameSize, inputFrameSize*kW)
   self.bias = torch.Tensor(outputFrameSize)
   self.gradWeight = torch.Tensor(outputFrameSize, inputFrameSize*kW)
   self.gradBias = torch.Tensor(outputFrameSize)
   
   self:reset()
end

function TemporalConvolution:reset(stdv)
   if stdv then
      stdv = stdv * math.sqrt(3)
   else
      stdv = 1/math.sqrt(self.kW*self.inputFrameSize)
   end
   self.weight:apply(function()
                        return random.uniform(-stdv, stdv)
                     end)
   self.bias:apply(function()
                      return random.uniform(-stdv, stdv)
                   end)   
end

function TemporalConvolution:forward(input)
   return input.nn.TemporalConvolution_forward(self, input)
end

function TemporalConvolution:backward(input, gradOutput)
   if self.gradInput then
      return input.nn.TemporalConvolution_backward(self, input, gradOutput)
   end
end

function TemporalConvolution:accGradParameters(input, gradOutput, scale)
   scale = scale or 1
   input.nn.TemporalConvolution_accGradParameters(self, input, gradOutput, scale)
end

-- we do not need to accumulate parameters when sharing
TemporalConvolution.sharedAccUpdateGradParameters = TemporalConvolution.accUpdateGradParameters
{'fraction_non_alphanumeric': 0.08910295003010235, 'fraction_numerical': 0.002408187838651415, 'mean_word_length': 3.7471428571428573, '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': '652378', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1005, 'n_words': 202}