speculative.h 884 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. #include "llama.h"
  3. #include "common.h"
  4. struct common_speculative;
  5. struct common_speculative_params {
  6. int n_draft = 16; // max drafted tokens
  7. int n_reuse = 256;
  8. float p_min = 0.9f; // min probability required to accept a token in the draft
  9. };
  10. struct common_speculative * common_speculative_init(struct llama_context * ctx_dft);
  11. void common_speculative_free(struct common_speculative * spec);
  12. bool common_speculative_are_compatible(
  13. const struct llama_context * ctx_tgt,
  14. const struct llama_context * ctx_dft);
  15. // sample up to n_draft tokens and add them to the batch using the draft model
  16. llama_tokens common_speculative_gen_draft(
  17. struct common_speculative * spec,
  18. struct common_speculative_params params,
  19. const llama_tokens & prompt,
  20. llama_token id_last);