-
Notifications
You must be signed in to change notification settings - Fork 116
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
#0: Add borrowed storage support for the aggregate_as_tensor function #18555
Open
jjiangTT
wants to merge
4
commits into
main
Choose a base branch
from
jjiang/support_borrowed_aggregate
base: main
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.
+63
−0
Conversation
This file contains 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
omilyutin-tt
reviewed
Mar 3, 2025
ttnn/cpp/ttnn/distributed/api.cpp
Outdated
Comment on lines
103
to
110
auto visitor = tt::stl::overloaded{[&shard, &host_owned_buffers](const auto& buffer) -> OwnedBuffer { | ||
using BufferType = std::decay_t<decltype(buffer)>; | ||
using ValueType = typename BufferType::value_type; | ||
|
||
std::vector<ValueType> physical_data(buffer.begin(), buffer.end()); | ||
|
||
std::vector<ValueType> logical_data = | ||
tensor_impl::decode_tensor_data(std::move(physical_data), shard.get_tensor_spec()); | ||
|
||
return owned_buffer::create(std::move(logical_data)); | ||
}}; |
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.
I don't think we need this? Does this work:
auto borrowed_buffer = std::get<BorrowedStorage>(shard.get_storage()).buffer;
auto owned_buffer = std::visit(
[](auto&& buffer) {
using BorrowedStorageType = std::vector<std::decay_t<decltype(*(buffer.begin()))>>;
return owned_buffer::create(BorrowedStorageType(buffer.begin(), buffer.end()));
},
borrowed_buffer);
omilyutin-tt
requested changes
Mar 3, 2025
@@ -93,7 +93,31 @@ Tensor aggregate_as_tensor( | |||
} | |||
auto storage = MultiDeviceHostStorage{config, std::move(host_owned_buffers), specs}; | |||
return Tensor(std::move(storage), reference_shard.get_tensor_spec()); | |||
} else if (storage_type == StorageType::BORROWED) { |
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.
I don't think this is formatted?
eb73a5e
to
84c65ae
Compare
cf2f060
to
e2a46b1
Compare
4e5f8a9
to
0f8151f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ticket
Link to Github Issue
Problem description
The aggregate_as_tensor function currently goes straight to assuming anything that isn't an owned tensor is a device tensor and then failing. Borrowed storage is currently the "preferred default" so newly created non-bfp_b types would require a conversion before they could be aggregated otherwise.
What's changed
Added support for borrowed storage tensors by turning them into owned tensors and then aggregating them into a multidevicehost storage backed tensor.
Added TT_FATAL checking to prevent any other types from crashing on the storage variant fetch and give some more visibility into failures.
Checklist