Skip to content

drq: change view to reshape to support channels last#1367

Closed
chunyuan-w wants to merge 2 commits intopytorch:mainfrom
chunyuan-w:chunyuan/fix_view
Closed

drq: change view to reshape to support channels last#1367
chunyuan-w wants to merge 2 commits intopytorch:mainfrom
chunyuan-w:chunyuan/fix_view

Conversation

@chunyuan-w
Copy link
Contributor

@chunyuan-w chunyuan-w commented Jan 12, 2023

The current implementation of drq does not support channels last input since view has constraints on the input size and stride (https://pytorch.org/docs/stable/generated/torch.Tensor.view.html):

Cannot view a tensor with shape torch.Size([1, 32, 35, 35]) and strides (39200, 1, 1120, 32) as a tensor with shape (1, 39200)!

Change view to reshape which returns a view if the shapes are compatible, and copies (equivalent to calling contiguous()) otherwise.

@chunyuan-w
Copy link
Contributor Author

@xuzhao9 could you please help review this PR? Thanks!

@chunyuan-w
Copy link
Contributor Author

cc @jgong5

@facebook-github-bot
Copy link
Contributor

@xuzhao9 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@xuzhao9 xuzhao9 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the improvement.
Just want to note that we should also add a comment in the code saying this is an update that doesn't exist in the upstream code: https://github.com/denisyarats/drq/blob/master/drq.py#L48

self.outputs['conv%s' % (i + 1)] = conv

h = conv.view(conv.size(0), -1)
h = conv.reshape(conv.size(0), -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add one-line comment mention that this is an improvement that doesn't exist in the upstream code (with link to the upstream code at https://github.com/denisyarats/drq/blob/master/drq.py#L48)?

Copy link

Choose a reason for hiding this comment

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

@xuzhao9 We can submit a PR to upstream too. Does it sound good to you?

Copy link
Contributor

Choose a reason for hiding this comment

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

@xuzhao9 We can submit a PR to upstream too. Does it sound good to you?

Sure, if you can submit a PR to upstream and get accepted, we don't need the comment line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added one-line comment as suggested for now.
I'll submit a PR to upstream this. If it is accepted, let me submit a following-up PR later to this benchmark repo to remove the one-line comment. Is it okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that shoulds perfect to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI, I've submitted a PR to the upstream drq repo: denisyarats/drq#27.

@chunyuan-w
Copy link
Contributor Author

For the CI failure, it seems unrelated with my changes:
image

And it also marks that there are 2 workflows awaiting approval:
image

@xuzhao9 could you please help on that?

@xuzhao9
Copy link
Contributor

xuzhao9 commented Jan 13, 2023

For the CI failure, it seems unrelated with my changes: image

And it also marks that there are 2 workflows awaiting approval: image

@xuzhao9 could you please help on that?

There is a pre-existing CI failure not because of this PR. Sorry but we are still working on it.
I manually tested this PR should be safe, we can merge it despite the CI problem.

@facebook-github-bot
Copy link
Contributor

@xuzhao9 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@xuzhao9 merged this pull request in ef39f8c.

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.

4 participants