speculative.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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.75f; // min probability required to accept a token in the draft
  9. };
  10. struct common_speculative * common_speculative_init(
  11. struct llama_context * ctx_tgt,
  12. struct llama_context * ctx_dft
  13. );
  14. void common_speculative_free(struct common_speculative * spec);
  15. bool common_speculative_are_compatible(
  16. const struct llama_context * ctx_tgt,
  17. const struct llama_context * ctx_dft);
  18. void common_speculative_add_replacement_tgt_dft(
  19. struct common_speculative * spec,
  20. const char *source, const char *dest);
  21. // sample up to n_draft tokens and add them to the batch using the draft model
  22. llama_tokens common_speculative_gen_draft(
  23. struct common_speculative * spec,
  24. struct common_speculative_params params,
  25. const llama_tokens & prompt,
  26. llama_token id_last);