Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions csrc/engine/compiler/paged_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <algorithm>
#include <cstdint>
#include <stdexcept>
#include <vector>

namespace infinilm::engine {
Expand Down Expand Up @@ -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<int32_t> 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();
Expand Down Expand Up @@ -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<const int32_t *>(
runtime_seq_lens->data()),
batch_size);
}
auto shared_output = std::shared_ptr<InfinilmModel::Output>(new InfinilmModel::Output{std::get<1>(result->second.compiled)->logits->resume_from_blob_()});

return std::make_tuple(graph, shared_output);
Expand Down
Loading