InfiniOps
Operator Library for Accelerators
Loading...
Searching...
No Matches
nll_loss_backward.h
Go to the documentation of this file.
1#ifndef INFINI_OPS_BASE_NLL_LOSS_BACKWARD_H_
2#define INFINI_OPS_BASE_NLL_LOSS_BACKWARD_H_
3
4#include <optional>
5
6#include "operator.h"
7
8namespace infini::ops {
9
10class NllLossBackward : public Operator<NllLossBackward> {
11 public:
12 NllLossBackward(const Tensor grad_output, const Tensor input,
13 const Tensor target, const std::optional<Tensor> weight,
14 const Tensor total_weight, const int64_t reduction,
15 const int64_t ignore_index, Tensor grad_input)
16 : grad_output_shape_{grad_output.shape()},
17 grad_output_strides_{grad_output.strides()},
18 grad_output_type_{grad_output.dtype()},
19 input_shape_{input.shape()},
20 input_strides_{input.strides()},
21 input_type_{input.dtype()},
22 target_shape_{target.shape()},
23 target_strides_{target.strides()},
24 target_type_{target.dtype()},
25 total_weight_shape_{total_weight.shape()},
26 total_weight_strides_{total_weight.strides()},
27 total_weight_type_{total_weight.dtype()},
28 grad_input_shape_{grad_input.shape()},
29 grad_input_strides_{grad_input.strides()},
30 grad_input_type_{grad_input.dtype()},
31 has_weight_{weight.has_value()},
32 weight_shape_{weight ? Tensor::Shape{weight->shape()}
33 : Tensor::Shape{}},
34 weight_strides_{weight ? Tensor::Strides{weight->strides()}
35 : Tensor::Strides{}},
36 weight_type_{weight ? weight->dtype() : DataType::kFloat32},
37 reduction_{reduction},
38 ignore_index_{ignore_index},
39 device_index_{grad_input.device().index()} {}
40
41 virtual void operator()(const Tensor grad_output, const Tensor input,
42 const Tensor target,
43 const std::optional<Tensor> weight,
44 const Tensor total_weight, const int64_t reduction,
45 const int64_t ignore_index,
46 Tensor grad_input) const = 0;
47
48 protected:
49 Tensor::Shape grad_output_shape_;
50
51 Tensor::Strides grad_output_strides_;
52
54
55 Tensor::Shape input_shape_;
56
57 Tensor::Strides input_strides_;
58
59 DataType input_type_;
60
61 Tensor::Shape target_shape_;
62
63 Tensor::Strides target_strides_;
64
65 DataType target_type_;
66
67 Tensor::Shape total_weight_shape_;
68
69 Tensor::Strides total_weight_strides_;
70
72
73 Tensor::Shape grad_input_shape_;
74
75 Tensor::Strides grad_input_strides_;
76
78
79 bool has_weight_{false};
80
81 Tensor::Shape weight_shape_;
82
83 Tensor::Strides weight_strides_;
84
85 DataType weight_type_{DataType::kFloat32};
86
87 int64_t reduction_{};
88
89 int64_t ignore_index_{};
90
92};
93
94} // namespace infini::ops
95
96#endif
Definition nll_loss_backward.h:10
int64_t reduction_
Definition nll_loss_backward.h:87
int64_t ignore_index_
Definition nll_loss_backward.h:89
Tensor::Shape target_shape_
Definition nll_loss_backward.h:61
Tensor::Shape grad_input_shape_
Definition nll_loss_backward.h:73
virtual void operator()(const Tensor grad_output, const Tensor input, const Tensor target, const std::optional< Tensor > weight, const Tensor total_weight, const int64_t reduction, const int64_t ignore_index, Tensor grad_input) const =0
Tensor::Strides target_strides_
Definition nll_loss_backward.h:63
Tensor::Strides grad_output_strides_
Definition nll_loss_backward.h:51
Tensor::Strides weight_strides_
Definition nll_loss_backward.h:83
DataType total_weight_type_
Definition nll_loss_backward.h:71
int device_index_
Definition nll_loss_backward.h:91
Tensor::Shape weight_shape_
Definition nll_loss_backward.h:81
NllLossBackward(const Tensor grad_output, const Tensor input, const Tensor target, const std::optional< Tensor > weight, const Tensor total_weight, const int64_t reduction, const int64_t ignore_index, Tensor grad_input)
Definition nll_loss_backward.h:12
Tensor::Shape input_shape_
Definition nll_loss_backward.h:55
Tensor::Shape total_weight_shape_
Definition nll_loss_backward.h:67
DataType weight_type_
Definition nll_loss_backward.h:85
DataType grad_output_type_
Definition nll_loss_backward.h:53
DataType input_type_
Definition nll_loss_backward.h:59
Tensor::Shape grad_output_shape_
Definition nll_loss_backward.h:49
Tensor::Strides input_strides_
Definition nll_loss_backward.h:57
DataType target_type_
Definition nll_loss_backward.h:65
Tensor::Strides grad_input_strides_
Definition nll_loss_backward.h:75
bool has_weight_
Definition nll_loss_backward.h:79
Tensor::Strides total_weight_strides_
Definition nll_loss_backward.h:69
DataType grad_input_type_
Definition nll_loss_backward.h:77
Definition generated/include/operator.h:282
Definition generated/include/operator.h:28
infini::rt::TensorView Tensor
Definition tensor.h:8