Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Remove not using tensor for backward
Browse files Browse the repository at this point in the history
  • Loading branch information
mejai1206 committed Sep 19, 2023
1 parent 271b428 commit 86d3cfd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions trident/operation/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@ def forward(ctx: Any, *args: Any, **kwargs: Any):
output = Linear.__forward(input, weight, bias, use_accelerator)
util.pop_trace()

ctx.save_for_backward(input, weight, bias, output)
ctx.save_for_backward(input, weight, bias)
ctx.use_accelerator = use_accelerator

return output

@staticmethod
def backward(ctx: Any, *grad_outputs: Any):
(grad_output,) = grad_outputs
input, weight, bias, output = ctx.saved_tensors
input, weight, bias = ctx.saved_tensors

util.push_trace("Linear.__backward")
grad_input, grad_weight, grad_bias = Linear.__backward(
grad_output, output, input, weight, bias, ctx.use_accelerator
)
grad_input, grad_weight, grad_bias = Linear.__backward(grad_output, input, weight, bias, ctx.use_accelerator)
util.pop_trace()

return grad_input, grad_weight, grad_bias, None, None
Expand Down Expand Up @@ -81,7 +79,7 @@ def grid(meta):
return output

@staticmethod
def __backward(grad_output, output, input, weight, bias, use_accelerator):
def __backward(grad_output, input, weight, bias, use_accelerator):
factory_kwargs = {"device": input.device, "dtype": input.dtype}
num_batches, m_size, k_size = input.shape
n_size, _ = weight.shape
Expand Down

0 comments on commit 86d3cfd

Please sign in to comment.