Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/cpp/test_aten_xla_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,25 @@ TEST_F(AtenXlaTensorTest, TestChainMatMul) {
});
}

TEST_F(AtenXlaTensorTest, TestLinear) {
at::Tensor input = at::rand({2, 4}, at::TensorOptions(at::kFloat));
at::Tensor weight = at::rand({3, 4}, at::TensorOptions(at::kFloat));
at::Tensor bias = at::rand({3});
at::Tensor result = at::linear(input, weight);
at::Tensor result_with_bias = at::linear(input, weight, bias);
ForEachDevice([&](const Device& device) {
at::Tensor xla_input = bridge::CreateXlaTensor(input, device);
at::Tensor xla_weight = bridge::CreateXlaTensor(weight, device);
at::Tensor xla_bias = bridge::CreateXlaTensor(bias, device);
at::Tensor xla_result = at::linear(xla_input, xla_weight);
at::Tensor xla_result_with_bias =
at::linear(xla_input, xla_weight, xla_bias);
AllClose(result, xla_result, /*rtol=*/1e-3, /*atol=*/1e-4);
AllClose(result_with_bias, xla_result_with_bias, /*rtol=*/1e-3,
/*atol=*/1e-4);
});
}

TEST_F(AtenXlaTensorTest, TestEinsumOuter) {
at::Tensor a = at::rand({5}, at::TensorOptions(at::kFloat));
at::Tensor b = at::rand({5}, at::TensorOptions(at::kFloat));
Expand Down
6 changes: 6 additions & 0 deletions torch_xla/csrc/aten_xla_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,12 @@ at::Tensor AtenXlaType::chain_matmul(at::TensorList matrices) const {
return at::native::chain_matmul(matrices);
}

at::Tensor AtenXlaType::linear(const at::Tensor& input,
const at::Tensor& weight,
const at::Tensor& bias) const {
return at::native::linear(input, weight, bias);
}

std::vector<at::Tensor> AtenXlaType::broadcast_tensors(
at::TensorList tensors) const {
return bridge::AtenFromXlaTensors(
Expand Down
3 changes: 3 additions & 0 deletions torch_xla/csrc/aten_xla_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ class AtenXlaType : public AtenXlaTypeBase {

at::Tensor chain_matmul(at::TensorList matrices) const override;

at::Tensor linear(const at::Tensor& input, const at::Tensor& weight,
const at::Tensor& bias) const override;

std::vector<at::Tensor> broadcast_tensors(
at::TensorList tensors) const override;

Expand Down