[Piecewise] support disable decode cuda graph when enable piecewise cuda graph (#13965)

This commit is contained in:
Stefan He
2025-11-26 18:35:59 -08:00
committed by GitHub
parent 70c6f95107
commit 9f340ab1fb
3 changed files with 44 additions and 33 deletions

View File

@@ -433,19 +433,24 @@ class SGLangBackend:
self,
).run(*example_inputs)
graph_path = os.path.join(local_cache_dir, "computation_graph.py")
if not os.path.exists(graph_path):
# code adapted from https://github.com/thuml/depyf/blob/dab831108a752d1facc00acdd6d4243891845c37/depyf/explain/patched_lazy_format_graph_code.py#L30 # noqa
# use `print_readable` because it can include submodules
src = (
"from __future__ import annotations\nimport torch\n"
+ self.split_gm.print_readable(print_output=False)
)
src = src.replace("<lambda>", "GraphModule")
with open(graph_path, "w") as f:
f.write(src)
rank = torch.distributed.get_rank()
rank0_log(f"Computation graph saved to {graph_path}")
if rank == 0:
graph_path = os.path.join(
local_cache_dir, f"computation_graph_{time.time()}.py"
)
if not os.path.exists(graph_path):
# code adapted from https://github.com/thuml/depyf/blob/dab831108a752d1facc00acdd6d4243891845c37/depyf/explain/patched_lazy_format_graph_code.py#L30 # noqa
# use `print_readable` because it can include submodules
src = (
"from __future__ import annotations\nimport torch\n"
+ self.split_gm.print_readable(print_output=False)
)
src = src.replace("<lambda>", "GraphModule")
with open(graph_path, "w") as f:
f.write(src)
rank0_log(f"Computation graph saved to {graph_path}")
self._called = True
return self.split_gm