hf_text-generation-inference/backends/trtllm/include/backend.h

98 lines
2.4 KiB
C
Raw Normal View History

//
// Created by Morgan Funtowicz on 6/30/24.
//
#ifndef TGI_TRTLLM_BACKEND_H
#define TGI_TRTLLM_BACKEND_H
#include <filesystem>
2024-07-03 02:27:53 -06:00
#include <span>
#include <fmt/format.h>
2024-07-08 16:08:49 -06:00
#include <nlohmann/json.hpp>
2024-07-03 02:27:53 -06:00
#include <tensorrt_llm/runtime/common.h>
#include <tensorrt_llm/executor/executor.h>
#include <tensorrt_llm/plugins/api/tllmPlugin.h>
2024-07-03 02:27:53 -06:00
using json = nlohmann::json;
2024-07-03 02:27:53 -06:00
namespace tle = tensorrt_llm::executor;
namespace huggingface::tgi::backends {
2024-07-08 16:08:49 -06:00
/**
* Initialize all the components required by TRTLLM.
* It is required to call this function before attempting to load any engine
*/
void InitializeBackend();
/**
*
* @param config
* @param workerPath
* @param channel
* @return
*/
tle::ExecutorConfig GetExecutorConfig(const json &config, const std::string &workerPath);
2024-07-08 16:08:49 -06:00
/**
*
*/
class TensorRtLlmBackend {
private:
const json config;
2024-07-03 02:27:53 -06:00
tle::Executor executor;
public:
explicit TensorRtLlmBackend(
const std::filesystem::path &engineFolder,
const std::filesystem::path &executorWorker
);
2024-07-03 02:27:53 -06:00
/***
* Indicate if the backend is ready to accept incoming request
* @return true if ready, false otherwise
*/
[[nodiscard]] bool IsReady() const {
return executor.canEnqueueRequests();
}
/***
*
* @param tokens
* @param maxNewTokens
* @param topK
* @param topP
* @param temperature
* @param minLength
* @param repetitionPenalty
2024-07-08 16:08:49 -06:00
* @param frequencyPenalty
2024-07-03 02:27:53 -06:00
* @param seed
* @param nTopTokens
* @return
*/
[[nodiscard]] tle::IdType Submit(
2024-07-08 16:08:49 -06:00
const std::vector<tle::TokenIdType> &tokens,
2024-07-03 02:27:53 -06:00
int32_t maxNewTokens,
2024-07-08 16:08:49 -06:00
int32_t topK,
2024-07-03 02:27:53 -06:00
float_t topP,
float_t temperature,
int32_t minLength,
std::optional<float_t> repetitionPenalty = std::nullopt,
2024-07-08 16:08:49 -06:00
std::optional<float_t> frequencyPenalty = std::nullopt,
2024-07-03 02:27:53 -06:00
std::optional<uint32_t> seed = std::nullopt,
std::optional<uint32_t> nTopTokens = std::nullopt
);
2024-07-08 16:08:49 -06:00
/***
*
* @param reqId
* @return
*/
std::vector<tle::Response> Poll(tle::IdType reqId);
};
}
#endif //TGI_TRTLLM_BACKEND_H