/* * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ #include "families/pegasus/runtime/pipeline.h" #include "trtmc/runtime/family_factory.h" #include "trtmc/runtime/trt_backend.h" #include #include namespace trtmc::pegasus { namespace { std::vector section(const BundleReader& reader, const char* name) { const auto* found = reader.find_section(name); if (!found || found->length == 0) throw std::runtime_error(std::string("pegasus missing bundle section: ") + name); return reader.read_section(name); } std::unique_ptr engine(const FamilyContext& context, const char* name) { const auto plan = section(context.reader, name); auto module = context.backend.create_module(plan.data(), plan.size(), {}); if (!module || !module->ok()) throw std::runtime_error(std::string("pegasus could not load ") + name); module->set_timing_label(std::string("pegasus ") + name); return module; } } // namespace } // namespace trtmc::pegasus extern "C" trtmc::ITask* trtmc_create_family(const trtmc::FamilyContext& context) { namespace pg = trtmc::pegasus; if (context.kv_cache_size_bytes != 0) throw std::invalid_argument("pegasus does not support --kv-cache-size"); const auto data = pg::section(context.reader, "runtime.json"); const auto json = nlohmann::json::parse(data.begin(), data.end()); if (json.at("schema_version").get() != 1) throw std::invalid_argument("pegasus unsupported runtime schema"); pg::Config config; config.hidden_size = json.at("hidden_size").get(); config.vocab_size = json.at("vocab_size").get(); config.decoder_layers = json.at("decoder_layers").get(); config.max_sequence_length = json.at("max_sequence_length").get(); config.decoder_start_token_id = json.at("decoder_start_token_id").get(); config.eos_token_id = json.at("eos_token_id").get(); config.pad_token_id = json.at("pad_token_id").get(); const auto tokenizer_data = pg::section(context.reader, "tokenizer.json"); auto tokenizer = pg::CreateUnigramTokenizer(tokenizer_data.data(), tokenizer_data.size(), false); return new pg::Pipeline(pg::engine(context, "encoder.plan"), pg::engine(context, "decoder.plan"), std::move(tokenizer), config); }