-
Notifications
You must be signed in to change notification settings - Fork 404
Add TensorRT weight streaming support to the ExecuTorch delegate #4336
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
Draft
shoumikhin
wants to merge
1
commit into
pytorch:main
Choose a base branch
from
shoumikhin:weight_streaming_executorch_delegate
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.
Draft
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions
34
cpp/include/torch_tensorrt/executorch/WeightStreamingBudget.h
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,34 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| namespace torch_tensorrt { | ||
| namespace executorch_backend { | ||
|
|
||
| // Compile spec key that carries the weight streaming budget from export into the | ||
| // delegate. Must match WEIGHT_STREAMING_BUDGET_COMPILE_SPEC_KEY on the Python | ||
| // side (py/torch_tensorrt/executorch/partitioner.py). | ||
| inline constexpr char kWeightStreamingBudgetKey[] = "weight_streaming_budget"; | ||
|
|
||
| // Result of parsing a weight streaming budget compile spec value. | ||
| // | ||
| // The value is a non-negative decimal integer: an explicit GPU budget in bytes. | ||
| // The automatic budget is intentionally not encoded here: when no budget spec is | ||
| // present, the delegate applies TensorRT's automatic budget itself, mirroring the | ||
| // PyTorch runtimes. | ||
| // | ||
| // valid == false -> a value was present but could not be parsed (or was | ||
| // negative); the caller should reject the program. | ||
| // valid == true -> bytes holds the parsed non-negative byte budget. | ||
| struct WsBudget { | ||
| bool valid = false; | ||
| int64_t bytes = 0; | ||
| }; | ||
|
|
||
| // Parses a budget from a raw byte range. The value is NOT assumed to be NUL | ||
| // terminated; only the first nbytes bytes are read. | ||
| WsBudget parse_weight_streaming_budget(const void* value, std::size_t nbytes); | ||
|
|
||
| } // namespace executorch_backend | ||
| } // namespace torch_tensorrt |
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
35 changes: 35 additions & 0 deletions
35
cpp/src/torch_tensorrt/executorch/WeightStreamingBudget.cpp
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,35 @@ | ||
| #include "torch_tensorrt/executorch/WeightStreamingBudget.h" | ||
|
|
||
| #include <charconv> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <system_error> | ||
|
|
||
| namespace torch_tensorrt { | ||
| namespace executorch_backend { | ||
|
|
||
| WsBudget parse_weight_streaming_budget(const void* value, std::size_t nbytes) { | ||
| WsBudget result; // valid == false until the value is fully parsed | ||
|
|
||
| if (value == nullptr || nbytes == 0) { | ||
| return result; | ||
| } | ||
| // The value is a non-negative decimal byte budget and is not NUL terminated. | ||
| // std::from_chars consumes only ASCII digits (no leading whitespace, sign, or | ||
| // base prefix), so a leftover byte (trailing garbage or an embedded NUL), an | ||
| // out-of-range value, or a negative leaves the result invalid. | ||
| const char* const first = static_cast<const char*>(value); | ||
| const char* const last = first + nbytes; | ||
| int64_t parsed = 0; | ||
| const std::from_chars_result fc = std::from_chars(first, last, parsed); | ||
| if (fc.ec != std::errc() || fc.ptr != last || parsed < 0) { | ||
| return result; | ||
| } | ||
|
|
||
| result.valid = true; | ||
| result.bytes = parsed; | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace executorch_backend | ||
| } // namespace torch_tensorrt |
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.
What happens if len = 0? Give a warning to the user