cache.h 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include <torch/all.h>
  3. #include <map>
  4. #include <vector>
  5. void swap_blocks(torch::Tensor& src, torch::Tensor& dst,
  6. const torch::Tensor& block_mapping);
  7. // NOTE: the key_caches and value_caches vectors are constant but
  8. // not the Tensors they contain. The vectors need to be const refs
  9. // in order to satisfy pytorch's C++ operator registration code.
  10. void copy_blocks(std::vector<torch::Tensor> const& key_caches,
  11. std::vector<torch::Tensor> const& value_caches,
  12. const torch::Tensor& block_mapping);
  13. void reshape_and_cache(torch::Tensor& key, torch::Tensor& value,
  14. torch::Tensor& key_cache, torch::Tensor& value_cache,
  15. torch::Tensor& slot_mapping,
  16. const std::string& kv_cache_dtype, const double k_scale,
  17. const double v_scale);
  18. void reshape_and_cache_flash(torch::Tensor& key, torch::Tensor& value,
  19. torch::Tensor& key_cache,
  20. torch::Tensor& value_cache,
  21. torch::Tensor& slot_mapping,
  22. const std::string& kv_cache_dtype,
  23. const double k_scale, const double v_scale);
  24. // Just for unittest
  25. void convert_fp8(torch::Tensor& dst_cache, torch::Tensor& src_cache,
  26. const double scale, const std::string& kv_cache_dtype);