Thank you!
I think you really hit the point, I reviewed my code just now and I find out that maybe my fault is:
I create two Parameters, weight and Bi_weight in one conv layer, and when forward propagate, the data value of “Bi_weight” is computed from data value of “weight” like:

self.Bi_weight.data[channal] = Binary(self.weight.data[channal] )

When I create the two Parameters, “require_grad” of the both are “True”, so when BP, weight’s grad is computed from Bi_weight’s, and the latter require gradient.
Am I right about the reason why my code doesn’t work? And I am still wondering if I want loss.backward() not to compute the grad of weight to fix the bug, and when updating the parameters by “optimizer.step()”, the weight would be updated with Bi_weight’s grad, what should I do? I have tried set weight.require_grad to be False and update with the code:

optimizer.zero_grad()
loss.backward()
for layer in model.modules():
if isinstance(layer, nn.Conv2d_Bi):
# print(“shot:”, layer.Bi_weight.requires_grad, layer.Bi_weight.grad)
layer.weight.grad = copy.deepcopy(layer.Bi_weight.grad)
optimizer.step()

But failed, optimizer can’t update a parameter not requiring grad.
Thank you again!
Chengzhe XU