-
Notifications
You must be signed in to change notification settings - Fork 365
Centralizing Partitioning State #1263
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
Conversation
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
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.
Code conforms to C++ style guidelines
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.
Code conforms to Python style guidelines
@bowang007 This should be roughly equivalent to our current system. There are a couple improvements on this that I'd like to do that I want your input on.
|
std::ostream& operator<<(std::ostream& os, const NodeExecutorDecision& format) { | ||
switch (format) { | ||
case NodeExecutorDecision::kUNSUPPORTED: | ||
return os << "to run torch due to lack of converter support"; |
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.
"run in torch"
core/compiler.cpp
Outdated
@@ -272,8 +269,8 @@ GraphAndMapping ConstructFallbackGraph( | |||
// convert the 2 blocks in prim::if and get the converted graph with mappings | |||
std::vector<GraphAndMapping> graph_and_mappings; | |||
for (auto cur_block : if_node->blocks()) { | |||
graph_and_mappings.push_back( | |||
ConstructFallbackGraph(new_mod, cur_block, example_tensor_map, cfg, static_params, fallback_nodes)); | |||
graph_and_mappings.push_back(ConstructFallbackGraph_( |
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.
Not wildly pressing but is there a way to do all the partitioning beforehand then go through and compile specific blocks? Having them mixed is not as easy to debug
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.
@bowang007 thoughts here?
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.
Perhaps what we do is recursively partition, then recursively compile the final graph. Not sure if graph stitching can handle this right now.
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
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.
Code conforms to C++ style guidelines
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.
Code conforms to Python style guidelines
core/compiler.cpp
Outdated
@@ -219,19 +219,16 @@ void AddIfBlockToGraph( | |||
return; | |||
} | |||
|
|||
GraphAndMapping ConstructFallbackGraph( | |||
GraphAndMapping ConstructFallbackGraph_( |
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 a more distinguishing name for this maybe?
Went through just now, I think the general architecture is very clear and comprehensive, here are some thoughts: |
I want to be able to enable features like #1257 |
@narendasan If we store SegmentedBlocks
|
Where do we put sub blocks now? |
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.
Code conforms to C++ style guidelines
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.
Code conforms to Python style guidelines
Signed-off-by: Bo Wang <[email protected]>
Signed-off-by: Bo Wang <[email protected]>
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.
Code conforms to C++ style guidelines
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.
Code conforms to Python style guidelines
Signed-off-by: Bo Wang <[email protected]>
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.
There are some changes that do not conform to C++ style guidelines:
diff --git a/home/runner/work/TensorRT/TensorRT/core/compiler.cpp b/tmp/changes.txt
index 178d3c4..8599be8 100644
--- a/home/runner/work/TensorRT/TensorRT/core/compiler.cpp
+++ b/tmp/changes.txt
@@ -142,7 +142,7 @@ partitioning::GraphAndMapping BuildHybridGraph(
partitioning::Partition(&partitioning_ctx, collection_input_ivalues_map);
- for (auto &partitioned_block : partitioning_ctx.partitioned_blocks) {
+ for (auto& partitioned_block : partitioning_ctx.partitioned_blocks) {
partitioning::PartitionedGraph& segmented_blocks = partitioned_block.second;
for (auto& seg_block : segmented_blocks) {
diff --git a/home/runner/work/TensorRT/TensorRT/core/partitioning/partitioning.cpp b/tmp/changes.txt
index 1a596a2..0d18f37 100644
--- a/home/runner/work/TensorRT/TensorRT/core/partitioning/partitioning.cpp
+++ b/tmp/changes.txt
@@ -73,7 +73,6 @@ void SetExplicitFallbackNodes(PartitioningCtx* ctx, torch::jit::Block* block) {
// Set the rest nodes to TensorRt
ctx->setNodeExecutorDecision(n, NodeExecutorDecision::kCONVERT);
}
-
}
return;
}
@@ -236,9 +235,12 @@ void resolveTRTNonTensorInputs(PartitioningCtx* ctx, torch::jit::Block* block) {
}
}
if (!inputs_to_resolve.empty()) {
- std::vector<torch::jit::Node*> dependency_nodes = getDependencyNodes(inputs_to_resolve, cur_partitioned_block[i]);
+ std::vector<torch::jit::Node*> dependency_nodes =
+ getDependencyNodes(inputs_to_resolve, cur_partitioned_block[i]);
dependency_nodes.insert(
- dependency_nodes.end(), cur_partitioned_block[i].raw_nodes().begin(), cur_partitioned_block[i].raw_nodes().end());
+ dependency_nodes.end(),
+ cur_partitioned_block[i].raw_nodes().begin(),
+ cur_partitioned_block[i].raw_nodes().end());
cur_partitioned_block[i] = SegmentedBlock(SegmentedBlock::kTensorRT, dependency_nodes);
}
}
@@ -339,7 +341,6 @@ void SegmentGraph(PartitioningCtx* ctx, torch::jit::Block* block) {
std::vector<torch::jit::Node*> in_prog_trt_blk_nodes, in_prog_pyt_blk_nodes;
for (const auto n : nodes) {
-
// Skip constant nodes as they are resources for both kinds of modules
if (n->kind() == torch::jit::prim::Constant) {
continue;
@@ -438,7 +439,6 @@ void Partition(PartitioningCtx* ctx, ExampleIValues& example_tensor_map) {
// Go through all the blocks to do the partitioning
for (torch::jit::Block* block : ctx->original_blocks) {
-
// Find all the fallback nodes and build execution decision LUT for all nodes
SetNodeExecutorLUT(ctx, block);
@@ -453,22 +453,17 @@ void Partition(PartitioningCtx* ctx, ExampleIValues& example_tensor_map) {
LOG_DEBUG("Registering input/output torch::jit::Value for segmented graphs");
registerSegmentsOutputs(ctx, block);
- for (auto &i : ctx->partitioned_blocks[block]) {
+ for (auto& i : ctx->partitioned_blocks[block]) {
LOG_DEBUG(i);
}
// run shape analysis on each segmented block
runShapeAnalysis(ctx, block, example_tensor_map);
-
}
-
-
-// for (uint64_t i = 0; i < ctx->blocks.size(); i++) {
-// ctx->blocks[i].update_id(i);
-// }
-
-
+ // for (uint64_t i = 0; i < ctx->blocks.size(); i++) {
+ // ctx->blocks[i].update_id(i);
+ // }
}
} // namespace partitioning
diff --git a/home/runner/work/TensorRT/TensorRT/core/partitioning/stitching.cpp b/tmp/changes.txt
index f8a9633..42cfe9d 100644
--- a/home/runner/work/TensorRT/TensorRT/core/partitioning/stitching.cpp
+++ b/tmp/changes.txt
@@ -97,7 +97,6 @@ void AddIfBlockToGraph(
return;
}
-
GraphAndMapping Stitch(PartitioningCtx* ctx, torch::jit::Block* block) {
auto new_g = std::make_shared<torch::jit::Graph>();
@@ -146,8 +145,7 @@ GraphAndMapping Stitch(PartitioningCtx* ctx, torch::jit::Block* block) {
}
}
return {new_g, old_to_new_g};
-
-}
-}
-}
}
+} // namespace partitioning
+} // namespace core
+} // namespace torch_tensorrt
diff --git a/home/runner/work/TensorRT/TensorRT/core/partitioning/partitioningctx/PartitioningCtx.cpp b/tmp/changes.txt
index 4b8368d..3c1db64 100644
--- a/home/runner/work/TensorRT/TensorRT/core/partitioning/partitioningctx/PartitioningCtx.cpp
+++ b/tmp/changes.txt
@@ -38,7 +38,7 @@ void PartitioningCtx::setNodeExecutorDecision(torch::jit::Node* n, NodeExecutorD
// NOTE: This is this way due to partitioning.cpp L#134 I dont know if this is what we should do.
auto result = node_executor_decision_map[n] = decision;
- return ;
+ return;
}
bool PartitioningCtx::shouldNodeRunInTorch(torch::jit::Node* n) {
ERROR: Some files do not conform to style guidelines
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.
Code conforms to Python style guidelines
Signed-off-by: Bo Wang <[email protected]>
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.
There are some changes that do not conform to C++ style guidelines:
diff --git a/home/runner/work/TensorRT/TensorRT/core/partitioning/partitioning.cpp b/tmp/changes.txt
index 86cfd6d..53b9f22 100644
--- a/home/runner/work/TensorRT/TensorRT/core/partitioning/partitioning.cpp
+++ b/tmp/changes.txt
@@ -454,7 +454,6 @@ void Partition(PartitioningCtx* ctx, ExampleIValues& example_tensor_map) {
LOG_DEBUG("Registering input/output torch::jit::Value for segmented graphs");
RegisterSegmentsOutputs(ctx, block);
-
// run shape analysis on each segmented block
RunShapeAnalysis(ctx, block, example_tensor_map);
}
ERROR: Some files do not conform to style guidelines
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.
Code conforms to Python style guidelines
Signed-off-by: Bo Wang <[email protected]>
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.
Code conforms to C++ style guidelines
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.
Code conforms to Python style guidelines
Signed-off-by: Dheeraj Peri <[email protected]>
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.
Code conforms to C++ style guidelines
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.
Code conforms to Python style guidelines
Signed-off-by: Dheeraj Peri <[email protected]>
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.
Code conforms to Python style guidelines
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.
Code conforms to C++ style guidelines
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.
Code conforms to Python style guidelines
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.
Code conforms to C++ style guidelines
Description
It is incredibly hard to track the state of the partitioning process because the pipeline relies on a number of shared lookup tables that are modified in place during the course of partitioning.
PartitioningCtx
, similar toConversionCtx
centralizes key information like decisions about node executors, user settings, the in progress graph etc. so that this information is uniformly managed and queryable at any point during the pipelines execution. This means it is hard to client code to alter state in unpredictable ways and it also reduces the amount of arguments that need to be passed to each phase.Addresses #949
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: