| Utilities for converting data types into structured JSON for dumping. |
| from typing import Any, Dict, List, Sequence, Set |
| import torch._logging._internal |
| INTERN_TABLE: Dict[str, int] = {} |
| DUMPED_FILES: Set[str] = set() |
| def intern_string(s: str) -> int: |
| r = INTERN_TABLE.get(s, None) |
| torch._logging._internal.trace_structured( |
| "str", lambda: (s, r), suppress_context=True |
| def dump_file(filename: str) -> None: |
| if "eval_with_key" not in filename: |
| if filename in DUMPED_FILES: |
| DUMPED_FILES.add(filename) |
| from torch.fx.graph_module import _loader |
| torch._logging._internal.trace_structured( |
| payload_fn=lambda: _loader.get_source(filename), |
| def from_traceback(tb: Sequence[traceback.FrameSummary]) -> List[Dict[str, Any]]: |
| # dict naming convention here coincides with |
| # python/combined_traceback.cpp |
| "filename": intern_string(frame.filename), |