-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Hetero support continuous batching #30371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WeldonWangwang
wants to merge
13
commits into
openvinotoolkit:master
Choose a base branch
from
WeldonWangwang:wangwang/hetero_support_cb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+325
−4
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c0da1ef
hetero support remote tensor
WeldonWangwang 33063bd
Hetero support continuous batching
WeldonWangwang 0e6c022
clean code
WeldonWangwang df95fdc
Merge branch 'master' into wangwang/hetero_support_cb
WeldonWangwang 940e5be
Fix submodel with paged-attention ops
WeldonWangwang 82c0609
clean code
WeldonWangwang 589f559
clean code
WeldonWangwang 1b6f2ee
Fix build error
WeldonWangwang 1b7fd80
Fix code style
WeldonWangwang 0d6328e
Fix code style
WeldonWangwang 284e025
Fix build error
WeldonWangwang d67fb74
Fix test cases
WeldonWangwang a5f05e7
Rename some classes
WeldonWangwang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "remote_context.hpp" | ||
|
||
#include <memory> | ||
|
||
#include "openvino/runtime/make_tensor.hpp" | ||
#include "remote_tensor.hpp" | ||
|
||
namespace ov { | ||
namespace hetero { | ||
|
||
RemoteContext::RemoteContext(std::map<std::string, ov::SoPtr<ov::IRemoteContext>> contexts) { | ||
m_contexts = contexts; | ||
} | ||
|
||
const ov::AnyMap& RemoteContext::get_property() const { | ||
return m_contexts.begin()->second->get_property(); | ||
} | ||
|
||
std::shared_ptr<RemoteContext> RemoteContext::get_this_shared_ptr() { | ||
return std::static_pointer_cast<RemoteContext>(shared_from_this()); | ||
} | ||
|
||
ov::SoPtr<ov::IRemoteTensor> RemoteContext::create_tensor(const ov::element::Type& type, | ||
const ov::Shape& shape, | ||
const ov::AnyMap& params) { | ||
std::vector<ov::SoPtr<ov::IRemoteTensor>> tensors; | ||
for (auto& item : m_contexts) { | ||
auto a = item.second->create_tensor(type, shape, params); | ||
tensors.emplace_back(a); | ||
} | ||
return std::make_shared<ov::hetero::RemoteTensor>(get_this_shared_ptr(), tensors); | ||
} | ||
|
||
const std::string& RemoteContext::get_device_name() const { | ||
static const std::string name = "HETERO"; | ||
return name; | ||
} | ||
|
||
} // namespace hetero | ||
} // namespace ov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "openvino/runtime/iremote_context.hpp" | ||
|
||
namespace ov { | ||
namespace hetero { | ||
class RemoteContext : public ov::IRemoteContext { | ||
public: | ||
using Ptr = std::shared_ptr<RemoteContext>; | ||
|
||
RemoteContext(std::map<std::string, ov::SoPtr<ov::IRemoteContext>> contexts); | ||
|
||
const std::string& get_device_name() const override; | ||
const ov::AnyMap& get_property() const override; | ||
|
||
ov::SoPtr<ov::IRemoteTensor> create_tensor(const ov::element::Type& type, | ||
const ov::Shape& shape, | ||
const ov::AnyMap& params) override; | ||
|
||
private: | ||
std::shared_ptr<RemoteContext> get_this_shared_ptr(); | ||
std::map<std::string, ov::SoPtr<ov::IRemoteContext>> m_contexts; | ||
}; | ||
|
||
} // namespace hetero | ||
} // namespace ov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "remote_tensor.hpp" | ||
|
||
namespace ov { | ||
namespace hetero { | ||
|
||
RemoteTensor::RemoteTensor(std::shared_ptr<RemoteContext> context, std::vector<ov::SoPtr<ov::IRemoteTensor>> tensors) | ||
: m_context(context), | ||
m_ordered_tensor(tensors) { | ||
for (auto& tensor : tensors) { | ||
auto remote_tensor = std::dynamic_pointer_cast<ov::IRemoteTensor>(tensor._ptr); | ||
m_remote_tensors.emplace_back(remote_tensor); | ||
auto device_name = remote_tensor->get_device_name(); | ||
m_tensors.insert({device_name, tensor}); | ||
} | ||
} | ||
|
||
const std::string& RemoteTensor::get_device_name() const { | ||
return m_context->get_device_name(); | ||
} | ||
|
||
const ov::element::Type& RemoteTensor::get_element_type() const { | ||
return m_tensors.begin()->second->get_element_type(); | ||
} | ||
|
||
const ov::Strides& RemoteTensor::get_strides() const { | ||
return m_tensors.begin()->second->get_strides(); | ||
} | ||
|
||
const AnyMap& RemoteTensor::get_properties() const { | ||
return m_tensors.begin()->second->get_properties(); | ||
} | ||
|
||
const ov::Shape& RemoteTensor::get_shape() const { | ||
return m_tensors.begin()->second->get_shape(); | ||
} | ||
|
||
std::shared_ptr<RemoteContext> RemoteTensor::get_context() const { | ||
return m_context; | ||
} | ||
|
||
ov::SoPtr<ov::IRemoteTensor> RemoteTensor::get_tensor(int index) const { | ||
return m_ordered_tensor[index]; | ||
} | ||
|
||
ov::SoPtr<ov::IRemoteTensor> RemoteTensor::get_tensor_by_name(const std::string device_name) const { | ||
return m_tensors.at(device_name); | ||
} | ||
|
||
void RemoteTensor::set_shape(ov::Shape shape) { | ||
for (auto it = m_tensors.begin(); it != m_tensors.end(); ++it) { | ||
it->second->set_shape(shape); | ||
} | ||
} | ||
|
||
void RemoteTensor::copy_to(const std::shared_ptr<ov::ITensor>& dst, | ||
size_t src_offset, | ||
size_t dst_offset, | ||
const ov::Shape& roi_shape) const { | ||
if (auto remote = std::dynamic_pointer_cast<ov::hetero::RemoteTensor>(dst)) { | ||
int i = 0; | ||
for (auto& tensor : m_remote_tensors) { | ||
auto itensor = std::dynamic_pointer_cast<ov::ITensor>(remote->get_tensor(i)._ptr); | ||
tensor->copy_to(itensor, src_offset, dst_offset, roi_shape); | ||
i++; | ||
} | ||
} else { | ||
int i = 0; | ||
for (auto& tensor : m_remote_tensors) { | ||
tensor->copy_to(dst, src_offset, dst_offset + i * get_strides()[0], roi_shape); | ||
i++; | ||
} | ||
} | ||
} | ||
|
||
void RemoteTensor::copy_from(const std::shared_ptr<const ov::ITensor>& src, | ||
size_t src_offset, | ||
size_t dst_offset, | ||
const ov::Shape& roi_shape) { | ||
if (auto remote = std::dynamic_pointer_cast<const ov::hetero::RemoteTensor>(src)) { | ||
int i = 0; | ||
for (auto& tensor : m_remote_tensors) { | ||
auto itensor = std::dynamic_pointer_cast<ov::ITensor>(remote->get_tensor(i)._ptr); | ||
tensor->copy_from(itensor, src_offset, dst_offset, roi_shape); | ||
i++; | ||
} | ||
} else { | ||
auto new_roi_shape = get_shape(); | ||
new_roi_shape[0] = roi_shape[0]; | ||
int i = 0; | ||
for (auto& tensor : m_remote_tensors) { | ||
tensor->copy_from(src, src_offset + i * get_strides()[0], dst_offset, new_roi_shape); | ||
i++; | ||
} | ||
} | ||
} | ||
|
||
} // namespace hetero | ||
} // namespace ov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
#include "openvino/runtime/iremote_tensor.hpp" | ||
#include "remote_context.hpp" | ||
|
||
namespace ov { | ||
namespace hetero { | ||
|
||
class RemoteTensor : public ov::IRemoteTensor { | ||
public: | ||
RemoteTensor(std::shared_ptr<ov::hetero::RemoteContext> context, std::vector<ov::SoPtr<ov::IRemoteTensor>> tensors); | ||
|
||
const std::string& get_device_name() const override; | ||
|
||
const ov::element::Type& get_element_type() const override; | ||
|
||
const ov::Strides& get_strides() const override; | ||
|
||
const AnyMap& get_properties() const override; | ||
|
||
const ov::Shape& get_shape() const override; | ||
|
||
std::shared_ptr<RemoteContext> get_context() const; | ||
|
||
ov::SoPtr<ov::IRemoteTensor> get_tensor(int index) const; | ||
|
||
ov::SoPtr<ov::IRemoteTensor> get_tensor_by_name(const std::string device_name) const; | ||
|
||
void set_shape(ov::Shape shape) override; | ||
|
||
void copy_to(const std::shared_ptr<ov::ITensor>& dst, | ||
size_t src_offset, | ||
size_t dst_offset, | ||
const ov::Shape& roi_shape) const override; | ||
|
||
void copy_from(const std::shared_ptr<const ov::ITensor>& src, | ||
size_t src_offset, | ||
size_t dst_offset, | ||
const ov::Shape& roi_shape) override; | ||
|
||
private: | ||
std::shared_ptr<RemoteContext> m_context; | ||
std::vector<ov::SoPtr<ov::IRemoteTensor>> m_ordered_tensor; | ||
std::map<std::string, ov::SoPtr<ov::IRemoteTensor>> m_tensors; | ||
std::vector<std::shared_ptr<ov::IRemoteTensor>> m_remote_tensors; | ||
}; | ||
|
||
} // namespace hetero | ||
} // namespace ov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tried beam search? can it work with hetero? it had problem with tensor parallel, not sure hetero
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi bell, I haven't tried beam search yet, will try it.