Update Optional[x] -> x | None and Union[x, y] to x | y (#26633)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
|
||||
import copy
|
||||
from collections import defaultdict
|
||||
from collections.abc import Callable
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from typing import Any, Callable, Optional, TypeAlias, Union
|
||||
from typing import Any, Optional, TypeAlias
|
||||
|
||||
import pandas as pd
|
||||
from torch._C._autograd import DeviceType, _KinetoEvent, _ProfilerResult
|
||||
@@ -62,14 +63,14 @@ class ModelStatsEntry:
|
||||
trace: str
|
||||
|
||||
|
||||
StatsEntry: TypeAlias = Union[ModelStatsEntry, SummaryStatsEntry]
|
||||
StatsEntry: TypeAlias = ModelStatsEntry | SummaryStatsEntry
|
||||
|
||||
|
||||
@dataclass
|
||||
class _StatsTreeNode:
|
||||
entry: StatsEntry
|
||||
children: list[StatsEntry]
|
||||
parent: Optional[StatsEntry]
|
||||
parent: StatsEntry | None
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -82,7 +83,7 @@ class LayerwiseProfileResults(profile):
|
||||
_summary_stats_tree: list[_StatsTreeNode] = field(init=False)
|
||||
|
||||
# profile metadata
|
||||
num_running_seqs: Optional[int] = None
|
||||
num_running_seqs: int | None = None
|
||||
|
||||
def __post_init__(self):
|
||||
self._build_correlation_map()
|
||||
@@ -150,7 +151,7 @@ class LayerwiseProfileResults(profile):
|
||||
@staticmethod
|
||||
def _indent_row_names_based_on_depth(
|
||||
depths_rows: list[tuple[int, StatsEntry]],
|
||||
indent_style: Union[Callable[[int], str], str] = " ",
|
||||
indent_style: Callable[[int], str] | str = " ",
|
||||
):
|
||||
indented_rows = []
|
||||
for depth, row in depths_rows:
|
||||
@@ -171,7 +172,7 @@ class LayerwiseProfileResults(profile):
|
||||
event_tree = self._kineto_results.experimental_event_tree()
|
||||
|
||||
def _df_traversal(
|
||||
event: _ProfilerEvent, curr_node: Optional[_ModuleTreeNode] = None
|
||||
event: _ProfilerEvent, curr_node: _ModuleTreeNode | None = None
|
||||
):
|
||||
# For the tensor parallel case for now only look at task 1
|
||||
if event.start_tid != 1:
|
||||
@@ -242,7 +243,7 @@ class LayerwiseProfileResults(profile):
|
||||
|
||||
def build_summary_stats_tree_df(
|
||||
node: _ModuleTreeNode,
|
||||
parent: Optional[_StatsTreeNode] = None,
|
||||
parent: _StatsTreeNode | None = None,
|
||||
summary_trace: tuple[str] = (),
|
||||
):
|
||||
if event_has_module(node.event):
|
||||
@@ -287,7 +288,7 @@ class LayerwiseProfileResults(profile):
|
||||
self._summary_stats_tree.append(build_summary_stats_tree_df(root))
|
||||
|
||||
def build_model_stats_tree_df(
|
||||
node: _ModuleTreeNode, parent: Optional[_StatsTreeNode] = None
|
||||
node: _ModuleTreeNode, parent: _StatsTreeNode | None = None
|
||||
):
|
||||
if event_has_module(
|
||||
node.event,
|
||||
@@ -357,7 +358,7 @@ class LayerwiseProfileResults(profile):
|
||||
|
||||
|
||||
class layerwise_profile(profile):
|
||||
def __init__(self, num_running_seqs: Optional[int] = None):
|
||||
def __init__(self, num_running_seqs: int | None = None):
|
||||
"""
|
||||
layerwise profile constructor.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import dataclasses
|
||||
from typing import Callable, Union
|
||||
from collections.abc import Callable
|
||||
|
||||
from torch._C._profiler import _EventType, _ProfilerEvent, _TensorMetadata
|
||||
|
||||
@@ -78,7 +78,7 @@ class TablePrinter:
|
||||
|
||||
|
||||
def indent_string(
|
||||
string: str, indent: int, indent_style: Union[Callable[[int], str], str] = " "
|
||||
string: str, indent: int, indent_style: Callable[[int], str] | str = " "
|
||||
) -> str:
|
||||
if indent:
|
||||
if isinstance(indent_style, str):
|
||||
|
||||
Reference in New Issue
Block a user