2023-12-15 01:35:58 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-06-10 04:23:30 +08:00
|
|
|
#include <torch/all.h>
|
2023-02-16 15:47:03 +08:00
|
|
|
|
2023-03-11 01:58:21 +08:00
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2024-05-22 15:18:41 +08:00
|
|
|
void swap_blocks(torch::Tensor& src, torch::Tensor& dst,
|
|
|
|
|
const torch::Tensor& block_mapping);
|
2023-02-16 15:47:03 +08:00
|
|
|
|
2024-06-10 04:23:30 +08: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 15:18:41 +08:00
|
|
|
const torch::Tensor& block_mapping);
|
2023-03-11 01:58:21 +08:00
|
|
|
|
2024-05-22 15:18:41 +08:00
|
|
|
void reshape_and_cache(torch::Tensor& key, torch::Tensor& value,
|
|
|
|
|
torch::Tensor& key_cache, torch::Tensor& value_cache,
|
|
|
|
|
torch::Tensor& slot_mapping,
|
2024-07-17 06:31:32 +08:00
|
|
|
const std::string& kv_cache_dtype, const double k_scale,
|
|
|
|
|
const double v_scale);
|
2023-02-19 03:22:57 +08:00
|
|
|
|
2024-05-22 15:18:41 +08: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-25 02:36:52 +08:00
|
|
|
const std::string& kv_cache_dtype,
|
|
|
|
|
const double k_scale, const double v_scale);
|
2024-05-04 06:51:27 +08:00
|
|
|
|
2024-01-29 08:43:54 +08:00
|
|
|
// Just for unittest
|
2024-05-22 15:18:41 +08:00
|
|
|
void convert_fp8(torch::Tensor& dst_cache, torch::Tensor& src_cache,
|
2024-06-10 04:23:30 +08:00
|
|
|
const double scale, const std::string& kv_cache_dtype);
|