Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support N-D tensors in Bilinear#5764

Merged
soumith merged 5 commits into
pytorch:masterfrom
li-roy:bilinear
Mar 17, 2018
Merged

Support N-D tensors in Bilinear#5764
soumith merged 5 commits into
pytorch:masterfrom
li-roy:bilinear

Conversation

@li-roy
Copy link
Copy Markdown
Contributor

@li-roy li-roy commented Mar 14, 2018

Closes #5601.

@goldsborough
Copy link
Copy Markdown
Contributor

@pytorchbot retest this please

@li-roy
Copy link
Copy Markdown
Contributor Author

li-roy commented Mar 15, 2018

@pytorchbot retest this please

namespace at { namespace native {

Tensor bilinear(const Tensor& input1, const Tensor& input2, const Tensor& weight, const Tensor& bias) {
auto b_input1 = input1.unsqueeze(-2).unsqueeze(-2);

This comment was marked as off-topic.

Shape:
- Input: :math:`(N, \text{in1_features})`, :math:`(N, \text{in2_features})`
- Output: :math:`(N, \text{out_features})`
where :math:`*` means any number of additional dimensions. All but the last

This comment was marked as off-topic.

Comment thread aten/src/ATen/native/Linear.cpp Outdated
auto b_input2 = input2.unsqueeze(-2).unsqueeze(-1);

auto output = at::matmul(at::matmul(b_input1, weight), b_input2);
output = output.squeeze(-1).squeeze(-2).sum(-1);

This comment was marked as off-topic.

Comment thread aten/src/ATen/native/Linear.cpp Outdated

Tensor bilinear(const Tensor& input1, const Tensor& input2, const Tensor& weight, const Tensor& bias) {
if (input1.dim() != input2.dim()) {
throw std::runtime_error("Inputs should have the same number of dimensions");

This comment was marked as off-topic.

Comment thread aten/src/ATen/native/Linear.cpp Outdated
}
for (int64_t i = 0; i < input1.dim() - 1; i++) {
if (input1.size(i) != input2.size(i)) {
throw std::runtime_error("Batch dimensions of inputs do not match");

This comment was marked as off-topic.

Comment thread aten/src/ATen/native/Linear.cpp Outdated
if (input1.dim() != input2.dim()) {
throw std::runtime_error("Inputs should have the same number of dimensions");
}
AT_ASSERT(input1.dim() == input2.dim(), "bilinear(): input dimensions do not match: got %d and %d",

This comment was marked as off-topic.

Comment thread aten/src/ATen/native/Linear.cpp Outdated
throw std::runtime_error("Bias sizes does not match weight size");
AT_ASSERT(input1.size(i) == input2.size(i),
"bilinear(): input batch dimensions do not match at dim %d: got %d and %d",
i, input1.size(i), input2.size(i));

This comment was marked as off-topic.

@li-roy
Copy link
Copy Markdown
Contributor Author

li-roy commented Mar 17, 2018

@pytorchbot retest this please

Copy link
Copy Markdown
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

🥇          🥇 🥇 🥇 🥇    🥇 🥇 🥇       🥇 🥇🥇 🥇 🥇 
🥇          🥇                 🥇          🥇    🥇   🥇 
🥇          🥇     🥇 🥇      🥇           🥇    🥇   🥇 
🥇          🥇        🥇       🥇          🥇    🥇   🥇 
🥇 🥇 🥇    🥇 🥇 🥇 🥇      🥇          🥇    🥇   🥇 

@soumith soumith merged commit 1dcad08 into pytorch:master Mar 17, 2018
@soumith
Copy link
Copy Markdown
Collaborator

soumith commented Mar 17, 2018

I like richard's enthusiasm :D

@li-roy li-roy deleted the bilinear branch April 19, 2018 17:39
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
* support n-d inputs in bilinear and move to aten

* support n-d inputs in bilinear and move to aten

* add asserts to bilinear inputs

* address comments

* cast int64_t in asserts
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