Skip to content

Commit affc3a3

Browse files
FindHaofacebook-github-bot
authored andcommitted
Transform Log Name Usage from String Containment to Regex Pattern Matching
Summary: ### Core Change Converted log name matching from simple string containment checks to regex pattern matching to properly handle wildcard patterns in log filenames. ### Files Modified #### 1. `utils.py` **Function:** `logs_downloaded()` (lines 444-452) * **Before:** `if log_filename in entry:` * **After:** `pattern = re.compile(log_filename) if pattern.search(entry):` **Function:** `download_logs()` (line 318) * **Pattern:** Changed from `f"{LOG_PREFIX}{rank_config.to_rank().to_string('')}"` to `f"{LOG_PREFIX}.*{rank_config.to_rank().to_string('')}"` * #### 2. `common.py` **Function:** `parse_logs()` (lines 288-291) * **Before:** ``` log_name = f"{LOG_PREFIX}{rank_config.to_rank().to_string('')}" if log_name in item: ``` * **After:** ``` log_name = f"{LOG_PREFIX}.*{rank_config.to_rank().to_string('')}" pattern = re.compile(log_name) if pattern.search(item): ``` ### Key Changes 1. **Pattern Enhancement:** Added `.*` wildcard in log name patterns to match variable content between prefix and suffix 2. **Matching Method:** Replaced `in` operator with `re.compile()` and `pattern.search()` for proper regex matching 3. **Consistency:** Applied same regex-based approach across both files ### Impact * Enables proper matching of log files with variable content between prefix and rank suffix * Supports regex wildcards in log filename patterns (e.g., `dedicated_log_triton_trace_.*rank_0`) * Maintains consistent log matching behavior across the codebase * Fixes linting errors while preserving intended functionality Reviewed By: davidberard98 Differential Revision: D78115507 fbshipit-source-id: 26a1e3e79323359aa3ee976531b6b3a5e1ec44fa
1 parent d5975f7 commit affc3a3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

tritonparse/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import Optional, Tuple
1515

1616
from .extract_source_mappings import parse_single_file
17-
from .shared_vars import DEFAULT_TRACE_FILE_PREFIX as LOG_PREFIX
17+
from .shared_vars import DEFAULT_TRACE_FILE_PREFIX_WITHOUT_USER as LOG_PREFIX
1818
from .tp_logger import logger
1919

2020
LOG_RANK_REGEX = re.compile(r"rank_(\d+)")
@@ -285,8 +285,9 @@ def parse_logs(
285285
path = os.path.join(raw_log_dir, item)
286286
if not os.path.isfile(path):
287287
continue
288-
log_name = f"{LOG_PREFIX}{rank_config.to_rank().to_string('')}"
289-
if log_name in item:
288+
log_name = f"{LOG_PREFIX}.*{rank_config.to_rank().to_string('')}"
289+
pattern = re.compile(log_name)
290+
if pattern.search(item):
290291
# Check if the log has a rank in its name
291292
rank_match = LOG_RANK_REGEX.search(item)
292293
if rank_match:

tritonparse/shared_vars.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
DEFAULT_TRACE_FILE_PREFIX = (
77
f"dedicated_log_triton_trace_{os.getenv('USER', 'unknown')}_"
88
)
9+
DEFAULT_TRACE_FILE_PREFIX_WITHOUT_USER = "dedicated_log_triton_trace_"

0 commit comments

Comments
 (0)