Run the Whisper decoder to obtain the logits and probabilities for the next token. Make sure to call whisper_encode() first. tokens + n_tokens is the provided context for the decoder. n_past is the number of tokens to use from previous decoder calls. Returns 0 on success
| 187 | // provided context for the decoder. n_past is the number of tokens to use |
| 188 | // from previous decoder calls. Returns 0 on success |
| 189 | void Context::decode(std::vector<whisper_token> *token, size_t n_past, |
| 190 | size_t threads) { |
| 191 | if (!encode_completed) { |
| 192 | RAISE_RUNTIME_ERROR("encode not completed."); |
| 193 | } |
| 194 | if (threads < 1) |
| 195 | throw std::invalid_argument("threads must be >= 1"); |
| 196 | |
| 197 | int res; |
| 198 | |
| 199 | if (!init_with_state) { |
| 200 | RAISE_IF_NULL(wstate); |
| 201 | res = whisper_decode_with_state(wctx, wstate, token->data(), |
| 202 | token->size(), n_past, threads); |
| 203 | } else { |
| 204 | res = |
| 205 | whisper_decode(wctx, token->data(), token->size(), n_past, threads); |
| 206 | } |
| 207 | |
| 208 | if (res == -1) { |
| 209 | RAISE_RUNTIME_ERROR("whisper_decode failed"); |
| 210 | } else if (res == 0) { |
| 211 | decode_once = true; |
| 212 | } else { |
| 213 | RAISE_RUNTIME_ERROR("Unknown error."); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // Run the Whisper decoder to obtain the logits and probabilities for the next |
| 218 | // token. Make sure to call whisper_encode() first. tokens + n_tokens is the |