Skip to content

Commit 6341e8a

Browse files
committed
feat: add nll_loss_backward base
1 parent 78424f7 commit 6341e8a

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

src/base/nll_loss_backward.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// AUTO-GENERATED by `scripts/generate_torch_ops.py` — DO NOT EDIT.
2+
#ifndef INFINI_OPS_BASE_NLL_LOSS_BACKWARD_H_
3+
#define INFINI_OPS_BASE_NLL_LOSS_BACKWARD_H_
4+
5+
#include "operator.h"
6+
7+
namespace infini::ops {
8+
9+
class NllLossBackward : public Operator<NllLossBackward> {
10+
public:
11+
NllLossBackward(const Tensor grad_output, const Tensor input, const Tensor target, const int64_t reduction, const int64_t ignore_index, const Tensor total_weight, Tensor grad_input)
12+
: grad_output_shape_{grad_output.shape()},
13+
grad_output_strides_{grad_output.strides()},
14+
grad_output_type_{grad_output.dtype()},
15+
input_shape_{input.shape()},
16+
input_strides_{input.strides()},
17+
input_type_{input.dtype()},
18+
target_shape_{target.shape()},
19+
target_strides_{target.strides()},
20+
target_type_{target.dtype()},
21+
total_weight_shape_{total_weight.shape()},
22+
total_weight_strides_{total_weight.strides()},
23+
total_weight_type_{total_weight.dtype()},
24+
grad_input_shape_{grad_input.shape()},
25+
grad_input_strides_{grad_input.strides()},
26+
grad_input_type_{grad_input.dtype()},
27+
reduction_{reduction},
28+
ignore_index_{ignore_index},
29+
device_index_{grad_input.device().index()} {}
30+
31+
virtual void operator()(const Tensor grad_output, const Tensor input, const Tensor target, const int64_t reduction, const int64_t ignore_index, const Tensor total_weight, Tensor grad_input) const = 0;
32+
33+
protected:
34+
Tensor::Shape grad_output_shape_;
35+
36+
Tensor::Strides grad_output_strides_;
37+
38+
DataType grad_output_type_;
39+
40+
Tensor::Shape input_shape_;
41+
42+
Tensor::Strides input_strides_;
43+
44+
DataType input_type_;
45+
46+
Tensor::Shape target_shape_;
47+
48+
Tensor::Strides target_strides_;
49+
50+
DataType target_type_;
51+
52+
Tensor::Shape total_weight_shape_;
53+
54+
Tensor::Strides total_weight_strides_;
55+
56+
DataType total_weight_type_;
57+
58+
Tensor::Shape grad_input_shape_;
59+
60+
Tensor::Strides grad_input_strides_;
61+
62+
DataType grad_input_type_;
63+
64+
int64_t reduction_{};
65+
66+
int64_t ignore_index_{};
67+
68+
int device_index_{0};
69+
};
70+
71+
} // namespace infini::ops
72+
73+
#endif

0 commit comments

Comments
 (0)