-
Notifications
You must be signed in to change notification settings - Fork 27
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
add extract gpt result script #142
Open
ouyangyu
wants to merge
3
commits into
master
Choose a base branch
from
dev_oneflow_extract_gpt_result
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
import argparse | ||
from extract_util import extract_result | ||
|
||
|
||
parser = argparse.ArgumentParser(description="flags for GPT benchmark") | ||
parser.add_argument( | ||
"--benchmark_log_dir", type=str, default="./logs/oneflow", required=False | ||
) | ||
parser.add_argument("--start_iter", type=int, default=300) | ||
parser.add_argument("--end_iter", type=int, default=400) | ||
parser.add_argument("--print_mode", type=str, default="markdown") | ||
args = parser.parse_args() | ||
|
||
|
||
def extract_info_from_file(log_file): | ||
""" | ||
num_nodes ....................................... 1 | ||
num_gpus_per_node ............................... 8 | ||
data_parallel_size .............................. 1 | ||
tensor_model_parallel_size ...................... 8 | ||
pipeline_model_parallel_size .................... 1 | ||
global_batch_size ............................... 32 | ||
micro_batch_size ................................ 32 | ||
num_accumulation_steps .......................... 1 | ||
num_layers ...................................... 16 | ||
hidden_size ..................................... 2304 | ||
num_attention_heads ............................. 16 | ||
seq_length ...................................... 2048 | ||
log_interval .................................... 1 | ||
Training... | ||
| step | micro_batches | samples | throughput | latency | loss | | ||
| -------- | --------------- | --------------- | ---------- | ---------- | ---------- | | ||
| 1 | 1 | 32 | 3.65895 | 8.74569 | 11.27187 | | ||
| 2 | 2 | 64 | 5.92391 | 5.40183 | 22.54614 | | ||
| 3 | 3 | 96 | 33.08657 | 0.96716 | 33.82825 | | ||
| 4 | 4 | 128 | 32.91274 | 0.97227 | 45.10602 | | ||
| 5 | 5 | 160 | 33.05942 | 0.96795 | 56.36795 | | ||
| 6 | 6 | 192 | 32.97452 | 0.97045 | 67.64371 | | ||
| 7 | 7 | 224 | 32.75634 | 0.97691 | 78.92993 | | ||
| 8 | 8 | 256 | 33.13264 | 0.96581 | 90.20315 | | ||
| 9 | 9 | 288 | 33.01570 | 0.96924 | 101.47802 | | ||
utilization.gpu [%], memory.used [MiB] | ||
100 %, 13858 MiB | ||
100 %, 13994 MiB | ||
100 %, 13994 MiB | ||
100 %, 13994 MiB | ||
100 %, 13994 MiB | ||
93 %, 13994 MiB | ||
100 %, 14102 MiB | ||
100 %, 13850 MiB | ||
""" | ||
# extract info from file name | ||
# print('extract file:',log_file) | ||
result_dict = {} | ||
with open(log_file, "r") as f: | ||
for line in f.readlines(): | ||
ss = line.split(" ") | ||
if len(ss) == 5 and ss[2] in [ | ||
"num_nodes", | ||
"num_gpus_per_node", | ||
"data_parallel_size", | ||
"tensor_model_parallel_size", | ||
"pipeline_model_parallel_size", | ||
"micro_batch_size", | ||
"global_batch_size", | ||
"num_accumulation_steps", | ||
"num_layers", | ||
"hidden_size", | ||
"num_attention_heads", | ||
"seq_length", | ||
"log_interval", | ||
]: | ||
result_dict[ss[2]] = ss[-1].strip() | ||
elif len(ss) == 4 and "MiB" in line and "utilization" not in line: | ||
memory_userd = int(ss[-2]) | ||
if ( | ||
"memory" not in result_dict.keys() | ||
or result_dict["memory"] < memory_userd | ||
): | ||
result_dict["memory"] = memory_userd | ||
|
||
ss = line.split("|") | ||
if len(ss) == 8 and "loss" not in line and "-" not in line: | ||
tmp_line = "".join(line.split(" ")).split("|") | ||
result_dict["throughput_{}".format(tmp_line[1])] = float(tmp_line[4]) | ||
result_dict["latency_{}".format(tmp_line[1])] = ( | ||
float(tmp_line[5]) * 1000 | ||
) | ||
|
||
return result_dict | ||
|
||
|
||
if __name__ == "__main__": | ||
extract_result(args, extract_info_from_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
import glob | ||
from statistics import median | ||
|
||
|
||
def compute_throughput(result_dict, args): | ||
throughput = 0 | ||
latency = 0 | ||
log_interval = int(result_dict["log_interval"]) | ||
for i in range(args.start_iter, args.end_iter + log_interval, log_interval): | ||
throughput += result_dict["throughput_{}".format(i)] | ||
latency += result_dict["latency_{}".format(i)] | ||
|
||
return ( | ||
latency / (args.end_iter - args.start_iter), | ||
throughput / (args.end_iter - args.start_iter), | ||
) | ||
|
||
|
||
def get_mode_print(mode): | ||
def mode_print(lst): | ||
if mode == "markdown": | ||
print( | ||
"|", | ||
" | ".join( | ||
("{:.2f}" if type(v) is float else "{}").format(v) for v in lst | ||
), | ||
"|", | ||
) | ||
else: | ||
print( | ||
",".join( | ||
("{:.2f}" if type(v) is float else "{}").format(v) for v in lst | ||
) | ||
) | ||
|
||
return mode_print | ||
|
||
|
||
def extract_result(args, extract_func): | ||
mode_print = get_mode_print(args.print_mode) | ||
logs_list = glob.glob(os.path.join(args.benchmark_log_dir, "*/*.log")) | ||
logs_list = sorted(logs_list) | ||
|
||
throughput_final_result_dict = {} | ||
memory_final_result_dict = {} | ||
lantency_final_result_dict = {} | ||
print("## All Results") | ||
header_list = ["case", "memory", "lantency", "throuthput(sample/sec)"] | ||
mode_print(header_list) | ||
if args.print_mode == "markdown": | ||
mode_print(["--------" for _ in range(4)]) | ||
for l in logs_list: | ||
result_dict = extract_func(l) | ||
lantency, throughput = compute_throughput(result_dict, args) | ||
case = "{num_nodes}n{num_gpus_per_node}g_dp{data_parallel_size}_mp{tensor_model_parallel_size}_pp{pipeline_model_parallel_size}_mbs{micro_batch_size}_gbs{global_batch_size}_na{num_accumulation_steps}_l{num_layers}_hs{hidden_size}_nah{num_attention_heads}_sl{seq_length}".format( | ||
**result_dict | ||
) | ||
mode_print( | ||
[ | ||
case, | ||
"{} (MiB)".format(result_dict["memory"]), | ||
"{} (ms)".format(round(lantency, 2)), | ||
throughput, | ||
] | ||
) | ||
|
||
if case in throughput_final_result_dict: | ||
throughput_final_result_dict[case].append(throughput) | ||
memory_final_result_dict[case].append(result_dict["memory"]) | ||
lantency_final_result_dict[case].append(lantency) | ||
else: | ||
throughput_final_result_dict[case] = [throughput] | ||
memory_final_result_dict[case] = [result_dict["memory"]] | ||
lantency_final_result_dict[case] = [lantency] | ||
|
||
# calculate median throughput and speedup | ||
final_result_list = [] | ||
for k, v in throughput_final_result_dict.items(): | ||
final_result_list.append( | ||
[ | ||
k, | ||
max(memory_final_result_dict[k]), | ||
median(lantency_final_result_dict[k]), | ||
median(v), | ||
] | ||
) | ||
|
||
# sort final_result_list | ||
# final_result_list = sorted(final_result_list, key=lambda x: (-x[2], x[0], x[1])) | ||
|
||
# print results | ||
print("## Filtered Result `median value`") | ||
mode_print(["case", "memory (MiB)", "lantency (ms)", "throuthput(sample/sec)"]) | ||
if args.print_mode == "markdown": | ||
mode_print(["--------" for _ in range(5)]) | ||
for res in final_result_list: | ||
mode_print(res) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
every step?