-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmulti_margin_loss_backward.h
More file actions
72 lines (50 loc) · 1.9 KB
/
multi_margin_loss_backward.h
File metadata and controls
72 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef INFINI_OPS_BASE_MULTI_MARGIN_LOSS_BACKWARD_H_
#define INFINI_OPS_BASE_MULTI_MARGIN_LOSS_BACKWARD_H_
#include "operator.h"
namespace infini::ops {
class MultiMarginLossBackward : public Operator<MultiMarginLossBackward> {
public:
MultiMarginLossBackward(const Tensor grad_output, const Tensor input,
const Tensor target, const double p,
const double margin, const int64_t reduction,
Tensor grad_input)
: grad_output_shape_{grad_output.shape()},
grad_output_strides_{grad_output.strides()},
grad_output_type_{grad_output.dtype()},
input_shape_{input.shape()},
input_strides_{input.strides()},
input_type_{input.dtype()},
target_shape_{target.shape()},
target_strides_{target.strides()},
target_type_{target.dtype()},
grad_input_shape_{grad_input.shape()},
grad_input_strides_{grad_input.strides()},
grad_input_type_{grad_input.dtype()},
p_{p},
margin_{margin},
reduction_{reduction},
device_index_{grad_input.device().index()} {}
virtual void operator()(const Tensor grad_output, const Tensor input,
const Tensor target, const double p,
const double margin, const int64_t reduction,
Tensor grad_input) const = 0;
protected:
Tensor::Shape grad_output_shape_;
Tensor::Strides grad_output_strides_;
DataType grad_output_type_;
Tensor::Shape input_shape_;
Tensor::Strides input_strides_;
DataType input_type_;
Tensor::Shape target_shape_;
Tensor::Strides target_strides_;
DataType target_type_;
Tensor::Shape grad_input_shape_;
Tensor::Strides grad_input_strides_;
DataType grad_input_type_;
double p_{};
double margin_{};
int64_t reduction_{};
int device_index_{0};
};
} // namespace infini::ops
#endif