Esempio n. 1
0
    def buildOutGrad(self, grad):
        if len(self.fwds) == 0:
            return grad

        grad = [[] for _ in range(
            len(self.data) if isinstance(self.data, list) else 1)]

        for node, slots in self.fwds:
            if slots is not None:
                for slot in slots:
                    grad[slot].append(node.grad[self.name][slot])

            else:
                for i, gr in enumerate(node.grad[self.name]):
                    grad[i].append(gr)

        for i, grads in enumerate(grad):
            if len(grads) > 1:
                gr = copy(None, grads[0])

                for j in range(1, len(grads)):
                    Blas.toVectorAddVector(gr.ravel(), grads[j].ravel())

            else:
                gr = grads[0]

            grad[i] = gr

        if len(grad) == 1:
            grad = grad[0]

        return grad
Esempio n. 2
0
	def updateGrad(self, grad):
		sections = [grad.shape[self.axis] // self.times] * self.times
		ingrad = Utils.split(grad, sections, axis=self.axis)

		for i in range(1, len(ingrad)):
			Blas.toVectorAddVector(ingrad[0].ravel(), ingrad[i].ravel())

		self.grad = ingrad[0]
Esempio n. 3
0
    def updateGrad(self, grad):
        firstgrad = grad[0]

        self.grad = gpuarray.empty(firstgrad.shape,
                                   dtype=firstgrad.dtype,
                                   allocator=memPool)
        self.grad.fill(0)

        for gr in grad:
            Blas.toVectorAddVector(self.grad.ravel(), gr.ravel())
Esempio n. 4
0
    def updateData(self, data):
        firstdata = data[0]

        self.data = gpuarray.empty(firstdata.shape,
                                   dtype=firstdata.dtype,
                                   allocator=memPool)
        self.data.fill(0)

        for dat in data:
            Blas.toVectorAddVector(self.data.ravel(), dat.ravel())
Esempio n. 5
0
 def updateParams(self, learnRate):
     for var in self.vars.values():
         Blas.toVectorAddVector(var.data.ravel(),
                                var.grad.ravel(),
                                alpha=learnRate)