torch-rb 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/LICENSE.txt +46 -22
  4. data/README.md +73 -9
  5. data/ext/torch/ext.cpp +148 -315
  6. data/ext/torch/extconf.rb +6 -0
  7. data/ext/torch/nn_functions.cpp +615 -0
  8. data/ext/torch/nn_functions.hpp +6 -0
  9. data/ext/torch/templates.cpp +55 -0
  10. data/ext/torch/templates.hpp +298 -0
  11. data/ext/torch/tensor_functions.cpp +1920 -0
  12. data/ext/torch/tensor_functions.hpp +6 -0
  13. data/ext/torch/torch_functions.cpp +2975 -0
  14. data/ext/torch/torch_functions.hpp +6 -0
  15. data/lib/torch.rb +236 -112
  16. data/lib/torch/ext.bundle +0 -0
  17. data/lib/torch/inspector.rb +52 -25
  18. data/lib/torch/native/dispatcher.rb +48 -0
  19. data/lib/torch/native/function.rb +109 -0
  20. data/lib/torch/native/generator.rb +168 -0
  21. data/lib/torch/native/native_functions.yaml +6837 -0
  22. data/lib/torch/native/parser.rb +134 -0
  23. data/lib/torch/nn/alpha_dropout.rb +9 -0
  24. data/lib/torch/nn/avg_pool1d.rb +18 -0
  25. data/lib/torch/nn/avg_pool2d.rb +19 -0
  26. data/lib/torch/nn/avg_pool3d.rb +19 -0
  27. data/lib/torch/nn/avg_poolnd.rb +9 -0
  28. data/lib/torch/nn/batch_norm.rb +75 -0
  29. data/lib/torch/nn/batch_norm1d.rb +11 -0
  30. data/lib/torch/nn/batch_norm2d.rb +11 -0
  31. data/lib/torch/nn/batch_norm3d.rb +11 -0
  32. data/lib/torch/nn/bce_loss.rb +13 -0
  33. data/lib/torch/nn/bce_with_logits_loss.rb +15 -0
  34. data/lib/torch/nn/bilinear.rb +38 -0
  35. data/lib/torch/nn/constant_pad1d.rb +10 -0
  36. data/lib/torch/nn/constant_pad2d.rb +10 -0
  37. data/lib/torch/nn/constant_pad3d.rb +10 -0
  38. data/lib/torch/nn/constant_padnd.rb +18 -0
  39. data/lib/torch/nn/conv1d.rb +22 -0
  40. data/lib/torch/nn/conv2d.rb +16 -39
  41. data/lib/torch/nn/conv3d.rb +22 -0
  42. data/lib/torch/nn/convnd.rb +41 -0
  43. data/lib/torch/nn/cosine_embedding_loss.rb +14 -0
  44. data/lib/torch/nn/cosine_similarity.rb +15 -0
  45. data/lib/torch/nn/cross_entropy_loss.rb +14 -0
  46. data/lib/torch/nn/ctc_loss.rb +15 -0
  47. data/lib/torch/nn/dropout.rb +9 -0
  48. data/lib/torch/nn/dropout2d.rb +9 -0
  49. data/lib/torch/nn/dropout3d.rb +9 -0
  50. data/lib/torch/nn/dropoutnd.rb +15 -0
  51. data/lib/torch/nn/embedding.rb +52 -0
  52. data/lib/torch/nn/embedding_bag.rb +34 -0
  53. data/lib/torch/nn/feature_alpha_dropout.rb +9 -0
  54. data/lib/torch/nn/fold.rb +20 -0
  55. data/lib/torch/nn/functional.rb +419 -16
  56. data/lib/torch/nn/group_norm.rb +36 -0
  57. data/lib/torch/nn/gru.rb +49 -0
  58. data/lib/torch/nn/hardshrink.rb +18 -0
  59. data/lib/torch/nn/hinge_embedding_loss.rb +14 -0
  60. data/lib/torch/nn/identity.rb +14 -0
  61. data/lib/torch/nn/init.rb +58 -1
  62. data/lib/torch/nn/instance_norm.rb +20 -0
  63. data/lib/torch/nn/instance_norm1d.rb +18 -0
  64. data/lib/torch/nn/instance_norm2d.rb +11 -0
  65. data/lib/torch/nn/instance_norm3d.rb +11 -0
  66. data/lib/torch/nn/kl_div_loss.rb +13 -0
  67. data/lib/torch/nn/l1_loss.rb +13 -0
  68. data/lib/torch/nn/layer_norm.rb +35 -0
  69. data/lib/torch/nn/leaky_relu.rb +20 -0
  70. data/lib/torch/nn/linear.rb +12 -11
  71. data/lib/torch/nn/local_response_norm.rb +21 -0
  72. data/lib/torch/nn/log_sigmoid.rb +9 -0
  73. data/lib/torch/nn/log_softmax.rb +14 -0
  74. data/lib/torch/nn/loss.rb +10 -0
  75. data/lib/torch/nn/lp_pool1d.rb +9 -0
  76. data/lib/torch/nn/lp_pool2d.rb +9 -0
  77. data/lib/torch/nn/lp_poolnd.rb +22 -0
  78. data/lib/torch/nn/lstm.rb +66 -0
  79. data/lib/torch/nn/margin_ranking_loss.rb +14 -0
  80. data/lib/torch/nn/max_pool1d.rb +9 -0
  81. data/lib/torch/nn/max_pool2d.rb +9 -0
  82. data/lib/torch/nn/max_pool3d.rb +9 -0
  83. data/lib/torch/nn/max_poolnd.rb +19 -0
  84. data/lib/torch/nn/max_unpool1d.rb +16 -0
  85. data/lib/torch/nn/max_unpool2d.rb +16 -0
  86. data/lib/torch/nn/max_unpool3d.rb +16 -0
  87. data/lib/torch/nn/max_unpoolnd.rb +9 -0
  88. data/lib/torch/nn/module.rb +191 -19
  89. data/lib/torch/nn/mse_loss.rb +2 -2
  90. data/lib/torch/nn/multi_label_margin_loss.rb +13 -0
  91. data/lib/torch/nn/multi_label_soft_margin_loss.rb +13 -0
  92. data/lib/torch/nn/multi_margin_loss.rb +17 -0
  93. data/lib/torch/nn/nll_loss.rb +14 -0
  94. data/lib/torch/nn/pairwise_distance.rb +16 -0
  95. data/lib/torch/nn/parameter.rb +4 -0
  96. data/lib/torch/nn/poisson_nll_loss.rb +16 -0
  97. data/lib/torch/nn/prelu.rb +19 -0
  98. data/lib/torch/nn/reflection_pad1d.rb +10 -0
  99. data/lib/torch/nn/reflection_pad2d.rb +10 -0
  100. data/lib/torch/nn/reflection_padnd.rb +13 -0
  101. data/lib/torch/nn/relu.rb +8 -3
  102. data/lib/torch/nn/replication_pad1d.rb +10 -0
  103. data/lib/torch/nn/replication_pad2d.rb +10 -0
  104. data/lib/torch/nn/replication_pad3d.rb +10 -0
  105. data/lib/torch/nn/replication_padnd.rb +13 -0
  106. data/lib/torch/nn/rnn.rb +22 -0
  107. data/lib/torch/nn/rnn_base.rb +198 -0
  108. data/lib/torch/nn/sequential.rb +1 -10
  109. data/lib/torch/nn/sigmoid.rb +9 -0
  110. data/lib/torch/nn/smooth_l1_loss.rb +13 -0
  111. data/lib/torch/nn/soft_margin_loss.rb +13 -0
  112. data/lib/torch/nn/softmax.rb +18 -0
  113. data/lib/torch/nn/softmax2d.rb +10 -0
  114. data/lib/torch/nn/softmin.rb +14 -0
  115. data/lib/torch/nn/softplus.rb +19 -0
  116. data/lib/torch/nn/softshrink.rb +18 -0
  117. data/lib/torch/nn/softsign.rb +9 -0
  118. data/lib/torch/nn/tanh.rb +9 -0
  119. data/lib/torch/nn/tanhshrink.rb +9 -0
  120. data/lib/torch/nn/triplet_margin_loss.rb +18 -0
  121. data/lib/torch/nn/unfold.rb +19 -0
  122. data/lib/torch/nn/utils.rb +25 -0
  123. data/lib/torch/nn/weighted_loss.rb +10 -0
  124. data/lib/torch/nn/zero_pad2d.rb +9 -0
  125. data/lib/torch/optim/adadelta.rb +57 -0
  126. data/lib/torch/optim/adagrad.rb +71 -0
  127. data/lib/torch/optim/adam.rb +81 -0
  128. data/lib/torch/optim/adamax.rb +68 -0
  129. data/lib/torch/optim/adamw.rb +82 -0
  130. data/lib/torch/optim/asgd.rb +65 -0
  131. data/lib/torch/optim/lr_scheduler/lr_scheduler.rb +33 -0
  132. data/lib/torch/optim/lr_scheduler/step_lr.rb +17 -0
  133. data/lib/torch/optim/optimizer.rb +62 -0
  134. data/lib/torch/optim/rmsprop.rb +76 -0
  135. data/lib/torch/optim/rprop.rb +68 -0
  136. data/lib/torch/optim/sgd.rb +60 -0
  137. data/lib/torch/random.rb +10 -0
  138. data/lib/torch/tensor.rb +90 -30
  139. data/lib/torch/utils/data/data_loader.rb +15 -0
  140. data/lib/torch/utils/data/tensor_dataset.rb +8 -1
  141. data/lib/torch/version.rb +1 -1
  142. metadata +122 -3
@@ -22,4 +22,10 @@ $LDFLAGS << " -Wl,-rpath,#{lib}"
22
22
  $LDFLAGS << " -L#{lib}"
23
23
  $LDFLAGS << " -ltorch -lc10"
24
24
 
25
+ # generate C++ functions
26
+ puts "Generating C++ functions..."
27
+ require_relative "../../lib/torch/native/generator"
28
+ Torch::Native::Generator.generate_cpp_functions
29
+
30
+ # create makefile
25
31
  create_makefile("torch/ext")
@@ -0,0 +1,615 @@
1
+ // generated by rake generate:functions
2
+ // do not edit by hand
3
+
4
+ #include <torch/torch.h>
5
+ #include <rice/Module.hpp>
6
+ #include "templates.hpp"
7
+
8
+ void add_nn_functions(Module m) {
9
+ m
10
+ .define_singleton_method(
11
+ "_adaptive_avg_pool2d",
12
+ *[](const Tensor &self, IntArrayRef output_size) {
13
+ return torch::adaptive_avg_pool2d(self, output_size);
14
+ })
15
+ .define_singleton_method(
16
+ "_adaptive_avg_pool2d_out",
17
+ *[](const Tensor &self, IntArrayRef output_size, Tensor &out) {
18
+ return torch::adaptive_avg_pool2d_out(out, self, output_size);
19
+ })
20
+ .define_singleton_method(
21
+ "_adaptive_avg_pool3d",
22
+ *[](const Tensor &self, IntArrayRef output_size) {
23
+ return torch::adaptive_avg_pool3d(self, output_size);
24
+ })
25
+ .define_singleton_method(
26
+ "_adaptive_avg_pool3d_out",
27
+ *[](const Tensor &self, IntArrayRef output_size, Tensor &out) {
28
+ return torch::adaptive_avg_pool3d_out(out, self, output_size);
29
+ })
30
+ .define_singleton_method(
31
+ "_adaptive_max_pool2d",
32
+ *[](const Tensor &self, IntArrayRef output_size) {
33
+ return wrap(torch::adaptive_max_pool2d(self, output_size));
34
+ })
35
+ .define_singleton_method(
36
+ "_adaptive_max_pool2d_out",
37
+ *[](const Tensor &self, IntArrayRef output_size, Tensor &out, Tensor &indices) {
38
+ return wrap(torch::adaptive_max_pool2d_out(out, indices, self, output_size));
39
+ })
40
+ .define_singleton_method(
41
+ "_adaptive_max_pool3d",
42
+ *[](const Tensor &self, IntArrayRef output_size) {
43
+ return wrap(torch::adaptive_max_pool3d(self, output_size));
44
+ })
45
+ .define_singleton_method(
46
+ "_adaptive_max_pool3d_out",
47
+ *[](const Tensor &self, IntArrayRef output_size, Tensor &out, Tensor &indices) {
48
+ return wrap(torch::adaptive_max_pool3d_out(out, indices, self, output_size));
49
+ })
50
+ .define_singleton_method(
51
+ "_avg_pool2d",
52
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, bool ceil_mode, bool count_include_pad) {
53
+ return torch::avg_pool2d(self, kernel_size, stride, padding, ceil_mode, count_include_pad);
54
+ })
55
+ .define_singleton_method(
56
+ "_avg_pool2d_divisor_override",
57
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, bool ceil_mode, bool count_include_pad, int64_t divisor_override) {
58
+ return torch::avg_pool2d(self, kernel_size, stride, padding, ceil_mode, count_include_pad, divisor_override);
59
+ })
60
+ .define_singleton_method(
61
+ "_avg_pool3d",
62
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, bool ceil_mode, bool count_include_pad) {
63
+ return torch::avg_pool3d(self, kernel_size, stride, padding, ceil_mode, count_include_pad);
64
+ })
65
+ .define_singleton_method(
66
+ "_avg_pool3d_divisor_override",
67
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, bool ceil_mode, bool count_include_pad, int64_t divisor_override) {
68
+ return torch::avg_pool3d(self, kernel_size, stride, padding, ceil_mode, count_include_pad, divisor_override);
69
+ })
70
+ .define_singleton_method(
71
+ "_binary_cross_entropy",
72
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction) {
73
+ return torch::binary_cross_entropy(self, target, weight, reduction);
74
+ })
75
+ .define_singleton_method(
76
+ "_binary_cross_entropy_out",
77
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, Tensor &out) {
78
+ return torch::binary_cross_entropy_out(out, self, target, weight, reduction);
79
+ })
80
+ .define_singleton_method(
81
+ "_col2im",
82
+ *[](const Tensor &self, IntArrayRef output_size, IntArrayRef kernel_size, IntArrayRef dilation, IntArrayRef padding, IntArrayRef stride) {
83
+ return torch::col2im(self, output_size, kernel_size, dilation, padding, stride);
84
+ })
85
+ .define_singleton_method(
86
+ "_col2im_out",
87
+ *[](const Tensor &self, IntArrayRef output_size, IntArrayRef kernel_size, IntArrayRef dilation, IntArrayRef padding, IntArrayRef stride, Tensor &out) {
88
+ return torch::col2im_out(out, self, output_size, kernel_size, dilation, padding, stride);
89
+ })
90
+ .define_singleton_method(
91
+ "_elu",
92
+ *[](const Tensor &self, Scalar alpha, Scalar scale, Scalar input_scale) {
93
+ return torch::elu(self, alpha, scale, input_scale);
94
+ })
95
+ .define_singleton_method(
96
+ "_elu_",
97
+ *[](Tensor &self, Scalar alpha, Scalar scale, Scalar input_scale) {
98
+ return torch::elu_(self, alpha, scale, input_scale);
99
+ })
100
+ .define_singleton_method(
101
+ "_elu_out",
102
+ *[](const Tensor &self, Scalar alpha, Scalar scale, Scalar input_scale, Tensor &out) {
103
+ return torch::elu_out(out, self, alpha, scale, input_scale);
104
+ })
105
+ .define_singleton_method(
106
+ "_fractional_max_pool2d",
107
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef output_size, const Tensor &random_samples) {
108
+ return wrap(torch::fractional_max_pool2d(self, kernel_size, output_size, random_samples));
109
+ })
110
+ .define_singleton_method(
111
+ "_fractional_max_pool2d_output",
112
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef output_size, const Tensor &random_samples, Tensor &output, Tensor &indices) {
113
+ return wrap(torch::fractional_max_pool2d_out(output, indices, self, kernel_size, output_size, random_samples));
114
+ })
115
+ .define_singleton_method(
116
+ "_fractional_max_pool3d",
117
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef output_size, const Tensor &random_samples) {
118
+ return wrap(torch::fractional_max_pool3d(self, kernel_size, output_size, random_samples));
119
+ })
120
+ .define_singleton_method(
121
+ "_fractional_max_pool3d_output",
122
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef output_size, const Tensor &random_samples, Tensor &output, Tensor &indices) {
123
+ return wrap(torch::fractional_max_pool3d_out(output, indices, self, kernel_size, output_size, random_samples));
124
+ })
125
+ .define_singleton_method(
126
+ "_gelu",
127
+ *[](const Tensor &self) {
128
+ return torch::gelu(self);
129
+ })
130
+ .define_singleton_method(
131
+ "_glu",
132
+ *[](const Tensor &self, int64_t dim) {
133
+ return torch::glu(self, dim);
134
+ })
135
+ .define_singleton_method(
136
+ "_glu_out",
137
+ *[](const Tensor &self, int64_t dim, Tensor &out) {
138
+ return torch::glu_out(out, self, dim);
139
+ })
140
+ .define_singleton_method(
141
+ "_hardtanh",
142
+ *[](const Tensor &self, Scalar min_val, Scalar max_val) {
143
+ return torch::hardtanh(self, min_val, max_val);
144
+ })
145
+ .define_singleton_method(
146
+ "_hardtanh_",
147
+ *[](Tensor &self, Scalar min_val, Scalar max_val) {
148
+ return torch::hardtanh_(self, min_val, max_val);
149
+ })
150
+ .define_singleton_method(
151
+ "_hardtanh_out",
152
+ *[](const Tensor &self, Scalar min_val, Scalar max_val, Tensor &out) {
153
+ return torch::hardtanh_out(out, self, min_val, max_val);
154
+ })
155
+ .define_singleton_method(
156
+ "_im2col",
157
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef dilation, IntArrayRef padding, IntArrayRef stride) {
158
+ return torch::im2col(self, kernel_size, dilation, padding, stride);
159
+ })
160
+ .define_singleton_method(
161
+ "_im2col_out",
162
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef dilation, IntArrayRef padding, IntArrayRef stride, Tensor &out) {
163
+ return torch::im2col_out(out, self, kernel_size, dilation, padding, stride);
164
+ })
165
+ .define_singleton_method(
166
+ "_l1_loss",
167
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction) {
168
+ return torch::l1_loss(self, target, reduction);
169
+ })
170
+ .define_singleton_method(
171
+ "_l1_loss_out",
172
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction, Tensor &out) {
173
+ return torch::l1_loss_out(out, self, target, reduction);
174
+ })
175
+ .define_singleton_method(
176
+ "_leaky_relu",
177
+ *[](const Tensor &self, Scalar negative_slope) {
178
+ return torch::leaky_relu(self, negative_slope);
179
+ })
180
+ .define_singleton_method(
181
+ "_leaky_relu_",
182
+ *[](Tensor &self, Scalar negative_slope) {
183
+ return torch::leaky_relu_(self, negative_slope);
184
+ })
185
+ .define_singleton_method(
186
+ "_leaky_relu_out",
187
+ *[](const Tensor &self, Scalar negative_slope, Tensor &out) {
188
+ return torch::leaky_relu_out(out, self, negative_slope);
189
+ })
190
+ .define_singleton_method(
191
+ "_linear",
192
+ *[](const Tensor &input, const Tensor &weight, OptionalTensor bias) {
193
+ return torch::linear(input, weight, bias);
194
+ })
195
+ .define_singleton_method(
196
+ "_log_sigmoid",
197
+ *[](const Tensor &self) {
198
+ return torch::log_sigmoid(self);
199
+ })
200
+ .define_singleton_method(
201
+ "_log_sigmoid_forward",
202
+ *[](const Tensor &self) {
203
+ return wrap(torch::log_sigmoid_forward(self));
204
+ })
205
+ .define_singleton_method(
206
+ "_log_sigmoid_forward_output",
207
+ *[](const Tensor &self, Tensor &output, Tensor &buffer) {
208
+ return wrap(torch::log_sigmoid_forward_out(output, buffer, self));
209
+ })
210
+ .define_singleton_method(
211
+ "_log_sigmoid_out",
212
+ *[](const Tensor &self, Tensor &out) {
213
+ return torch::log_sigmoid_out(out, self);
214
+ })
215
+ .define_singleton_method(
216
+ "_max_pool2d_with_indices",
217
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, bool ceil_mode) {
218
+ return wrap(torch::max_pool2d_with_indices(self, kernel_size, stride, padding, dilation, ceil_mode));
219
+ })
220
+ .define_singleton_method(
221
+ "_max_pool2d_with_indices_out",
222
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, bool ceil_mode, Tensor &out, Tensor &indices) {
223
+ return wrap(torch::max_pool2d_with_indices_out(out, indices, self, kernel_size, stride, padding, dilation, ceil_mode));
224
+ })
225
+ .define_singleton_method(
226
+ "_max_pool3d_with_indices",
227
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, bool ceil_mode) {
228
+ return wrap(torch::max_pool3d_with_indices(self, kernel_size, stride, padding, dilation, ceil_mode));
229
+ })
230
+ .define_singleton_method(
231
+ "_max_pool3d_with_indices_out",
232
+ *[](const Tensor &self, IntArrayRef kernel_size, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, bool ceil_mode, Tensor &out, Tensor &indices) {
233
+ return wrap(torch::max_pool3d_with_indices_out(out, indices, self, kernel_size, stride, padding, dilation, ceil_mode));
234
+ })
235
+ .define_singleton_method(
236
+ "_max_unpool2d",
237
+ *[](const Tensor &self, const Tensor &indices, IntArrayRef output_size) {
238
+ return torch::max_unpool2d(self, indices, output_size);
239
+ })
240
+ .define_singleton_method(
241
+ "_max_unpool2d_out",
242
+ *[](const Tensor &self, const Tensor &indices, IntArrayRef output_size, Tensor &out) {
243
+ return torch::max_unpool2d_out(out, self, indices, output_size);
244
+ })
245
+ .define_singleton_method(
246
+ "_max_unpool3d",
247
+ *[](const Tensor &self, const Tensor &indices, IntArrayRef output_size, IntArrayRef stride, IntArrayRef padding) {
248
+ return torch::max_unpool3d(self, indices, output_size, stride, padding);
249
+ })
250
+ .define_singleton_method(
251
+ "_max_unpool3d_out",
252
+ *[](const Tensor &self, const Tensor &indices, IntArrayRef output_size, IntArrayRef stride, IntArrayRef padding, Tensor &out) {
253
+ return torch::max_unpool3d_out(out, self, indices, output_size, stride, padding);
254
+ })
255
+ .define_singleton_method(
256
+ "_mkldnn_linear",
257
+ *[](const Tensor &input, const Tensor &weight, OptionalTensor bias) {
258
+ return torch::mkldnn_linear(input, weight, bias);
259
+ })
260
+ .define_singleton_method(
261
+ "_mkldnn_reorder_conv2d_weight",
262
+ *[](const Tensor &self, IntArrayRef padding, IntArrayRef stride, IntArrayRef dilation, int64_t groups) {
263
+ return torch::mkldnn_reorder_conv2d_weight(self, padding, stride, dilation, groups);
264
+ })
265
+ .define_singleton_method(
266
+ "_mse_loss",
267
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction) {
268
+ return torch::mse_loss(self, target, reduction);
269
+ })
270
+ .define_singleton_method(
271
+ "_mse_loss_out",
272
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction, Tensor &out) {
273
+ return torch::mse_loss_out(out, self, target, reduction);
274
+ })
275
+ .define_singleton_method(
276
+ "_multi_margin_loss",
277
+ *[](const Tensor &self, const Tensor &target, Scalar p, Scalar margin, OptionalTensor weight, MyReduction reduction) {
278
+ return torch::multi_margin_loss(self, target, p, margin, weight, reduction);
279
+ })
280
+ .define_singleton_method(
281
+ "_multi_margin_loss_out",
282
+ *[](const Tensor &self, const Tensor &target, Scalar p, Scalar margin, OptionalTensor weight, MyReduction reduction, Tensor &out) {
283
+ return torch::multi_margin_loss_out(out, self, target, p, margin, weight, reduction);
284
+ })
285
+ .define_singleton_method(
286
+ "_multilabel_margin_loss",
287
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction) {
288
+ return torch::multilabel_margin_loss(self, target, reduction);
289
+ })
290
+ .define_singleton_method(
291
+ "_multilabel_margin_loss_forward",
292
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction) {
293
+ return wrap(torch::multilabel_margin_loss_forward(self, target, reduction));
294
+ })
295
+ .define_singleton_method(
296
+ "_multilabel_margin_loss_forward_output",
297
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction, Tensor &output, Tensor &is_target) {
298
+ return wrap(torch::multilabel_margin_loss_forward_out(output, is_target, self, target, reduction));
299
+ })
300
+ .define_singleton_method(
301
+ "_multilabel_margin_loss_out",
302
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction, Tensor &out) {
303
+ return torch::multilabel_margin_loss_out(out, self, target, reduction);
304
+ })
305
+ .define_singleton_method(
306
+ "_nll_loss",
307
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index) {
308
+ return torch::nll_loss(self, target, weight, reduction, ignore_index);
309
+ })
310
+ .define_singleton_method(
311
+ "_nll_loss2d",
312
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index) {
313
+ return torch::nll_loss2d(self, target, weight, reduction, ignore_index);
314
+ })
315
+ .define_singleton_method(
316
+ "_nll_loss2d_forward",
317
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index) {
318
+ return wrap(torch::nll_loss2d_forward(self, target, weight, reduction, ignore_index));
319
+ })
320
+ .define_singleton_method(
321
+ "_nll_loss2d_forward_output",
322
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index, Tensor &output, Tensor &total_weight) {
323
+ return wrap(torch::nll_loss2d_forward_out(output, total_weight, self, target, weight, reduction, ignore_index));
324
+ })
325
+ .define_singleton_method(
326
+ "_nll_loss2d_out",
327
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index, Tensor &out) {
328
+ return torch::nll_loss2d_out(out, self, target, weight, reduction, ignore_index);
329
+ })
330
+ .define_singleton_method(
331
+ "_nll_loss_forward",
332
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index) {
333
+ return wrap(torch::nll_loss_forward(self, target, weight, reduction, ignore_index));
334
+ })
335
+ .define_singleton_method(
336
+ "_nll_loss_forward_output",
337
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index, Tensor &output, Tensor &total_weight) {
338
+ return wrap(torch::nll_loss_forward_out(output, total_weight, self, target, weight, reduction, ignore_index));
339
+ })
340
+ .define_singleton_method(
341
+ "_nll_loss_out",
342
+ *[](const Tensor &self, const Tensor &target, OptionalTensor weight, MyReduction reduction, int64_t ignore_index, Tensor &out) {
343
+ return torch::nll_loss_out(out, self, target, weight, reduction, ignore_index);
344
+ })
345
+ .define_singleton_method(
346
+ "_one_hot",
347
+ *[](const Tensor &self, int64_t num_classes) {
348
+ return torch::one_hot(self, num_classes);
349
+ })
350
+ .define_singleton_method(
351
+ "_reflection_pad1d",
352
+ *[](const Tensor &self, IntArrayRef padding) {
353
+ return torch::reflection_pad1d(self, padding);
354
+ })
355
+ .define_singleton_method(
356
+ "_reflection_pad1d_out",
357
+ *[](const Tensor &self, IntArrayRef padding, Tensor &out) {
358
+ return torch::reflection_pad1d_out(out, self, padding);
359
+ })
360
+ .define_singleton_method(
361
+ "_reflection_pad2d",
362
+ *[](const Tensor &self, IntArrayRef padding) {
363
+ return torch::reflection_pad2d(self, padding);
364
+ })
365
+ .define_singleton_method(
366
+ "_reflection_pad2d_out",
367
+ *[](const Tensor &self, IntArrayRef padding, Tensor &out) {
368
+ return torch::reflection_pad2d_out(out, self, padding);
369
+ })
370
+ .define_singleton_method(
371
+ "_replication_pad1d",
372
+ *[](const Tensor &self, IntArrayRef padding) {
373
+ return torch::replication_pad1d(self, padding);
374
+ })
375
+ .define_singleton_method(
376
+ "_replication_pad1d_out",
377
+ *[](const Tensor &self, IntArrayRef padding, Tensor &out) {
378
+ return torch::replication_pad1d_out(out, self, padding);
379
+ })
380
+ .define_singleton_method(
381
+ "_replication_pad2d",
382
+ *[](const Tensor &self, IntArrayRef padding) {
383
+ return torch::replication_pad2d(self, padding);
384
+ })
385
+ .define_singleton_method(
386
+ "_replication_pad2d_out",
387
+ *[](const Tensor &self, IntArrayRef padding, Tensor &out) {
388
+ return torch::replication_pad2d_out(out, self, padding);
389
+ })
390
+ .define_singleton_method(
391
+ "_replication_pad3d",
392
+ *[](const Tensor &self, IntArrayRef padding) {
393
+ return torch::replication_pad3d(self, padding);
394
+ })
395
+ .define_singleton_method(
396
+ "_replication_pad3d_out",
397
+ *[](const Tensor &self, IntArrayRef padding, Tensor &out) {
398
+ return torch::replication_pad3d_out(out, self, padding);
399
+ })
400
+ .define_singleton_method(
401
+ "_rrelu_with_noise",
402
+ *[](const Tensor &self, const Tensor &noise, Scalar lower, Scalar upper, bool training) {
403
+ return torch::rrelu_with_noise(self, noise, lower, upper, training);
404
+ })
405
+ .define_singleton_method(
406
+ "_rrelu_with_noise_",
407
+ *[](Tensor &self, const Tensor &noise, Scalar lower, Scalar upper, bool training) {
408
+ return torch::rrelu_with_noise_(self, noise, lower, upper, training);
409
+ })
410
+ .define_singleton_method(
411
+ "_rrelu_with_noise_out",
412
+ *[](const Tensor &self, const Tensor &noise, Scalar lower, Scalar upper, bool training, Tensor &out) {
413
+ return torch::rrelu_with_noise_out(out, self, noise, lower, upper, training);
414
+ })
415
+ .define_singleton_method(
416
+ "_slow_conv_dilated2d",
417
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation) {
418
+ return torch::slow_conv_dilated2d(self, weight, kernel_size, bias, stride, padding, dilation);
419
+ })
420
+ .define_singleton_method(
421
+ "_slow_conv_dilated3d",
422
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation) {
423
+ return torch::slow_conv_dilated3d(self, weight, kernel_size, bias, stride, padding, dilation);
424
+ })
425
+ .define_singleton_method(
426
+ "_slow_conv_transpose2d",
427
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef output_padding, IntArrayRef dilation) {
428
+ return torch::slow_conv_transpose2d(self, weight, kernel_size, bias, stride, padding, output_padding, dilation);
429
+ })
430
+ .define_singleton_method(
431
+ "_slow_conv_transpose2d_out",
432
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef output_padding, IntArrayRef dilation, Tensor &out) {
433
+ return torch::slow_conv_transpose2d_out(out, self, weight, kernel_size, bias, stride, padding, output_padding, dilation);
434
+ })
435
+ .define_singleton_method(
436
+ "_slow_conv_transpose3d",
437
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef output_padding, IntArrayRef dilation) {
438
+ return torch::slow_conv_transpose3d(self, weight, kernel_size, bias, stride, padding, output_padding, dilation);
439
+ })
440
+ .define_singleton_method(
441
+ "_slow_conv_transpose3d_out",
442
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef output_padding, IntArrayRef dilation, Tensor &out) {
443
+ return torch::slow_conv_transpose3d_out(out, self, weight, kernel_size, bias, stride, padding, output_padding, dilation);
444
+ })
445
+ .define_singleton_method(
446
+ "_smooth_l1_loss",
447
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction) {
448
+ return torch::smooth_l1_loss(self, target, reduction);
449
+ })
450
+ .define_singleton_method(
451
+ "_smooth_l1_loss_out",
452
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction, Tensor &out) {
453
+ return torch::smooth_l1_loss_out(out, self, target, reduction);
454
+ })
455
+ .define_singleton_method(
456
+ "_soft_margin_loss",
457
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction) {
458
+ return torch::soft_margin_loss(self, target, reduction);
459
+ })
460
+ .define_singleton_method(
461
+ "_soft_margin_loss_out",
462
+ *[](const Tensor &self, const Tensor &target, MyReduction reduction, Tensor &out) {
463
+ return torch::soft_margin_loss_out(out, self, target, reduction);
464
+ })
465
+ .define_singleton_method(
466
+ "_softplus",
467
+ *[](const Tensor &self, Scalar beta, Scalar threshold) {
468
+ return torch::softplus(self, beta, threshold);
469
+ })
470
+ .define_singleton_method(
471
+ "_softplus_out",
472
+ *[](const Tensor &self, Scalar beta, Scalar threshold, Tensor &out) {
473
+ return torch::softplus_out(out, self, beta, threshold);
474
+ })
475
+ .define_singleton_method(
476
+ "_softshrink",
477
+ *[](const Tensor &self, Scalar lambd) {
478
+ return torch::softshrink(self, lambd);
479
+ })
480
+ .define_singleton_method(
481
+ "_softshrink_out",
482
+ *[](const Tensor &self, Scalar lambd, Tensor &out) {
483
+ return torch::softshrink_out(out, self, lambd);
484
+ })
485
+ .define_singleton_method(
486
+ "_thnn_conv2d",
487
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding) {
488
+ return torch::thnn_conv2d(self, weight, kernel_size, bias, stride, padding);
489
+ })
490
+ .define_singleton_method(
491
+ "_thnn_conv2d_forward",
492
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding) {
493
+ return wrap(torch::thnn_conv2d_forward(self, weight, kernel_size, bias, stride, padding));
494
+ })
495
+ .define_singleton_method(
496
+ "_thnn_conv2d_forward_output",
497
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, Tensor &output, Tensor &finput, Tensor &fgrad_input) {
498
+ return wrap(torch::thnn_conv2d_forward_out(output, finput, fgrad_input, self, weight, kernel_size, bias, stride, padding));
499
+ })
500
+ .define_singleton_method(
501
+ "_thnn_conv2d_out",
502
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, Tensor &out) {
503
+ return torch::thnn_conv2d_out(out, self, weight, kernel_size, bias, stride, padding);
504
+ })
505
+ .define_singleton_method(
506
+ "_thnn_conv3d",
507
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding) {
508
+ return torch::thnn_conv3d(self, weight, kernel_size, bias, stride, padding);
509
+ })
510
+ .define_singleton_method(
511
+ "_thnn_conv3d_forward",
512
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding) {
513
+ return wrap(torch::thnn_conv3d_forward(self, weight, kernel_size, bias, stride, padding));
514
+ })
515
+ .define_singleton_method(
516
+ "_thnn_conv3d_forward_output",
517
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, Tensor &output, Tensor &finput, Tensor &fgrad_input) {
518
+ return wrap(torch::thnn_conv3d_forward_out(output, finput, fgrad_input, self, weight, kernel_size, bias, stride, padding));
519
+ })
520
+ .define_singleton_method(
521
+ "_thnn_conv3d_out",
522
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, Tensor &out) {
523
+ return torch::thnn_conv3d_out(out, self, weight, kernel_size, bias, stride, padding);
524
+ })
525
+ .define_singleton_method(
526
+ "_thnn_conv_depthwise2d",
527
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation) {
528
+ return torch::thnn_conv_depthwise2d(self, weight, kernel_size, bias, stride, padding, dilation);
529
+ })
530
+ .define_singleton_method(
531
+ "_thnn_conv_depthwise2d_forward",
532
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation) {
533
+ return torch::thnn_conv_depthwise2d_forward(self, weight, kernel_size, bias, stride, padding, dilation);
534
+ })
535
+ .define_singleton_method(
536
+ "_thnn_conv_depthwise2d_forward_out",
537
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, Tensor &out) {
538
+ return torch::thnn_conv_depthwise2d_forward_out(out, self, weight, kernel_size, bias, stride, padding, dilation);
539
+ })
540
+ .define_singleton_method(
541
+ "_thnn_conv_depthwise2d_out",
542
+ *[](const Tensor &self, const Tensor &weight, IntArrayRef kernel_size, OptionalTensor bias, IntArrayRef stride, IntArrayRef padding, IntArrayRef dilation, Tensor &out) {
543
+ return torch::thnn_conv_depthwise2d_out(out, self, weight, kernel_size, bias, stride, padding, dilation);
544
+ })
545
+ .define_singleton_method(
546
+ "_upsample_bicubic2d",
547
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners) {
548
+ return torch::upsample_bicubic2d(self, output_size, align_corners);
549
+ })
550
+ .define_singleton_method(
551
+ "_upsample_bicubic2d_out",
552
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners, Tensor &out) {
553
+ return torch::upsample_bicubic2d_out(out, self, output_size, align_corners);
554
+ })
555
+ .define_singleton_method(
556
+ "_upsample_bilinear2d",
557
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners) {
558
+ return torch::upsample_bilinear2d(self, output_size, align_corners);
559
+ })
560
+ .define_singleton_method(
561
+ "_upsample_bilinear2d_out",
562
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners, Tensor &out) {
563
+ return torch::upsample_bilinear2d_out(out, self, output_size, align_corners);
564
+ })
565
+ .define_singleton_method(
566
+ "_upsample_linear1d",
567
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners) {
568
+ return torch::upsample_linear1d(self, output_size, align_corners);
569
+ })
570
+ .define_singleton_method(
571
+ "_upsample_linear1d_out",
572
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners, Tensor &out) {
573
+ return torch::upsample_linear1d_out(out, self, output_size, align_corners);
574
+ })
575
+ .define_singleton_method(
576
+ "_upsample_nearest1d",
577
+ *[](const Tensor &self, IntArrayRef output_size) {
578
+ return torch::upsample_nearest1d(self, output_size);
579
+ })
580
+ .define_singleton_method(
581
+ "_upsample_nearest1d_out",
582
+ *[](const Tensor &self, IntArrayRef output_size, Tensor &out) {
583
+ return torch::upsample_nearest1d_out(out, self, output_size);
584
+ })
585
+ .define_singleton_method(
586
+ "_upsample_nearest2d",
587
+ *[](const Tensor &self, IntArrayRef output_size) {
588
+ return torch::upsample_nearest2d(self, output_size);
589
+ })
590
+ .define_singleton_method(
591
+ "_upsample_nearest2d_out",
592
+ *[](const Tensor &self, IntArrayRef output_size, Tensor &out) {
593
+ return torch::upsample_nearest2d_out(out, self, output_size);
594
+ })
595
+ .define_singleton_method(
596
+ "_upsample_nearest3d",
597
+ *[](const Tensor &self, IntArrayRef output_size) {
598
+ return torch::upsample_nearest3d(self, output_size);
599
+ })
600
+ .define_singleton_method(
601
+ "_upsample_nearest3d_out",
602
+ *[](const Tensor &self, IntArrayRef output_size, Tensor &out) {
603
+ return torch::upsample_nearest3d_out(out, self, output_size);
604
+ })
605
+ .define_singleton_method(
606
+ "_upsample_trilinear3d",
607
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners) {
608
+ return torch::upsample_trilinear3d(self, output_size, align_corners);
609
+ })
610
+ .define_singleton_method(
611
+ "_upsample_trilinear3d_out",
612
+ *[](const Tensor &self, IntArrayRef output_size, bool align_corners, Tensor &out) {
613
+ return torch::upsample_trilinear3d_out(out, self, output_size, align_corners);
614
+ });
615
+ }