-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aten::multi_margin_loss and its variants (#895)
- [x] multi_margin_loss - [x] multi_margin_loss.out - [x] multi_margin_loss_backward - [x] multi_margin_loss_backward.grad_input --------- Co-authored-by: Yutao Xu <[email protected]>
- Loading branch information
1 parent
bdbda35
commit b189259
Showing
7 changed files
with
662 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <ATen/core/Tensor.h> | ||
#include <ATen/native/xpu/sycl/MultiMarginLossKernels.h> | ||
|
||
#include <ATen/ops/empty.h> | ||
#include <xpu/ATen/ops/multi_margin_loss_backward_native.h> | ||
#include <xpu/ATen/ops/multi_margin_loss_native.h> | ||
|
||
namespace at::native { | ||
|
||
Tensor& multi_margin_loss_xpu_out( | ||
const Tensor& self, | ||
const Tensor& target, | ||
const Scalar& p, | ||
const Scalar& margin, | ||
const std::optional<Tensor>& weight, | ||
int64_t reduction, | ||
Tensor& out) { | ||
xpu::multi_margin_loss_kernel( | ||
self, target, p, margin, weight, reduction, out); | ||
return out; | ||
} | ||
|
||
Tensor multi_margin_loss_xpu( | ||
const Tensor& self, | ||
const Tensor& target, | ||
const Scalar& p, | ||
const Scalar& margin, | ||
const std::optional<Tensor>& weight, | ||
int64_t reduction) { | ||
auto out = at::empty({0}, self.options()); | ||
xpu::multi_margin_loss_kernel( | ||
self, target, p, margin, weight, reduction, out); | ||
return out; | ||
} | ||
|
||
Tensor& multi_margin_loss_xpu_backward_out( | ||
const Tensor& grad_output, | ||
const Tensor& self, | ||
const Tensor& target, | ||
const Scalar& p, | ||
const Scalar& margin, | ||
const std::optional<Tensor>& weight, | ||
int64_t reduction, | ||
Tensor& grad_input) { | ||
xpu::multi_margin_loss_backward_kernel( | ||
grad_output, self, target, p, margin, weight, reduction, grad_input); | ||
return grad_input; | ||
} | ||
|
||
Tensor multi_margin_loss_xpu_backward( | ||
const Tensor& grad_output, | ||
const Tensor& self, | ||
const Tensor& target, | ||
const Scalar& p, | ||
const Scalar& margin, | ||
const std::optional<Tensor>& weight, | ||
int64_t reduction) { | ||
auto grad_input = at::empty({0}, self.options()); | ||
xpu::multi_margin_loss_backward_kernel( | ||
grad_output, self, target, p, margin, weight, reduction, grad_input); | ||
return grad_input; | ||
} | ||
|
||
} // namespace at::native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.