Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWilkinson committed Sep 10, 2024
1 parent 1416dad commit dd477b4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/offline_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import torch

from vllm import LLM, SamplingParams
from vllm.profiler import nm_profile
from vllm.profiler import layerwise_profile

BATCH_SIZE_DEFAULT = 1
PROMPT_LEN_DEFAULT = 256
Expand Down Expand Up @@ -78,7 +78,7 @@ def run_profile(context: ProfileContext, csv_output: Optional[str],
f"larger than max_num_batched_tokens ({max_num_batched_tokens}) "
f"and therefore cannot be run in a single profile step, please "
f"choose a smaller batch size or prompt length, or increase "
f"--max_num_batched_tokens")
f"--max-num-batched-tokens")
sys.exit(-1)
if batch_size >= max_num_seqs:
print(
Expand Down Expand Up @@ -106,12 +106,12 @@ def run_profile(context: ProfileContext, csv_output: Optional[str],
inputs={'prompt_token_ids': prompt_token_ids},
params=sampling_params)

with nm_profile() as prefill_prof:
with layerwise_profile() as prefill_prof:
llm.llm_engine.step() # First step is prefill

decode_results_list = []
for x in range(args.output_len - 1):
with nm_profile() as decode_prof:
with layerwise_profile() as decode_prof:
llm.llm_engine.step()
decode_results_list.append(decode_prof.results)

Expand Down
4 changes: 2 additions & 2 deletions vllm/profiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .nm_profile import nm_profile
from .layerwise_profile import layerwise_profile

__all__ = [
"nm_profile",
"layerwise_profile",
]
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _StatsTreeNode:


@dataclass
class NMProfileResults(profile):
class LayerwiseProfileResults(profile):
_kineto_results: _ProfilerResult
_kineto_event_correlation_map: Dict[int,
List[_KinetoEvent]] = field(init=False)
Expand Down Expand Up @@ -331,7 +331,7 @@ def df_traversal(node: _StatsTreeNode, curr_json_list: List[Dict]):
return root_dicts


class nm_profile(profile):
class layerwise_profile(profile):

def __init__(self):
super().__init__(
Expand All @@ -346,4 +346,4 @@ def __enter__(self):

def __exit__(self, exc_type, exc_val, exc_tb):
super().__exit__(exc_type, exc_val, exc_tb)
self.results = NMProfileResults(self.profiler.kineto_results)
self.results = LayerwiseProfileResults(self.profiler.kineto_results)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
from typing import Dict

from vllm.profiler.nm_profile import ModelStatsEntry, SummaryStatsEntry
from vllm.profiler.layerwise_profile import ModelStatsEntry, SummaryStatsEntry
from vllm.profiler.utils import TablePrinter, indent_string


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import argparse
import copy
import json
Expand Down Expand Up @@ -426,6 +427,9 @@ def make_plot_title_suffix(profile_json: dict) -> str:

output_directory = args.output_directory if args.output_directory else Path(
args.json_trace).parent

if not os.path.exists(output_directory):
os.makedirs(output_directory)

main(Path(args.json_trace), output_directory, depth, args.plot_metric,
make_names_unique, args.top_k, args.fold_json_node)

0 comments on commit dd477b4

Please sign in to comment.