| 49 | } |
| 50 | |
| 51 | void encoder_backward(Context& ctx, float* dwte, float* dwpe, |
| 52 | float* dout, int* inp, |
| 53 | int B, int T, int C) { |
| 54 | unsigned long b = static_cast<unsigned long>(B); |
| 55 | unsigned long t = static_cast<unsigned long>(T); |
| 56 | unsigned long c = static_cast<unsigned long>(C); |
| 57 | unsigned long v = VOCAB_SIZE; |
| 58 | struct EncoderParams { |
| 59 | uint32_t B; |
| 60 | uint32_t T; |
| 61 | uint32_t C; |
| 62 | }; |
| 63 | setLogLevel(kError); |
| 64 | Tensor dwte_t = createTensor(ctx, Shape{v, c}, kf32, dwte); |
| 65 | Tensor dwpe_t = createTensor(ctx, Shape{t, c}, kf32, dwpe); |
| 66 | Tensor dout_t = createTensor(ctx, Shape{b * t * c}, kf32, dout); |
| 67 | Tensor input = createTensor(ctx, Shape{b * t}, ki32, inp); |
| 68 | std::promise<void> promise; |
| 69 | std::future<void> future = promise.get_future(); |
| 70 | Kernel op = createKernel(ctx, {kShaderEncoderBackward, 256, kf32}, |
| 71 | Bindings{dwte_t, dwpe_t, dout_t, input}, |
| 72 | /* nWorkgroups */ {cdiv(b * t, 256), 1, 1}, |
| 73 | /* params */ |
| 74 | EncoderParams{ |
| 75 | static_cast<uint32_t>(b), |
| 76 | static_cast<uint32_t>(t), |
| 77 | static_cast<uint32_t>(c) |
| 78 | }); |
| 79 | dispatchKernel(ctx, op, promise); |
| 80 | wait(ctx, future); |
| 81 | toCPU(ctx, dwte_t, dwte, v * c * sizeof(float)); |
| 82 | toCPU(ctx, dwpe_t, dwpe, t * c * sizeof(float)); |
| 83 | } |
| 84 | |
| 85 | void layernorm_forward(Context& ctx, float* out, float* mean, float* rstd, |
| 86 | float* inp, float* weight, float* bias, |
no test coverage detected