-
Notifications
You must be signed in to change notification settings - Fork 92
Enhance performance test #1610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Enhance performance test #1610
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,65 +1,125 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Optional, Dict | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| LOG_DIR = "/auto-round/log_dir" | ||||||||||||||||||||||||||||||||||||||||||||||
| logging.basicConfig(level=logging.INFO, format="%(message)s") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| LOG_DIR = Path("/auto-round/log_dir") | ||||||||||||||||||||||||||||||||||||||||||||||
| OUTPUT_BASE_DIR = Path("/auto-round/.azure-pipelines/scripts/performance") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def parse_tuning_time(log_file): | ||||||||||||||||||||||||||||||||||||||||||||||
| with open(log_file, "r") as f: | ||||||||||||||||||||||||||||||||||||||||||||||
| content = f.read() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| pattern = r"tuning time ([0-9]+\.[0-9]+)" | ||||||||||||||||||||||||||||||||||||||||||||||
| match = re.search(pattern, content) | ||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||
| class QuantMetrics: | ||||||||||||||||||||||||||||||||||||||||||||||
| tuning_time_s: Optional[float] = None | ||||||||||||||||||||||||||||||||||||||||||||||
| peak_ram_gb: Optional[float] = None | ||||||||||||||||||||||||||||||||||||||||||||||
| peak_vram_gb: Optional[float] = None | ||||||||||||||||||||||||||||||||||||||||||||||
| output_size_gb: Optional[float] = None | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if match: | ||||||||||||||||||||||||||||||||||||||||||||||
| elapsed = str_to_float(match.group(1)) | ||||||||||||||||||||||||||||||||||||||||||||||
| return elapsed | ||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def get_dir_size_gb(path: Path) -> float: | ||||||||||||||||||||||||||||||||||||||||||||||
| if not path.exists() or not path.is_dir(): | ||||||||||||||||||||||||||||||||||||||||||||||
| return 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def str_to_float(value): | ||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||
| return round(float(value), 4) | ||||||||||||||||||||||||||||||||||||||||||||||
| except ValueError: | ||||||||||||||||||||||||||||||||||||||||||||||
| return value | ||||||||||||||||||||||||||||||||||||||||||||||
| total_bytes = sum(f.stat().st_size for f in path.rglob("*") if f.is_file()) | ||||||||||||||||||||||||||||||||||||||||||||||
| return round(total_bytes / (1024**3), 4) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def get_tuning_time(): | ||||||||||||||||||||||||||||||||||||||||||||||
| def parse_log_file(log_file: Path) -> QuantMetrics: | ||||||||||||||||||||||||||||||||||||||||||||||
| metrics = QuantMetrics() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if not log_file.exists(): | ||||||||||||||||||||||||||||||||||||||||||||||
| logging.warning(f"Log file not found: {log_file}") | ||||||||||||||||||||||||||||||||||||||||||||||
| return metrics | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| content = log_file.read_text(encoding="utf-8") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| time_match = re.search(r"tuning time ([0-9]+\.[0-9]+)", content) | ||||||||||||||||||||||||||||||||||||||||||||||
| if time_match: | ||||||||||||||||||||||||||||||||||||||||||||||
| metrics.tuning_time_s = round(float(time_match.group(1)), 4) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ram_match = re.search(r"'peak_ram':\s*([\d.]+)GB?.*?,'peak_vram':\s*([\d.]+)GB?", content) | ||||||||||||||||||||||||||||||||||||||||||||||
| if ram_match: | ||||||||||||||||||||||||||||||||||||||||||||||
| metrics.peak_ram_gb = round(float(ram_match.group(1)), 4) | ||||||||||||||||||||||||||||||||||||||||||||||
| metrics.peak_vram_gb = round(float(ram_match.group(2)), 4) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| ram_match = re.search(r"'peak_ram':\s*([\d.]+)GB?.*?,'peak_vram':\s*([\d.]+)GB?", content) | |
| if ram_match: | |
| metrics.peak_ram_gb = round(float(ram_match.group(1)), 4) | |
| metrics.peak_vram_gb = round(float(ram_match.group(2)), 4) | |
| # Parse peak RAM independently of VRAM and whitespace formatting | |
| ram_match = re.search(r"'peak_ram':\s*([\d.]+)GB?", content) | |
| if ram_match: | |
| metrics.peak_ram_gb = round(float(ram_match.group(1)), 4) | |
| # Parse peak VRAM; handle both scalar and multi-device dict formats | |
| vram_simple_match = re.search(r"'peak_vram':\s*([\d.]+)GB?", content) | |
| if vram_simple_match: | |
| metrics.peak_vram_gb = round(float(vram_simple_match.group(1)), 4) | |
| else: | |
| # Example dict format: 'peak_vram': {'cuda:0': 1.2GB, 'cuda:1': 1.5GB} | |
| vram_dict_match = re.search(r"'peak_vram':\s*\{([^}]+)\}", content) | |
| if vram_dict_match: | |
| vram_body = vram_dict_match.group(1) | |
| values = re.findall(r"([\d.]+)GB?", vram_body) | |
| if values: | |
| max_vram = max(float(v) for v in values) | |
| metrics.peak_vram_gb = round(max_vram, 4) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,9 +37,8 @@ function run_performance_test() { | |
| test_mode=$1 | ||
| cd /auto-round/.azure-pipelines/scripts/performance | ||
| local log_file="perf_test_${test_mode}.log" | ||
| rm -rf "saved" "${LOG_DIR}/${log_file}" | ||
| echo "##[group]run ${test_mode} performance test..." | ||
| auto-round --model_name ${model_name} --bits 4 --iters 200 --enable_torch_compile --device hpu --output_dir ./saved 2>&1 | tee -a "${LOG_DIR}/${log_file}" | ||
| auto-round --model_name ${model_name} --bits 4 --iters 200 --enable_torch_compile --device hpu --output_dir "./${test_mode}" 2>&1 | tee -a "${LOG_DIR}/${log_file}" | ||
| echo "##[endgroup]" | ||
|
Comment on lines
39
to
42
|
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse_log_file()usesre.search(...), which returns the first match in the file. If logs are appended (or contain multiple iterations), this will capture an older run rather than the most recent one. Preferre.findall(...)and use the last match, or ensure the log file is overwritten/cleared before each run.