Skip to content
Draft
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
14 changes: 14 additions & 0 deletions csrc/engine/infer_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../config/config_factory.hpp"
#include "spdlog/spdlog.h"
#include <future>
#include <mutex>
#include <stdexcept>
#include <unordered_set>

Expand Down Expand Up @@ -146,6 +147,15 @@ std::vector<std::string> InferEngine::state_dict_keys() {
//------------------------------------------------------
infinilm::InfinilmModel::Input
InferEngine::Input::to_model_input(infinicore::Device device) const {
// MACA maps a registered user pointer to only one node. Serialize H2D
// copies so TP ranks never access the same host registration concurrently.
static std::mutex maca_host_copy_mutex;
const bool serialize_host_copy
= device.getType() == infinicore::Device::Type::METAX;
std::unique_lock<std::mutex> maca_host_copy_lock;
if (serialize_host_copy) {
maca_host_copy_lock = std::unique_lock<std::mutex>(maca_host_copy_mutex);
}

auto to_device = [&](const std::optional<infinicore::Tensor> &t)
-> std::optional<infinicore::Tensor> {
Expand Down Expand Up @@ -183,6 +193,10 @@ InferEngine::Input::to_model_input(infinicore::Device device) const {
visual_token_ranges,
to_device(target_hidden_states)};

if (serialize_host_copy) {
infinicore::context::syncStream();
}

infinilm::global_state::get_forward_context().attn_metadata = {
input.past_sequence_lengths,
input.total_sequence_lengths,
Expand Down
Loading