2023-12-14 12:35:58 -05:00
|
|
|
#pragma once
|
|
|
|
|
2024-06-09 16:23:30 -04:00
|
|
|
#include <torch/all.h>
|
2023-02-16 07:47:03 +00:00
|
|
|
|
2023-03-10 09:58:21 -08:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
2024-05-22 03:18:41 -04:00
|
|
|
void swap_blocks(torch::Tensor& src, torch::Tensor& dst,
|
|
|
|
const torch::Tensor& block_mapping);
|
2023-02-16 07:47:03 +00:00
|
|
|
|
2024-06-09 16:23:30 -04:00
|
|
|
// Note: the key_caches and value_caches vectors are constant but
|
|
|
|
// not the Tensors they contain. The vectors need to be const refs
|
|
|
|
// in order to satisfy pytorch's C++ operator registration code.
|
|
|
|
void copy_blocks(std::vector<torch::Tensor> const& key_caches,
|
|
|
|
std::vector<torch::Tensor> const& value_caches,
|
2024-05-22 03:18:41 -04:00
|
|
|
const torch::Tensor& block_mapping);
|
2023-03-10 09:58:21 -08:00
|
|
|
|
2024-05-22 03:18:41 -04:00
|
|
|
void reshape_and_cache(torch::Tensor& key, torch::Tensor& value,
|
|
|
|
torch::Tensor& key_cache, torch::Tensor& value_cache,
|
|
|
|
torch::Tensor& slot_mapping,
|
2025-01-23 13:04:03 -05:00
|
|
|
const std::string& kv_cache_dtype,
|
|
|
|
torch::Tensor& k_scale, torch::Tensor& v_scale);
|
2023-02-18 19:22:57 +00:00
|
|
|
|
2024-05-22 03:18:41 -04:00
|
|
|
void reshape_and_cache_flash(torch::Tensor& key, torch::Tensor& value,
|
|
|
|
torch::Tensor& key_cache,
|
|
|
|
torch::Tensor& value_cache,
|
|
|
|
torch::Tensor& slot_mapping,
|
2024-07-24 11:36:52 -07:00
|
|
|
const std::string& kv_cache_dtype,
|
2025-01-23 13:04:03 -05:00
|
|
|
torch::Tensor& k_scale, torch::Tensor& v_scale);
|
2024-05-03 15:51:27 -07:00
|
|
|
|
2024-01-29 08:43:54 +08:00
|
|
|
// Just for unittest
|
2024-05-22 03:18:41 -04:00
|
|
|
void convert_fp8(torch::Tensor& dst_cache, torch::Tensor& src_cache,
|
2024-06-09 16:23:30 -04:00
|
|
|
const double scale, const std::string& kv_cache_dtype);
|