Fix unbound local error for return_val (#7395)

......
File "torch/_dynamo/backends/common.py", line 72, in
_wrapped_bw_compiler
  return disable(disable(bw_compiler_fn)(*args, **kwargs))
File "torch/_dynamo/eval_frame.py", line 838, in _fn
  return fn(*args, **kwargs)
File "deepspeed/compile/inductor.py", line 27, in wrapped_compiler
  mod_graph = dc_compiler(gm, fake_inputs)
File "deepspeed/compile/backend.py", line 330, in make_bw_graph
  run_opt_passes(
File "deepspeed/compile/backend.py", line 206, in run_opt_passes
  mem_prof.run(*create_inputs_fn())
File "deepspeed/compile/profilers/graph_profile.py", line 261, in run
  return return_val
UnboundLocalError: local variable 'return_val' referenced before
assignment

Signed-off-by: Hollow Man <hollowman@opensuse.org>
Co-authored-by: Masahiro Tanaka <81312776+tohtana@users.noreply.github.com>
This commit is contained in:
ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟
2025-06-27 20:10:01 +03:00
committed by GitHub
parent 59bb08bf90
commit 6c469425dc

View File

@ -96,6 +96,7 @@ class ProfilingInterpreter(Interpreter):
args: inputs to the graph. Tensors in the inpusts must be real tensors, not fake tensors. args can contain ds parameters.
returns: The output of the graph. Tensor in the output is real tensors.
"""
return_val = None
try:
assert _all_real_if_tensor(args), "Inputs must be real tensors"
self.nz3.enable_profiling(True)
@ -242,6 +243,7 @@ class MemoryProfilingInterpreter(Interpreter):
self.debug_log = debug_log
def run(self, *args) -> Any:
return_val = None
try:
assert _all_real_if_tensor(args), "Inputs must be real tensors"
self.nz3.enable_profiling(True)