cache.h 921 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <torch/extension.h>
  3. #include <map>
  4. #include <vector>
  5. void swap_blocks(
  6. torch::Tensor& src,
  7. torch::Tensor& dst,
  8. const std::map<int64_t, int64_t>& block_mapping);
  9. void copy_blocks(
  10. std::vector<torch::Tensor>& key_caches,
  11. std::vector<torch::Tensor>& value_caches,
  12. const std::map<int64_t, std::vector<int64_t>>& block_mapping);
  13. void reshape_and_cache(
  14. torch::Tensor& key,
  15. torch::Tensor& value,
  16. torch::Tensor& key_cache,
  17. torch::Tensor& value_cache,
  18. torch::Tensor& slot_mapping,
  19. const std::string& kv_cache_dtype,
  20. const float k_scale = 1.0f,
  21. const float k_zp = 0.0f,
  22. const float v_scale = 1.0f,
  23. const float v_zp = 0.0f);
  24. void gather_cached_kv(
  25. torch::Tensor& key,
  26. torch::Tensor& value,
  27. torch::Tensor& key_cache,
  28. torch::Tensor& value_cache,
  29. torch::Tensor& slot_mapping);
  30. void convert_fp8_e5m2(
  31. torch::Tensor& src_cache,
  32. torch::Tensor& dst_cache);