Skip to content

Commit c3466da

Browse files
Krovatkinfacebook-github-bot
authored andcommitted
Disable profiling when getGraphExecutorOptimize is unset (pytorch#46479)
Summary: `getGraphExecutorOptimize` mandates we don't do any optimizations beyond what's required to run graphs. In this scenario, we don't want to do any profiling as profiling information will not be used. Pull Request resolved: pytorch#46479 Reviewed By: ZolotukhinM Differential Revision: D24368292 Pulled By: Krovatkin fbshipit-source-id: a2c7618d459efca9cb0700c4d64d829b352792a8
1 parent 6a2f40d commit c3466da

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

torch/csrc/jit/runtime/profiling_graph_executor_impl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,21 @@ ExecutionPlan ProfilingGraphExecutorImpl::getPlanFor(
452452
std::lock_guard<std::mutex> lock(compile_mutex);
453453
GRAPH_DEBUG("Running ProfilingGraphExecutorImpl ", this);
454454

455+
// no opt mode
456+
if (!getGraphExecutorOptimize()) {
457+
if (!fallback_plan_) {
458+
auto copy = graph->copy();
459+
GRAPH_DEBUG(
460+
"Before LowerGradOf (beginning of runNooptPassPipeline)\n", *graph);
461+
LowerGradOf(*copy);
462+
GRAPH_DEBUG("After LowerGradOf, before RemoveExpands\n", *graph);
463+
RemoveExpands(copy);
464+
fallback_plan_ = ExecutionPlan(copy, function_name_);
465+
GRAPH_DUMP("NoOpt Graph: ", copy);
466+
}
467+
return *fallback_plan_;
468+
}
469+
455470
// if tensorExprFuserEnabled() returns true we need to persist the very first
456471
// time ProfilingGraphExecutorImpl is called, so we can update it correctly
457472
// for fallback functions in ProfilingGraphExecutorImpl Else,

torch/csrc/jit/runtime/profiling_graph_executor_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct ProfilingGraphExecutorImpl : public GraphExecutorImplBase {
2222
c10::optional<ExecutionPlan>
2323
profiling_plan_; // plan to run in order to profiling the code
2424
c10::optional<ExecutionPlan> optimized_plan_;
25+
// this plan is used if getGraphExecutorOptimize is unset
26+
c10::optional<ExecutionPlan> fallback_plan_;
2527
// fallback functions are inserted for tensorexpr fusion groups
2628
// and by specialize_autogradzero. Whenever, at runtime, input
2729
// tensor don't match profiled properties, fallback functions are called

0 commit comments

Comments
 (0)