Skip to content

Commit b4ed526

Browse files
xuzhao9facebook-github-bot
authored andcommitted
Upload raw logs to Manifold with env "TRITONPARSE_TRACE_MANIFOLD" (#360)
Summary: X-link: meta-pytorch/tritonbench#961 Add Manifold upload support for tritonparse traces as an alternative to Logarithm. When enabled via the TRITONPARSE_TRACE_MANIFOLD env var, traces are automatically uploaded to the pyper_traces Manifold bucket on stream cleanup, providing more accessible and persistent trace storage. Reviewed By: FindHao Differential Revision: D94970563
1 parent db474ed commit b4ed526

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

tritonparse/parse/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ def gzip_single_file(file_path: str, verbose: bool = False) -> str:
242242
shutil.copyfileobj(f_in, f_out)
243243

244244
# Delete the original file after successful compression
245-
os.remove(file_path)
245+
if os.path.exists(file_path):
246+
os.remove(file_path)
246247
if verbose:
247248
logger.info(f"Deleted original file {file_path}")
248249

tritonparse/structured_logging.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@
120120
TRITONPARSE_TENSOR_SAVE_MAX_RUNS = int(
121121
os.getenv("TRITONPARSE_TENSOR_SAVE_MAX_RUNS", "0")
122122
)
123+
# Whether upload to Manifold
124+
TRITONPARSE_TRACE_MANIFOLD = bool(os.getenv("TRITONPARSE_TRACE_MANIFOLD", None))
123125

124126
TRITON_TRACE_HANDLER = None
125127
# Global tensor blob manager instance
@@ -1097,19 +1099,19 @@ def emit(self, record):
10971099
else:
10981100
file_extension = ".ndjson"
10991101
file_mode = "a+"
1100-
log_file_name = os.path.abspath(
1102+
self.log_file_name = os.path.abspath(
11011103
os.path.join(root_dir, f"{filename}{file_extension}")
11021104
)
11031105
if TRITON_TRACE_COMPRESSION == "clp":
1104-
self.stream = clp_open(log_file_name, file_mode)
1106+
self.stream = clp_open(self.log_file_name, file_mode)
11051107
else:
11061108
self.stream = open(
1107-
log_file_name,
1109+
self.log_file_name,
11081110
mode=file_mode,
11091111
)
11101112
# Update _last_rank after successfully creating the file
11111113
self._last_rank = current_rank
1112-
log.debug("TritonTraceHandler: logging to %s", log_file_name)
1114+
log.debug("TritonTraceHandler: logging to %s", self.log_file_name)
11131115
else:
11141116
triton_trace_log.removeHandler(self)
11151117
return
@@ -1159,6 +1161,16 @@ def _cleanup(self):
11591161
"""Ensure proper cleanup on program exit"""
11601162
if self.stream is not None:
11611163
self.close()
1164+
if (
1165+
TRITONPARSE_TRACE_MANIFOLD
1166+
and hasattr(self, "log_file_name")
1167+
and self.log_file_name
1168+
and os.path.exists(self.log_file_name)
1169+
):
1170+
from tritonparse.fb.uploader import ManifoldTraceUploader
1171+
1172+
manifold_uploader = ManifoldTraceUploader()
1173+
manifold_uploader.upload(self.log_file_name)
11621174

11631175
def _ensure_stream_closed(self):
11641176
"""ensure stream is closed"""
@@ -1192,6 +1204,8 @@ def init_logs():
11921204
if TRITON_TRACE_HANDLER is None:
11931205
TRITON_TRACE_HANDLER = TritonTraceHandler(triton_trace_folder)
11941206
if triton_trace_folder is not None:
1207+
if TRITON_TRACE_HANDLER.root_dir != triton_trace_folder:
1208+
TRITON_TRACE_HANDLER._ensure_stream_closed()
11951209
TRITON_TRACE_HANDLER.root_dir = triton_trace_folder
11961210
# 2) Re-evaluate whether we have a writable directory
11971211
# (`get_root_dir()` also checks /logs logic, permissions, etc.)

0 commit comments

Comments
 (0)