Skip to content

Support broadcast for bias in grouped conv fwd#1081

Merged
bartekxk merged 6 commits into
developfrom
barkocot/issue-1076
Dec 8, 2023
Merged

Support broadcast for bias in grouped conv fwd#1081
bartekxk merged 6 commits into
developfrom
barkocot/issue-1076

Conversation

@bartekxk
Copy link
Copy Markdown
Contributor

@bartekxk bartekxk commented Dec 5, 2023

@bartekxk bartekxk self-assigned this Dec 5, 2023
Copy link
Copy Markdown
Contributor

@amberhassaan amberhassaan 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 from user interface perspective.

K, Do * Ho * Wo * G * K, 1, Ho * Wo * G * K, Wo * G * K, G * K};
// Logical broadcast bias (we have to pass bias lengths in the same format as output - GNKDHW)
std::array<ck::index_t, 6> bias_lengths{G, 1, K, 1, 1, 1};
std::array<ck::index_t, 6> bias_strides{K, 0, 1, 0, 0, 0};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not super important but I think the remaining strides should be >= K to be a valid set of strides.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lengths are set to 1 so these strides are also valid. Reference implementation uses these strides to perform logical broadcast.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For packed case, valid strides wouldn't have 0s. They'd be {K, K, 1, K , K, K}. For non-packed case, they can be anything >= K really.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If You would like to perform logical broadcast You have to jump to the same memory in each step.

For example:
You would like to use broadcasted memory 3x4x2, where (4x2 is broadcasted 3 times). So the step for the first dimension is 0.
data[0, x, y] == data[1, x, y] == data[2, x, y]


//
using G_K = ck::tensor_layout::convolution::G_K;
using GK = ck::tensor_layout::convolution::G_K;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like G_K is a duplicate of GK?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I removed GK. G_K is used in a lot of examples so to keep backward compatibility I left G_K (which is also less intuitive for me). I suppose, it was designed to supported not packed (G_K ) in different layout than packed (GK). At now the both cases are supported using G_K.

using InLayout = ck::tensor_layout::convolution::NDHWGC;
using WeiLayout = ck::tensor_layout::convolution::GKZYXC;
using OutLayout = ck::tensor_layout::convolution::NDHWGK;
using BiasLayout = ck::tensor_layout::convolution::G_K;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

one advantage of using a separate layout is that I can tell which one is bias and which one is z when passing as a tuple.

@geyyer geyyer requested review from geyyer and removed request for bwroblew December 7, 2023 21:34
Copy link
Copy Markdown
Contributor

@geyyer geyyer left a comment

Choose a reason for hiding this comment

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

LGTM!

@bartekxk bartekxk merged commit f836984 into develop Dec 8, 2023
@bartekxk bartekxk deleted the barkocot/issue-1076 branch December 14, 2023 23:43
asroy pushed a commit that referenced this pull request Dec 18, 2023
* Support broadcast for bias in grouped conv fwd

* Fix comment

* Comment fixes

* Remove GK layout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants