Hi,  I implemented my custom function and use the gradcheck tool in pytorch to check whether there are implementation issues. While it did not pass the gradient checking because of some loss of precision.

I set eps=1e-6, atol=1e-4. But I did not find the issue of my implementation.
Suggestions would be appreciated.
Edit: I post my code scripts here:
    @staticmethod
	def forward(ctx, input, weight, bias=None):
		ctx.save_for_backward(input, weight, bias)
		ctx.num = input.size(0)
		output = input.clone().zero_()
		for i in range(ctx.num):
			output[i,:] = torch.mul(input[i,:], weight)

		if bias is not None:
			output += bias

		return output
	@staticmethod	
	def backward(ctx, grad_output):
		input, weight, bias = ctx.saved_variables

		grad_input = grad_weight = grad_bias = None
			
		if ctx.needs_input_grad[0]:
			grad_input = grad_output.clone().zero_()
			for i in range(ctx.num):
				grad_input[i,:] = torch.mul(grad_output[i,:], weight)

		if ctx.needs_input_grad[1]:
			grad_weight = weight.clone().zero_()
			for i in range(ctx.num):
				grad_weight += torch.mul(grad_output[i,:], weight)

		if bias is not None and ctx.needs_input_grad[2]:
			grad_bias = torch.sum(grad_output, 0)

		if bias is not None:
			return grad_input, grad_weight, grad_bias
		else:
			return grad_input, grad_weight