Skip to content

Commit 8f6ad61

Browse files
committed
feat: add nll_loss_backward_grad_input base
1 parent 57ec7e3 commit 8f6ad61

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef INFINI_OPS_BASE_NLL_LOSS_BACKWARD_GRAD_INPUT_H_
2+
#define INFINI_OPS_BASE_NLL_LOSS_BACKWARD_GRAD_INPUT_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class NllLossBackwardGradInput : public Operator<NllLossBackwardGradInput> {
9+
public:
10+
NllLossBackwardGradInput(const Tensor grad_output, const Tensor self,
11+
const Tensor target, const int64_t reduction,
12+
const int64_t ignore_index,
13+
const Tensor total_weight, Tensor grad_input)
14+
: grad_output_shape_{grad_output.shape()},
15+
grad_output_strides_{grad_output.strides()},
16+
grad_output_type_{grad_output.dtype()},
17+
self_shape_{self.shape()},
18+
self_strides_{self.strides()},
19+
self_type_{self.dtype()},
20+
target_shape_{target.shape()},
21+
target_strides_{target.strides()},
22+
target_type_{target.dtype()},
23+
total_weight_shape_{total_weight.shape()},
24+
total_weight_strides_{total_weight.strides()},
25+
total_weight_type_{total_weight.dtype()},
26+
grad_input_shape_{grad_input.shape()},
27+
grad_input_strides_{grad_input.strides()},
28+
grad_input_type_{grad_input.dtype()},
29+
device_index_{grad_input.device().index()} {}
30+
31+
virtual void operator()(const Tensor grad_output, const Tensor self,
32+
const Tensor target, const int64_t reduction,
33+
const int64_t ignore_index, const Tensor total_weight,
34+
Tensor grad_input) const = 0;
35+
36+
protected:
37+
Tensor::Shape grad_output_shape_;
38+
Tensor::Strides grad_output_strides_;
39+
DataType grad_output_type_;
40+
Tensor::Shape self_shape_;
41+
Tensor::Strides self_strides_;
42+
DataType self_type_;
43+
Tensor::Shape target_shape_;
44+
Tensor::Strides target_strides_;
45+
DataType target_type_;
46+
Tensor::Shape total_weight_shape_;
47+
Tensor::Strides total_weight_strides_;
48+
DataType total_weight_type_;
49+
Tensor::Shape grad_input_shape_;
50+
Tensor::Strides grad_input_strides_;
51+
DataType grad_input_type_;
52+
int device_index_{0};
53+
};
54+
55+
} // namespace infini::ops
56+
57+
#endif

0 commit comments

Comments
 (0)