Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions rl_insight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
"""
Cluster scheduling analysis and visualization for RL workloads.

This package exposes:

- ``main.main``: CLI entry point
- ``mstx_parser.MstxClusterParser``: parser for Ascend MSTX traces
This package exposes parser modules and a CLI entry helper.
"""

from .main import main # noqa: F401

from .parser import mstx_parser
from .parser import torch_parser

__all__ = ["mstx_parser", "torch_parser"]

def main():
# Lazy import avoids preloading rl_insight.main during package import.
from .main import main as _main

return _main()


__all__ = ["mstx_parser", "torch_parser", "main"]
2 changes: 1 addition & 1 deletion rl_insight/parser/mstx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def parse_analysis_data(
return events

for row in data:
if row.get("pid") != process_id:
if row.get("pid") != process_id or row.get("ph") != "X":
continue

args = row.get("args")
Expand Down
7 changes: 4 additions & 3 deletions rl_insight/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ def mapper_func(self, data_maps: list[DataMap]):
try:
result = future.result()
results.append(result)
logger.info(
f"Completed rank {rank_id}: {completed}/{total_ranks} ({progress:.1f}%)"
)
if completed % (total_ranks // 10) == 0:
logger.info(
f"Completed rank {rank_id}: {completed}/{total_ranks} ({progress:.1f}%)"
)
Comment on lines +83 to +86

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The expression total_ranks // 10 can result in zero if total_ranks is less than 10. This will cause a ZeroDivisionError when calculating completed % 0. To prevent this crash, you should ensure the divisor is at least 1. A concise way to fix this is to use (total_ranks // 10 or 1), which defaults to 1 if the integer division result is 0.

Suggested change
if completed % (total_ranks // 10) == 0:
logger.info(
f"Completed rank {rank_id}: {completed}/{total_ranks} ({progress:.1f}%)"
)
if completed % (total_ranks // 10 or 1) == 0:
logger.info(
f"Completed rank {rank_id}: {completed}/{total_ranks} ({progress:.1f}%)"
)

except Exception as e:
logger.error(f"Failed to process rank {rank_id}: {e}")

Expand Down
Loading