Skip to content

Remove clone in fused rnn double back quick fix#1683

Closed
csarofeen wants to merge 7 commits intopytorch:masterfrom
csarofeen:fused_rnn_fix
Closed

Remove clone in fused rnn double back quick fix#1683
csarofeen wants to merge 7 commits intopytorch:masterfrom
csarofeen:fused_rnn_fix

Conversation

@csarofeen
Copy link
Contributor

Better fix for #1532

@apaszke
Copy link
Contributor

apaszke commented May 30, 2017

What's the memory footprint of these changes? It seems that it holds quite a workspace. Can't it e.g. save hx separately to decrease mem usage (it seems that it's just copied into the buffer)?

@csarofeen
Copy link
Contributor Author

That goes out of scope after the forward call and is not particularly big. But there were some larger memory usage issues that I got rid of.

Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but the linter is unhappy

*oghn = ghn;
DEVICE_LINEAR_GET(hidden, offset+0*hsz) = grg;
DEVICE_LINEAR_GET(hidden, offset+1*hsz) = gig;
DEVICE_LINEAR_GET(hidden, offset+2*hsz) = ghn;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

ibias = ibias.view(1, -1)
if hbias.dim() == 1:
hbias.unsqueeze_(0)
hbias = hbias.view(1, -1)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

self.backend = type2backend[type(input_gate)]

hy = input_gate.new()
storage = input_gate.new().resize_(hx.numel() * 5)

This comment was marked as off-topic.

igc = input_gate.clone()
hgc = hidden_gate.clone()
gradInputHx = gradOutput.new()
gradInInput = gradOutput.new().resize_(*self.igate_size)

This comment was marked as off-topic.

return igc, hgc, gradInput, gb1, gb2
if self.hasBias:
gb1 = gradInInput.sum(0).squeeze()
gb2 = gradInHidden.sum(0).squeeze()

This comment was marked as off-topic.

gradInInput = gradOutput.new().resize_(*self.igate_size)
gradInHidden = gradOutput.new().resize_(*self.hgate_size)

storage = self.buffer

This comment was marked as off-topic.

hy = input_gate.new()
storage = input_gate.new().resize_(hx.numel() * 5)

self.hasBias = False

This comment was marked as off-topic.

@soumith
Copy link
Collaborator

soumith commented Jun 7, 2017

merged into master

@soumith soumith closed this Jun 7, 2017
@csarofeen csarofeen deleted the fused_rnn_fix branch February 12, 2020 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants