src/api/native_tensor_audio_b.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // native_tensor_audio_b.cpp — the second half of the audio group (see | ||
| 2 | // native_tensor_audio.cpp for the first half): 1D padding, the conv1d / | ||
| 3 | // conv_transpose1d / causal-conv family, vocoder + codec activations, codec | ||
| 4 | // quantization, 1D resampling, log / exp / round elementwise maps and the | ||
| 5 | // autoregressive logit sampler, bound directly onto `bro.tensor`. | ||
| 6 | |||
| 7 | #include "api_internal.h" | ||
| 8 | |||
| 9 | #include <climits> | ||
| 10 | #include <cmath> | ||
| 11 | #include <cstdint> | ||
| 12 | #include <span> | ||
| 13 | #include <string> | ||
| 14 | |||
| 15 | namespace brotensor::api { | ||
| 16 | |||
| 17 | namespace { | ||
| 18 | |||
| 19 | namespace ev = bronze::embed; | ||
| 20 | using brotensor::Tensor; | ||
| 21 | |||
| 22 | 364 | int32_t argInt(ev::Value v, int32_t def = 0) { | |
| 23 | 364 | if (ev::isUndefined(v) || ev::isNull(v)) return def; | |
| 24 | 364 | double d = ev::toDouble(v); | |
| 25 | 364 | if (!std::isfinite(d) || d == 0.0) return 0; | |
| 26 | 324 | if (d >= -2147483648.0 && d <= 2147483647.0) { | |
| 27 | 324 | return static_cast<int32_t>(std::trunc(d)); | |
| 28 | } | ||
| 29 | ✗ | double m = std::fmod(std::trunc(d), 4294967296.0); | |
| 30 | ✗ | if (m >= 2147483648.0) m -= 4294967296.0; | |
| 31 | ✗ | else if (m < -2147483648.0) m += 4294967296.0; | |
| 32 | ✗ | return static_cast<int32_t>(m); | |
| 33 | 364 | } | |
| 34 | |||
| 35 | 28 | double argNum(ev::Value v, double def = 0.0) { | |
| 36 | 28 | if (ev::isUndefined(v) || ev::isNull(v)) return def; | |
| 37 | 28 | return ev::toDouble(v); | |
| 38 | 28 | } | |
| 39 | |||
| 40 | // conv1d is conv2d with H = kH = 1, and conv2d's device kernels trust the | ||
| 41 | // caller's dims, so the operand extents are checked here. Computes L_out. | ||
| 42 | 16 | void conv1dGeom(const char* L, int32_t N, int32_t C_in, int32_t Lin, int32_t C_out, int32_t kL, | |
| 43 | int32_t stride, int32_t padding, int32_t dilation, int32_t groups, int64_t& L_out) { | ||
| 44 | 16 | int64_t H_out = 0; | |
| 45 | 16 | needNonNegative(L, {N}); | |
| 46 | 16 | convGeom2d(L, C_in, C_out, 1, Lin, 1, kL, 1, stride, 0, padding, 1, dilation, groups, H_out, L_out); | |
| 47 | 16 | } | |
| 48 | |||
| 49 | // The conv1d filter is OIL: (C_out, (C_in/groups)*kL). | ||
| 50 | 14 | int64_t conv1dWeightElems(int32_t C_in, int32_t C_out, int32_t kL, int32_t groups) { | |
| 51 | 14 | return elems({C_out, C_in / groups, kL}); | |
| 52 | } | ||
| 53 | |||
| 54 | // ─── 1D padding ──────────────────────────────────────────────────────────── | ||
| 55 | |||
| 56 | 6 | ev::Value jsPad1dForward(ev::Value, std::span<const ev::Value> args) { | |
| 57 | 6 | const char* L = "pad1dForward"; | |
| 58 | 6 | Tensor* x = requireTensor(arg(args, 0), L, "X"); | |
| 59 | 6 | int32_t N = argInt(arg(args, 1), 1); | |
| 60 | 6 | int32_t C = argInt(arg(args, 2), 1); | |
| 61 | 6 | int32_t len = argInt(arg(args, 3), 0); | |
| 62 | 6 | int32_t padLeft = argInt(arg(args, 4), 0); | |
| 63 | 6 | int32_t padRight = argInt(arg(args, 5), 0); | |
| 64 | 6 | int32_t mode = argInt(arg(args, 6), 0); | |
| 65 | 6 | Tensor* y = requireTensor(arg(args, 7), L, "Y"); | |
| 66 | 6 | BROTENSOR_API_TRY | |
| 67 | 6 | brotensor::pad1d_forward(*x, N, C, len, padLeft, padRight, mode, *y); | |
| 68 | 6 | BROTENSOR_API_CATCH(L) | |
| 69 | 6 | return ev::undefined(); | |
| 70 | ✗ | } | |
| 71 | |||
| 72 | 2 | ev::Value jsPad1dBackward(ev::Value, std::span<const ev::Value> args) { | |
| 73 | 2 | const char* L = "pad1dBackward"; | |
| 74 | 2 | Tensor* dY = requireTensor(arg(args, 0), L, "dY"); | |
| 75 | 2 | int32_t N = argInt(arg(args, 1), 1); | |
| 76 | 2 | int32_t C = argInt(arg(args, 2), 1); | |
| 77 | 2 | int32_t len = argInt(arg(args, 3), 0); | |
| 78 | 2 | int32_t padLeft = argInt(arg(args, 4), 0); | |
| 79 | 2 | int32_t padRight = argInt(arg(args, 5), 0); | |
| 80 | 2 | int32_t mode = argInt(arg(args, 6), 0); | |
| 81 | 2 | Tensor* dX = requireTensor(arg(args, 7), L, "dX"); | |
| 82 | 2 | BROTENSOR_API_TRY | |
| 83 | 2 | brotensor::pad1d_backward(*dY, N, C, len, padLeft, padRight, mode, *dX); | |
| 84 | 2 | BROTENSOR_API_CATCH(L) | |
| 85 | 2 | return ev::undefined(); | |
| 86 | ✗ | } | |
| 87 | |||
| 88 | // ─── conv1d family (NCL) ─────────────────────────────────────────────────── | ||
| 89 | |||
| 90 | 4 | ev::Value jsConv1d(ev::Value, std::span<const ev::Value> args) { | |
| 91 | 4 | const char* Lb = "conv1d"; | |
| 92 | 4 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 93 | 4 | Tensor* wt = requireTensor(arg(args, 1), Lb, "Wt"); | |
| 94 | 4 | Tensor* bias = optionalTensor(arg(args, 2), Lb, "bias"); | |
| 95 | 4 | int32_t N = argInt(arg(args, 3), 1); | |
| 96 | 4 | int32_t C_in = argInt(arg(args, 4), 1); | |
| 97 | 4 | int32_t len = argInt(arg(args, 5), 0); | |
| 98 | 4 | int32_t C_out = argInt(arg(args, 6), 1); | |
| 99 | 4 | int32_t kL = argInt(arg(args, 7), 1); | |
| 100 | 4 | int32_t stride = argInt(arg(args, 8), 1); | |
| 101 | 4 | int32_t padding = argInt(arg(args, 9), 0); | |
| 102 | 4 | int32_t dilation = argInt(arg(args, 10), 1); | |
| 103 | 4 | int32_t groups = argInt(arg(args, 11), 1); | |
| 104 | 4 | Tensor* y = requireTensor(arg(args, 12), Lb, "Y"); | |
| 105 | 4 | int64_t L_out = 0; | |
| 106 | 4 | conv1dGeom(Lb, N, C_in, len, C_out, kL, stride, padding, dilation, groups, L_out); | |
| 107 | 16 | needOperands(Lb, x, { | |
| 108 | 4 | {"X", x, elems({N, C_in, len})}, | |
| 109 | 4 | {"Wt", wt, conv1dWeightElems(C_in, C_out, kL, groups)}, | |
| 110 | 4 | {"bias", bias, C_out}, | |
| 111 | }); | ||
| 112 | 4 | BROTENSOR_API_TRY | |
| 113 | 4 | brotensor::conv1d( | |
| 114 | 4 | *x, *wt, bias, N, C_in, len, C_out, kL, stride, padding, dilation, groups, *y); | |
| 115 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 116 | 4 | return ev::undefined(); | |
| 117 | ✗ | } | |
| 118 | |||
| 119 | 2 | ev::Value jsConv1dBackwardInput(ev::Value, std::span<const ev::Value> args) { | |
| 120 | 2 | const char* Lb = "conv1dBackwardInput"; | |
| 121 | 2 | Tensor* wt = requireTensor(arg(args, 0), Lb, "Wt"); | |
| 122 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 123 | 2 | int32_t N = argInt(arg(args, 2), 1); | |
| 124 | 2 | int32_t C_in = argInt(arg(args, 3), 1); | |
| 125 | 2 | int32_t len = argInt(arg(args, 4), 0); | |
| 126 | 2 | int32_t C_out = argInt(arg(args, 5), 1); | |
| 127 | 2 | int32_t kL = argInt(arg(args, 6), 1); | |
| 128 | 2 | int32_t stride = argInt(arg(args, 7), 1); | |
| 129 | 2 | int32_t padding = argInt(arg(args, 8), 0); | |
| 130 | 2 | int32_t dilation = argInt(arg(args, 9), 1); | |
| 131 | 2 | int32_t groups = argInt(arg(args, 10), 1); | |
| 132 | 2 | Tensor* dX = requireTensor(arg(args, 11), Lb, "dX"); | |
| 133 | 2 | int64_t L_out = 0; | |
| 134 | 2 | conv1dGeom(Lb, N, C_in, len, C_out, kL, stride, padding, dilation, groups, L_out); | |
| 135 | 6 | needOperands(Lb, dY, { | |
| 136 | 2 | {"dY", dY, elems({N, C_out, L_out})}, | |
| 137 | 2 | {"Wt", wt, conv1dWeightElems(C_in, C_out, kL, groups)}, | |
| 138 | }); | ||
| 139 | 2 | BROTENSOR_API_TRY | |
| 140 | 2 | brotensor::conv1d_backward_input( | |
| 141 | 2 | *wt, *dY, N, C_in, len, C_out, kL, stride, padding, dilation, groups, *dX); | |
| 142 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 143 | 2 | return ev::undefined(); | |
| 144 | ✗ | } | |
| 145 | |||
| 146 | 2 | ev::Value jsConv1dBackwardWeight(ev::Value, std::span<const ev::Value> args) { | |
| 147 | 2 | const char* Lb = "conv1dBackwardWeight"; | |
| 148 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 149 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 150 | 2 | int32_t N = argInt(arg(args, 2), 1); | |
| 151 | 2 | int32_t C_in = argInt(arg(args, 3), 1); | |
| 152 | 2 | int32_t len = argInt(arg(args, 4), 0); | |
| 153 | 2 | int32_t C_out = argInt(arg(args, 5), 1); | |
| 154 | 2 | int32_t kL = argInt(arg(args, 6), 1); | |
| 155 | 2 | int32_t stride = argInt(arg(args, 7), 1); | |
| 156 | 2 | int32_t padding = argInt(arg(args, 8), 0); | |
| 157 | 2 | int32_t dilation = argInt(arg(args, 9), 1); | |
| 158 | 2 | int32_t groups = argInt(arg(args, 10), 1); | |
| 159 | 2 | Tensor* dWt = requireTensor(arg(args, 11), Lb, "dWt"); | |
| 160 | 2 | int64_t L_out = 0; | |
| 161 | 2 | conv1dGeom(Lb, N, C_in, len, C_out, kL, stride, padding, dilation, groups, L_out); | |
| 162 | // dWt accumulates — "caller zeros". | ||
| 163 | 8 | needOperands(Lb, x, { | |
| 164 | 2 | {"X", x, elems({N, C_in, len})}, | |
| 165 | 2 | {"dY", dY, elems({N, C_out, L_out})}, | |
| 166 | 2 | {"dWt", dWt, conv1dWeightElems(C_in, C_out, kL, groups)}, | |
| 167 | }); | ||
| 168 | 2 | BROTENSOR_API_TRY | |
| 169 | 2 | brotensor::conv1d_backward_weight( | |
| 170 | 2 | *x, *dY, N, C_in, len, C_out, kL, stride, padding, dilation, groups, *dWt); | |
| 171 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 172 | 2 | return ev::undefined(); | |
| 173 | ✗ | } | |
| 174 | |||
| 175 | 2 | ev::Value jsConv1dBackwardBias(ev::Value, std::span<const ev::Value> args) { | |
| 176 | 2 | const char* Lb = "conv1dBackwardBias"; | |
| 177 | 2 | Tensor* dY = requireTensor(arg(args, 0), Lb, "dY"); | |
| 178 | 2 | int32_t N = argInt(arg(args, 1), 1); | |
| 179 | 2 | int32_t C_out = argInt(arg(args, 2), 1); | |
| 180 | 2 | int32_t L_out = argInt(arg(args, 3), 0); | |
| 181 | 2 | Tensor* dB = requireTensor(arg(args, 4), Lb, "dB"); | |
| 182 | 2 | needNonNegative(Lb, {N, C_out, L_out}); | |
| 183 | 2 | needOperands(Lb, dY, {{"dY", dY, elems({N, C_out, L_out})}, {"dB", dB, C_out}}); | |
| 184 | 2 | BROTENSOR_API_TRY | |
| 185 | 2 | brotensor::conv1d_backward_bias(*dY, N, C_out, L_out, *dB); | |
| 186 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 187 | 2 | return ev::undefined(); | |
| 188 | ✗ | } | |
| 189 | |||
| 190 | 2 | ev::Value jsConv1dInt8wFp16(ev::Value, std::span<const ev::Value> args) { | |
| 191 | 2 | const char* Lb = "conv1dInt8wFp16"; | |
| 192 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 193 | 2 | Tensor* wInt8 = requireTensor(arg(args, 1), Lb, "W_int8"); | |
| 194 | 2 | Tensor* scales = requireTensor(arg(args, 2), Lb, "scales"); | |
| 195 | 2 | Tensor* bias = optionalTensor(arg(args, 3), Lb, "bias"); | |
| 196 | 2 | int32_t N = argInt(arg(args, 4), 1); | |
| 197 | 2 | int32_t C_in = argInt(arg(args, 5), 1); | |
| 198 | 2 | int32_t len = argInt(arg(args, 6), 0); | |
| 199 | 2 | int32_t C_out = argInt(arg(args, 7), 1); | |
| 200 | 2 | int32_t kL = argInt(arg(args, 8), 1); | |
| 201 | 2 | int32_t stride = argInt(arg(args, 9), 1); | |
| 202 | 2 | int32_t padding = argInt(arg(args, 10), 0); | |
| 203 | 2 | int32_t dilation = argInt(arg(args, 11), 1); | |
| 204 | 2 | int32_t groups = argInt(arg(args, 12), 1); | |
| 205 | 2 | Tensor* y = requireTensor(arg(args, 13), Lb, "Y"); | |
| 206 | 2 | int64_t L_out = 0; | |
| 207 | 2 | conv1dGeom(Lb, N, C_in, len, C_out, kL, stride, padding, dilation, groups, L_out); | |
| 208 | 2 | needOperands(Lb, x, {{"X", x, elems({N, C_in, len})}, {"bias", bias, C_out}}); | |
| 209 | 2 | BROTENSOR_API_TRY | |
| 210 | 2 | brotensor::conv1d_int8w_fp16( | |
| 211 | 2 | *x, *wInt8, *scales, bias, N, C_in, len, C_out, kL, | |
| 212 | 2 | stride, padding, dilation, groups, *y); | |
| 213 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 214 | 2 | return ev::undefined(); | |
| 215 | ✗ | } | |
| 216 | |||
| 217 | 2 | ev::Value jsConvTranspose1dForward(ev::Value, std::span<const ev::Value> args) { | |
| 218 | 2 | const char* Lb = "convTranspose1dForward"; | |
| 219 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 220 | 2 | Tensor* wt = requireTensor(arg(args, 1), Lb, "Wt"); | |
| 221 | 2 | Tensor* bias = optionalTensor(arg(args, 2), Lb, "bias"); | |
| 222 | 2 | int32_t N = argInt(arg(args, 3), 1); | |
| 223 | 2 | int32_t C_in = argInt(arg(args, 4), 1); | |
| 224 | 2 | int32_t len = argInt(arg(args, 5), 0); | |
| 225 | 2 | int32_t C_out = argInt(arg(args, 6), 1); | |
| 226 | 2 | int32_t kL = argInt(arg(args, 7), 1); | |
| 227 | 2 | int32_t stride = argInt(arg(args, 8), 1); | |
| 228 | 2 | int32_t padding = argInt(arg(args, 9), 0); | |
| 229 | 2 | int32_t outputPadding = argInt(arg(args, 10), 0); | |
| 230 | 2 | int32_t dilation = argInt(arg(args, 11), 1); | |
| 231 | 2 | int32_t groups = argInt(arg(args, 12), 1); | |
| 232 | 2 | Tensor* y = requireTensor(arg(args, 13), Lb, "Y"); | |
| 233 | 2 | needNonNegative(Lb, {N, C_in, len}); | |
| 234 | 2 | needElems(Lb, "X", x, elems({N, C_in, len})); | |
| 235 | 2 | BROTENSOR_API_TRY | |
| 236 | 2 | brotensor::conv_transpose1d_forward( | |
| 237 | 2 | *x, *wt, bias, N, C_in, len, C_out, kL, | |
| 238 | 2 | stride, padding, outputPadding, dilation, groups, *y); | |
| 239 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 240 | 2 | return ev::undefined(); | |
| 241 | ✗ | } | |
| 242 | |||
| 243 | 2 | ev::Value jsConvTranspose1dBackwardInput(ev::Value, std::span<const ev::Value> args) { | |
| 244 | 2 | const char* Lb = "convTranspose1dBackwardInput"; | |
| 245 | 2 | Tensor* wt = requireTensor(arg(args, 0), Lb, "Wt"); | |
| 246 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 247 | 2 | int32_t N = argInt(arg(args, 2), 1); | |
| 248 | 2 | int32_t C_in = argInt(arg(args, 3), 1); | |
| 249 | 2 | int32_t len = argInt(arg(args, 4), 0); | |
| 250 | 2 | int32_t C_out = argInt(arg(args, 5), 1); | |
| 251 | 2 | int32_t kL = argInt(arg(args, 6), 1); | |
| 252 | 2 | int32_t stride = argInt(arg(args, 7), 1); | |
| 253 | 2 | int32_t padding = argInt(arg(args, 8), 0); | |
| 254 | 2 | int32_t outputPadding = argInt(arg(args, 9), 0); | |
| 255 | 2 | int32_t dilation = argInt(arg(args, 10), 1); | |
| 256 | 2 | int32_t groups = argInt(arg(args, 11), 1); | |
| 257 | 2 | Tensor* dX = requireTensor(arg(args, 12), Lb, "dX"); | |
| 258 | 2 | BROTENSOR_API_TRY | |
| 259 | 2 | brotensor::conv_transpose1d_backward_input( | |
| 260 | 2 | *wt, *dY, N, C_in, len, C_out, kL, | |
| 261 | 2 | stride, padding, outputPadding, dilation, groups, *dX); | |
| 262 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 263 | 2 | return ev::undefined(); | |
| 264 | ✗ | } | |
| 265 | |||
| 266 | 2 | ev::Value jsConvTranspose1dBackwardWeight(ev::Value, std::span<const ev::Value> args) { | |
| 267 | 2 | const char* Lb = "convTranspose1dBackwardWeight"; | |
| 268 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 269 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 270 | 2 | int32_t N = argInt(arg(args, 2), 1); | |
| 271 | 2 | int32_t C_in = argInt(arg(args, 3), 1); | |
| 272 | 2 | int32_t len = argInt(arg(args, 4), 0); | |
| 273 | 2 | int32_t C_out = argInt(arg(args, 5), 1); | |
| 274 | 2 | int32_t kL = argInt(arg(args, 6), 1); | |
| 275 | 2 | int32_t stride = argInt(arg(args, 7), 1); | |
| 276 | 2 | int32_t padding = argInt(arg(args, 8), 0); | |
| 277 | 2 | int32_t outputPadding = argInt(arg(args, 9), 0); | |
| 278 | 2 | int32_t dilation = argInt(arg(args, 10), 1); | |
| 279 | 2 | int32_t groups = argInt(arg(args, 11), 1); | |
| 280 | 2 | Tensor* dWt = requireTensor(arg(args, 12), Lb, "dWt"); | |
| 281 | 2 | BROTENSOR_API_TRY | |
| 282 | 2 | brotensor::conv_transpose1d_backward_weight( | |
| 283 | 2 | *x, *dY, N, C_in, len, C_out, kL, | |
| 284 | 2 | stride, padding, outputPadding, dilation, groups, *dWt); | |
| 285 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 286 | 2 | return ev::undefined(); | |
| 287 | ✗ | } | |
| 288 | |||
| 289 | 2 | ev::Value jsConvTranspose1dBackwardBias(ev::Value, std::span<const ev::Value> args) { | |
| 290 | 2 | const char* Lb = "convTranspose1dBackwardBias"; | |
| 291 | 2 | Tensor* dY = requireTensor(arg(args, 0), Lb, "dY"); | |
| 292 | 2 | int32_t N = argInt(arg(args, 1), 1); | |
| 293 | 2 | int32_t C_out = argInt(arg(args, 2), 1); | |
| 294 | 2 | int32_t L_out = argInt(arg(args, 3), 0); | |
| 295 | 2 | Tensor* dB = requireTensor(arg(args, 4), Lb, "dB"); | |
| 296 | 2 | BROTENSOR_API_TRY | |
| 297 | 2 | brotensor::conv_transpose1d_backward_bias(*dY, N, C_out, L_out, *dB); | |
| 298 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 299 | 2 | return ev::undefined(); | |
| 300 | ✗ | } | |
| 301 | |||
| 302 | 2 | ev::Value jsCausalConv1d(ev::Value, std::span<const ev::Value> args) { | |
| 303 | 2 | const char* Lb = "causalConv1d"; | |
| 304 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 305 | 2 | Tensor* wt = requireTensor(arg(args, 1), Lb, "Wt"); | |
| 306 | 2 | Tensor* bias = optionalTensor(arg(args, 2), Lb, "bias"); | |
| 307 | 2 | int32_t N = argInt(arg(args, 3), 1); | |
| 308 | 2 | int32_t C_in = argInt(arg(args, 4), 1); | |
| 309 | 2 | int32_t len = argInt(arg(args, 5), 0); | |
| 310 | 2 | int32_t C_out = argInt(arg(args, 6), 1); | |
| 311 | 2 | int32_t kL = argInt(arg(args, 7), 1); | |
| 312 | 2 | int32_t stride = argInt(arg(args, 8), 1); | |
| 313 | 2 | int32_t dilation = argInt(arg(args, 9), 1); | |
| 314 | 2 | int32_t groups = argInt(arg(args, 10), 1); | |
| 315 | 2 | Tensor* scratch = requireTensor(arg(args, 11), Lb, "scratch"); | |
| 316 | 2 | Tensor* y = requireTensor(arg(args, 12), Lb, "Y"); | |
| 317 | 2 | needPositive(Lb, {kL, dilation}); | |
| 318 | 2 | const int64_t padded = static_cast<int64_t>(len) + static_cast<int64_t>(dilation) * (kL - 1); | |
| 319 | 2 | if (padded > INT32_MAX) { | |
| 320 | ✗ | setError("causalConv1d: L + dilation*(kL-1) overflows"); | |
| 321 | } | ||
| 322 | 2 | int64_t L_out = 0; | |
| 323 | 2 | conv1dGeom(Lb, N, C_in, static_cast<int32_t>(padded), C_out, kL, stride, 0, dilation, groups, L_out); | |
| 324 | 8 | needOperands(Lb, x, { | |
| 325 | 2 | {"X", x, elems({N, C_in, len})}, | |
| 326 | 2 | {"Wt", wt, conv1dWeightElems(C_in, C_out, kL, groups)}, | |
| 327 | 2 | {"bias", bias, C_out}, | |
| 328 | }); | ||
| 329 | 2 | BROTENSOR_API_TRY | |
| 330 | 2 | brotensor::causal_conv1d( | |
| 331 | 2 | *x, *wt, bias, N, C_in, len, C_out, kL, stride, dilation, groups, *scratch, *y); | |
| 332 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 333 | 2 | return ev::undefined(); | |
| 334 | ✗ | } | |
| 335 | |||
| 336 | 4 | ev::Value jsCausalConv1dUpdate(ev::Value, std::span<const ev::Value> args) { | |
| 337 | 4 | const char* Lb = "causalConv1dUpdate"; | |
| 338 | 4 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 339 | 4 | Tensor* wt = requireTensor(arg(args, 1), Lb, "Wt"); | |
| 340 | 4 | Tensor* bias = optionalTensor(arg(args, 2), Lb, "bias"); | |
| 341 | 4 | int32_t N = argInt(arg(args, 3), 1); | |
| 342 | 4 | int32_t C = argInt(arg(args, 4), 1); | |
| 343 | 4 | int32_t L_step = argInt(arg(args, 5), 0); | |
| 344 | 4 | int32_t kL = argInt(arg(args, 6), 1); | |
| 345 | 4 | int32_t dilation = argInt(arg(args, 7), 1); | |
| 346 | 4 | Tensor* state = requireTensor(arg(args, 8), Lb, "state"); | |
| 347 | 4 | Tensor* y = requireTensor(arg(args, 9), Lb, "Y"); | |
| 348 | 4 | BROTENSOR_API_TRY | |
| 349 | 4 | brotensor::causal_conv1d_update(*x, *wt, bias, N, C, L_step, kL, dilation, *state, *y); | |
| 350 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 351 | 4 | return ev::undefined(); | |
| 352 | ✗ | } | |
| 353 | |||
| 354 | // ─── Vocoder / codec activations ─────────────────────────────────────────── | ||
| 355 | |||
| 356 | 4 | ev::Value jsSnakeForward(ev::Value, std::span<const ev::Value> args) { | |
| 357 | 4 | const char* Lb = "snakeForward"; | |
| 358 | 4 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 359 | 4 | Tensor* alpha = requireTensor(arg(args, 1), Lb, "alpha"); | |
| 360 | 4 | Tensor* beta = optionalTensor(arg(args, 2), Lb, "beta"); | |
| 361 | 4 | int32_t N = argInt(arg(args, 3), 1); | |
| 362 | 4 | int32_t C = argInt(arg(args, 4), 1); | |
| 363 | 4 | int32_t len = argInt(arg(args, 5), 0); | |
| 364 | 4 | Tensor* y = requireTensor(arg(args, 6), Lb, "Y"); | |
| 365 | 4 | BROTENSOR_API_TRY | |
| 366 | 4 | brotensor::snake_forward(*x, *alpha, beta, N, C, len, *y); | |
| 367 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 368 | 4 | return ev::undefined(); | |
| 369 | ✗ | } | |
| 370 | |||
| 371 | 4 | ev::Value jsSnakeBackward(ev::Value, std::span<const ev::Value> args) { | |
| 372 | 4 | const char* Lb = "snakeBackward"; | |
| 373 | 4 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 374 | 4 | Tensor* alpha = requireTensor(arg(args, 1), Lb, "alpha"); | |
| 375 | 4 | Tensor* beta = optionalTensor(arg(args, 2), Lb, "beta"); | |
| 376 | 4 | Tensor* dY = requireTensor(arg(args, 3), Lb, "dY"); | |
| 377 | 4 | int32_t N = argInt(arg(args, 4), 1); | |
| 378 | 4 | int32_t C = argInt(arg(args, 5), 1); | |
| 379 | 4 | int32_t len = argInt(arg(args, 6), 0); | |
| 380 | 4 | Tensor* dX = requireTensor(arg(args, 7), Lb, "dX"); | |
| 381 | 4 | Tensor* dAlpha = requireTensor(arg(args, 8), Lb, "dAlpha"); | |
| 382 | 4 | Tensor* dBeta = optionalTensor(arg(args, 9), Lb, "dBeta"); | |
| 383 | 4 | BROTENSOR_API_TRY | |
| 384 | 4 | brotensor::snake_backward(*x, *alpha, beta, *dY, N, C, len, *dX, *dAlpha, dBeta); | |
| 385 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 386 | 4 | return ev::undefined(); | |
| 387 | ✗ | } | |
| 388 | |||
| 389 | 4 | ev::Value jsEluForward(ev::Value, std::span<const ev::Value> args) { | |
| 390 | 4 | const char* Lb = "eluForward"; | |
| 391 | 4 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 392 | 4 | double alpha = argNum(arg(args, 1), 1.0); | |
| 393 | 4 | Tensor* y = requireTensor(arg(args, 2), Lb, "y"); | |
| 394 | 4 | BROTENSOR_API_TRY | |
| 395 | 4 | brotensor::elu_forward(*x, static_cast<float>(alpha), *y); | |
| 396 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 397 | 4 | return ev::undefined(); | |
| 398 | ✗ | } | |
| 399 | |||
| 400 | 2 | ev::Value jsEluBackward(ev::Value, std::span<const ev::Value> args) { | |
| 401 | 2 | const char* Lb = "eluBackward"; | |
| 402 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 403 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 404 | 2 | double alpha = argNum(arg(args, 2), 1.0); | |
| 405 | 2 | Tensor* dX = requireTensor(arg(args, 3), Lb, "dX"); | |
| 406 | 2 | needPair(Lb, "dY", dY, x); | |
| 407 | 2 | BROTENSOR_API_TRY | |
| 408 | 2 | brotensor::elu_backward(*x, *dY, static_cast<float>(alpha), *dX); | |
| 409 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 410 | 2 | return ev::undefined(); | |
| 411 | ✗ | } | |
| 412 | |||
| 413 | 2 | ev::Value jsLeakyReluForward(ev::Value, std::span<const ev::Value> args) { | |
| 414 | 2 | const char* Lb = "leakyReluForward"; | |
| 415 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 416 | 2 | double negativeSlope = argNum(arg(args, 1), 0.01); | |
| 417 | 2 | Tensor* y = requireTensor(arg(args, 2), Lb, "y"); | |
| 418 | 2 | BROTENSOR_API_TRY | |
| 419 | 2 | brotensor::leaky_relu_forward(*x, static_cast<float>(negativeSlope), *y); | |
| 420 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 421 | 2 | return ev::undefined(); | |
| 422 | ✗ | } | |
| 423 | |||
| 424 | 2 | ev::Value jsLeakyReluBackward(ev::Value, std::span<const ev::Value> args) { | |
| 425 | 2 | const char* Lb = "leakyReluBackward"; | |
| 426 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 427 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 428 | 2 | double negativeSlope = argNum(arg(args, 2), 0.01); | |
| 429 | 2 | Tensor* dX = requireTensor(arg(args, 3), Lb, "dX"); | |
| 430 | 2 | needPair(Lb, "dY", dY, x); | |
| 431 | 2 | BROTENSOR_API_TRY | |
| 432 | 2 | brotensor::leaky_relu_backward(*x, *dY, static_cast<float>(negativeSlope), *dX); | |
| 433 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 434 | 2 | return ev::undefined(); | |
| 435 | ✗ | } | |
| 436 | |||
| 437 | // ─── Codec quantization ──────────────────────────────────────────────────── | ||
| 438 | |||
| 439 | 2 | ev::Value jsVqEncodeForward(ev::Value, std::span<const ev::Value> args) { | |
| 440 | 2 | const char* Lb = "vqEncodeForward"; | |
| 441 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 442 | 2 | Tensor* codebook = requireTensor(arg(args, 1), Lb, "codebook"); | |
| 443 | 2 | Tensor* indices = requireTensor(arg(args, 2), Lb, "indices"); | |
| 444 | 2 | Tensor* quantized = requireTensor(arg(args, 3), Lb, "quantized"); | |
| 445 | 2 | BROTENSOR_API_TRY | |
| 446 | 2 | brotensor::vq_encode_forward(*x, *codebook, *indices, *quantized); | |
| 447 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 448 | 2 | return ev::undefined(); | |
| 449 | ✗ | } | |
| 450 | |||
| 451 | 2 | ev::Value jsVqEncodeBackward(ev::Value, std::span<const ev::Value> args) { | |
| 452 | 2 | const char* Lb = "vqEncodeBackward"; | |
| 453 | 2 | Tensor* dQuantized = requireTensor(arg(args, 0), Lb, "dQuantized"); | |
| 454 | 2 | Tensor* dX = requireTensor(arg(args, 1), Lb, "dX"); | |
| 455 | 2 | BROTENSOR_API_TRY | |
| 456 | 2 | brotensor::vq_encode_backward(*dQuantized, *dX); | |
| 457 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 458 | 2 | return ev::undefined(); | |
| 459 | ✗ | } | |
| 460 | |||
| 461 | 2 | ev::Value jsFsqQuantizeForward(ev::Value, std::span<const ev::Value> args) { | |
| 462 | 2 | const char* Lb = "fsqQuantizeForward"; | |
| 463 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 464 | 2 | Tensor* levels = requireTensor(arg(args, 1), Lb, "levels"); | |
| 465 | 2 | Tensor* quantized = requireTensor(arg(args, 2), Lb, "quantized"); | |
| 466 | 2 | Tensor* packedIndices = requireTensor(arg(args, 3), Lb, "packedIndices"); | |
| 467 | 2 | BROTENSOR_API_TRY | |
| 468 | 2 | brotensor::fsq_quantize_forward(*x, *levels, *quantized, *packedIndices); | |
| 469 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 470 | 2 | return ev::undefined(); | |
| 471 | ✗ | } | |
| 472 | |||
| 473 | 2 | ev::Value jsFsqQuantizeBackward(ev::Value, std::span<const ev::Value> args) { | |
| 474 | 2 | const char* Lb = "fsqQuantizeBackward"; | |
| 475 | 2 | Tensor* dQuantized = requireTensor(arg(args, 0), Lb, "dQuantized"); | |
| 476 | 2 | Tensor* dX = requireTensor(arg(args, 1), Lb, "dX"); | |
| 477 | 2 | BROTENSOR_API_TRY | |
| 478 | 2 | brotensor::fsq_quantize_backward(*dQuantized, *dX); | |
| 479 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 480 | 2 | return ev::undefined(); | |
| 481 | ✗ | } | |
| 482 | |||
| 483 | // ─── 1D resampling ───────────────────────────────────────────────────────── | ||
| 484 | |||
| 485 | 4 | ev::Value jsResample1dForward(ev::Value, std::span<const ev::Value> args) { | |
| 486 | 4 | const char* Lb = "resample1dForward"; | |
| 487 | 4 | Tensor* x = requireTensor(arg(args, 0), Lb, "X"); | |
| 488 | 4 | int32_t N = argInt(arg(args, 1), 1); | |
| 489 | 4 | int32_t C = argInt(arg(args, 2), 1); | |
| 490 | 4 | int32_t L_in = argInt(arg(args, 3), 0); | |
| 491 | 4 | int32_t L_out = argInt(arg(args, 4), 0); | |
| 492 | 4 | int32_t mode = argInt(arg(args, 5), 0); | |
| 493 | 4 | Tensor* y = requireTensor(arg(args, 6), Lb, "Y"); | |
| 494 | 4 | needNonNegative(Lb, {N, C, L_in, L_out}); | |
| 495 | 4 | needElems(Lb, "X", x, elems({N, C, L_in})); | |
| 496 | 4 | BROTENSOR_API_TRY | |
| 497 | 4 | brotensor::resample1d_forward(*x, N, C, L_in, L_out, mode, *y); | |
| 498 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 499 | 4 | return ev::undefined(); | |
| 500 | ✗ | } | |
| 501 | |||
| 502 | 4 | ev::Value jsResample1dBackward(ev::Value, std::span<const ev::Value> args) { | |
| 503 | 4 | const char* Lb = "resample1dBackward"; | |
| 504 | 4 | Tensor* dY = requireTensor(arg(args, 0), Lb, "dY"); | |
| 505 | 4 | int32_t N = argInt(arg(args, 1), 1); | |
| 506 | 4 | int32_t C = argInt(arg(args, 2), 1); | |
| 507 | 4 | int32_t L_in = argInt(arg(args, 3), 0); | |
| 508 | 4 | int32_t L_out = argInt(arg(args, 4), 0); | |
| 509 | 4 | int32_t mode = argInt(arg(args, 5), 0); | |
| 510 | 4 | Tensor* dX = requireTensor(arg(args, 6), Lb, "dX"); | |
| 511 | 4 | needNonNegative(Lb, {N, C, L_in, L_out}); | |
| 512 | 4 | needElems(Lb, "dY", dY, elems({N, C, L_out})); | |
| 513 | 4 | BROTENSOR_API_TRY | |
| 514 | 4 | brotensor::resample1d_backward(*dY, N, C, L_in, L_out, mode, *dX); | |
| 515 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 516 | 4 | return ev::undefined(); | |
| 517 | ✗ | } | |
| 518 | |||
| 519 | // ─── log / exp / round elementwise ───────────────────────────────────────── | ||
| 520 | |||
| 521 | 2 | ev::Value jsLogForward(ev::Value, std::span<const ev::Value> args) { | |
| 522 | 2 | const char* Lb = "logForward"; | |
| 523 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 524 | 2 | Tensor* y = requireTensor(arg(args, 1), Lb, "y"); | |
| 525 | 2 | BROTENSOR_API_TRY | |
| 526 | 2 | brotensor::log_forward(*x, *y); | |
| 527 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 528 | 2 | return ev::undefined(); | |
| 529 | ✗ | } | |
| 530 | |||
| 531 | 2 | ev::Value jsLogBackward(ev::Value, std::span<const ev::Value> args) { | |
| 532 | 2 | const char* Lb = "logBackward"; | |
| 533 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 534 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 535 | 2 | Tensor* dX = requireTensor(arg(args, 2), Lb, "dX"); | |
| 536 | 2 | needPair(Lb, "dY", dY, x); | |
| 537 | 2 | BROTENSOR_API_TRY | |
| 538 | 2 | brotensor::log_backward(*x, *dY, *dX); | |
| 539 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 540 | 2 | return ev::undefined(); | |
| 541 | ✗ | } | |
| 542 | |||
| 543 | 2 | ev::Value jsExpForward(ev::Value, std::span<const ev::Value> args) { | |
| 544 | 2 | const char* Lb = "expForward"; | |
| 545 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 546 | 2 | Tensor* y = requireTensor(arg(args, 1), Lb, "y"); | |
| 547 | 2 | BROTENSOR_API_TRY | |
| 548 | 2 | brotensor::exp_forward(*x, *y); | |
| 549 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 550 | 2 | return ev::undefined(); | |
| 551 | ✗ | } | |
| 552 | |||
| 553 | 2 | ev::Value jsExpBackward(ev::Value, std::span<const ev::Value> args) { | |
| 554 | 2 | const char* Lb = "expBackward"; | |
| 555 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 556 | 2 | Tensor* dY = requireTensor(arg(args, 1), Lb, "dY"); | |
| 557 | 2 | Tensor* dX = requireTensor(arg(args, 2), Lb, "dX"); | |
| 558 | 2 | needPair(Lb, "dY", dY, x); | |
| 559 | 2 | BROTENSOR_API_TRY | |
| 560 | 2 | brotensor::exp_backward(*x, *dY, *dX); | |
| 561 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 562 | 2 | return ev::undefined(); | |
| 563 | ✗ | } | |
| 564 | |||
| 565 | 2 | ev::Value jsRoundForward(ev::Value, std::span<const ev::Value> args) { | |
| 566 | 2 | const char* Lb = "roundForward"; | |
| 567 | 2 | Tensor* x = requireTensor(arg(args, 0), Lb, "x"); | |
| 568 | 2 | Tensor* y = requireTensor(arg(args, 1), Lb, "y"); | |
| 569 | 2 | BROTENSOR_API_TRY | |
| 570 | 2 | brotensor::round_forward(*x, *y); | |
| 571 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 572 | 2 | return ev::undefined(); | |
| 573 | ✗ | } | |
| 574 | |||
| 575 | 2 | ev::Value jsRoundBackward(ev::Value, std::span<const ev::Value> args) { | |
| 576 | 2 | const char* Lb = "roundBackward"; | |
| 577 | 2 | Tensor* dY = requireTensor(arg(args, 0), Lb, "dY"); | |
| 578 | 2 | Tensor* dX = requireTensor(arg(args, 1), Lb, "dX"); | |
| 579 | 2 | BROTENSOR_API_TRY | |
| 580 | 2 | brotensor::round_backward(*dY, *dX); | |
| 581 | 2 | BROTENSOR_API_CATCH(Lb) | |
| 582 | 2 | return ev::undefined(); | |
| 583 | ✗ | } | |
| 584 | |||
| 585 | // ─── Autoregressive logit sampling ───────────────────────────────────────── | ||
| 586 | |||
| 587 | 4 | ev::Value jsSampleLogits(ev::Value, std::span<const ev::Value> args) { | |
| 588 | 4 | const char* Lb = "sampleLogits"; | |
| 589 | 4 | Tensor* logits = requireTensor(arg(args, 0), Lb, "logits"); | |
| 590 | 4 | double temperature = argNum(arg(args, 1), 1.0); | |
| 591 | 4 | int32_t topK = argInt(arg(args, 2), 0); | |
| 592 | 4 | double topP = argNum(arg(args, 3), 1.0); | |
| 593 | 4 | uint64_t key = readSeedValue(arg(args, 4), 0, Lb); | |
| 594 | 4 | uint64_t counter = readSeedValue(arg(args, 5), 0, Lb); | |
| 595 | 4 | Tensor* indices = requireTensor(arg(args, 6), Lb, "indices"); | |
| 596 | 4 | BROTENSOR_API_TRY | |
| 597 | 4 | brotensor::sample_logits( | |
| 598 | 4 | *logits, static_cast<float>(temperature), topK, static_cast<float>(topP), | |
| 599 | 4 | key, counter, *indices); | |
| 600 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 601 | 4 | return ev::undefined(); | |
| 602 | ✗ | } | |
| 603 | |||
| 604 | 4 | ev::Value jsSampleLogitsInto(ev::Value, std::span<const ev::Value> args) { | |
| 605 | 4 | const char* Lb = "sampleLogitsInto"; | |
| 606 | 4 | Tensor* logits = requireTensor(arg(args, 0), Lb, "logits"); | |
| 607 | 4 | double temperature = argNum(arg(args, 1), 1.0); | |
| 608 | 4 | int32_t topK = argInt(arg(args, 2), 0); | |
| 609 | 4 | double topP = argNum(arg(args, 3), 1.0); | |
| 610 | 4 | uint64_t key = readSeedValue(arg(args, 4), 0, Lb); | |
| 611 | 4 | Tensor* counter = requireTensor(arg(args, 5), Lb, "counter"); | |
| 612 | 4 | Tensor* scratch = requireTensor(arg(args, 6), Lb, "scratch"); | |
| 613 | 4 | Tensor* indices = requireTensor(arg(args, 7), Lb, "indices"); | |
| 614 | 4 | BROTENSOR_API_TRY | |
| 615 | 4 | brotensor::sample_logits_into( | |
| 616 | 4 | *logits, static_cast<float>(temperature), topK, static_cast<float>(topP), | |
| 617 | 4 | key, *counter, *scratch, *indices); | |
| 618 | 4 | BROTENSOR_API_CATCH(Lb) | |
| 619 | 4 | return ev::undefined(); | |
| 620 | ✗ | } | |
| 621 | |||
| 622 | } // namespace | ||
| 623 | |||
| 624 | 2 | void installTensorAudioB(bronze::Value ns) { | |
| 625 | 2 | ev::ObjectBuilder b(ns); | |
| 626 | 2 | b.def("pad1dForward", 8, &jsPad1dForward); | |
| 627 | 2 | b.def("pad1dBackward", 8, &jsPad1dBackward); | |
| 628 | 2 | b.def("conv1d", 13, &jsConv1d); | |
| 629 | 2 | b.def("conv1dBackwardInput", 12, &jsConv1dBackwardInput); | |
| 630 | 2 | b.def("conv1dBackwardWeight", 12, &jsConv1dBackwardWeight); | |
| 631 | 2 | b.def("conv1dBackwardBias", 5, &jsConv1dBackwardBias); | |
| 632 | 2 | b.def("conv1dInt8wFp16", 14, &jsConv1dInt8wFp16); | |
| 633 | 2 | b.def("convTranspose1dForward", 14, &jsConvTranspose1dForward); | |
| 634 | 2 | b.def("convTranspose1dBackwardInput", 13, &jsConvTranspose1dBackwardInput); | |
| 635 | 2 | b.def("convTranspose1dBackwardWeight", 13, &jsConvTranspose1dBackwardWeight); | |
| 636 | 2 | b.def("convTranspose1dBackwardBias", 5, &jsConvTranspose1dBackwardBias); | |
| 637 | 2 | b.def("causalConv1d", 13, &jsCausalConv1d); | |
| 638 | 2 | b.def("causalConv1dUpdate", 10, &jsCausalConv1dUpdate); | |
| 639 | 2 | b.def("snakeForward", 7, &jsSnakeForward); | |
| 640 | 2 | b.def("snakeBackward", 10, &jsSnakeBackward); | |
| 641 | 2 | b.def("eluForward", 3, &jsEluForward); | |
| 642 | 2 | b.def("eluBackward", 4, &jsEluBackward); | |
| 643 | 2 | b.def("leakyReluForward", 3, &jsLeakyReluForward); | |
| 644 | 2 | b.def("leakyReluBackward", 4, &jsLeakyReluBackward); | |
| 645 | 2 | b.def("vqEncodeForward", 4, &jsVqEncodeForward); | |
| 646 | 2 | b.def("vqEncodeBackward", 2, &jsVqEncodeBackward); | |
| 647 | 2 | b.def("fsqQuantizeForward", 4, &jsFsqQuantizeForward); | |
| 648 | 2 | b.def("fsqQuantizeBackward", 2, &jsFsqQuantizeBackward); | |
| 649 | 2 | b.def("resample1dForward", 7, &jsResample1dForward); | |
| 650 | 2 | b.def("resample1dBackward", 7, &jsResample1dBackward); | |
| 651 | 2 | b.def("logForward", 2, &jsLogForward); | |
| 652 | 2 | b.def("logBackward", 3, &jsLogBackward); | |
| 653 | 2 | b.def("expForward", 2, &jsExpForward); | |
| 654 | 2 | b.def("expBackward", 3, &jsExpBackward); | |
| 655 | 2 | b.def("roundForward", 2, &jsRoundForward); | |
| 656 | 2 | b.def("roundBackward", 2, &jsRoundBackward); | |
| 657 | 2 | b.def("sampleLogits", 7, &jsSampleLogits); | |
| 658 | 2 | b.def("sampleLogitsInto", 8, &jsSampleLogitsInto); | |
| 659 | 2 | } | |
| 660 | |||
| 661 | } // namespace brotensor::api | ||
| 662 |