// // Created by Morgan Funtowicz on 6/30/24. // #ifndef TGI_TRTLLM_BACKEND_H #define TGI_TRTLLM_BACKEND_H #include #include #include #include #include #include #include using json = nlohmann::json; namespace tle = tensorrt_llm::executor; namespace huggingface::tgi::backends { /** * 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); /** * */ class TensorRtLlmBackend { private: const json config; tle::Executor executor; public: explicit TensorRtLlmBackend( const std::filesystem::path &engineFolder, const std::filesystem::path &executorWorker ); /*** * 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 * @param frequencyPenalty * @param seed * @param nTopTokens * @return */ [[nodiscard]] tle::IdType Submit( const std::vector &tokens, int32_t maxNewTokens, int32_t topK, float_t topP, float_t temperature, int32_t minLength, std::optional repetitionPenalty = std::nullopt, std::optional frequencyPenalty = std::nullopt, std::optional seed = std::nullopt, std::optional nTopTokens = std::nullopt ); /*** * * @param reqId * @return */ std::vector Poll(tle::IdType reqId); }; } #endif //TGI_TRTLLM_BACKEND_H