diff --git a/csrc/engine/compiler/paged_compiler.cpp b/csrc/engine/compiler/paged_compiler.cpp index df3fd1cb4..721129d4f 100644 --- a/csrc/engine/compiler/paged_compiler.cpp +++ b/csrc/engine/compiler/paged_compiler.cpp @@ -4,6 +4,7 @@ #include #include +#include #include namespace infinilm::engine { @@ -138,6 +139,14 @@ void PagedCompiler::compile() { // before every graph replay in get_compiled(). model_->reset_runtime_state(); infinicore::context::syncStream(); + if (infinicore::context::getDevice().getType() + == infinicore::Device::Type::ASCEND) { + std::vector capture_sequence_lengths(b, 1); + infinicore::graph::stage_task_update_host_int_array( + input.total_sequence_lengths.value(), + capture_sequence_lengths.data(), + capture_sequence_lengths.size()); + } infinicore::context::startGraphRecording(); auto output = model_->forward(input); auto graph = infinicore::context::stopGraphRecording(); @@ -205,6 +214,26 @@ PagedCompiler::Compiled PagedCompiler::get_compiled(const InfinilmModel::Input & model_->reset_runtime_state(); auto graph = std::get<0>(result->second.compiled); + if (graph != nullptr + && infinicore::context::getDevice().getType() + == infinicore::Device::Type::ASCEND) { + const auto &runtime_seq_lens = input.total_sequence_lengths.value(); + if (runtime_seq_lens->device().getType() + != infinicore::Device::Type::CPU + || runtime_seq_lens->dtype() + != infinicore::DataType::I32 + || runtime_seq_lens->shape().size() != 1 + || runtime_seq_lens->shape()[0] != batch_size) { + throw std::runtime_error( + "PagedCompiler expected CPU int32 " + "total_sequence_lengths for Ascend graph replay"); + } + graph->update_host_int_array( + graph_input.total_sequence_lengths.value(), + reinterpret_cast( + runtime_seq_lens->data()), + batch_size); + } auto shared_output = std::shared_ptr(new InfinilmModel::Output{std::get<1>(result->second.compiled)->logits->resume_from_blob_()}); return std::make_tuple(graph, shared_output);