-
Notifications
You must be signed in to change notification settings - Fork 118
jhw merge request #784
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
Open
jiahuiwen-baai
wants to merge
95
commits into
flagos-ai:main
Choose a base branch
from
jiahuiwen-baai:main
base: main
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
jhw merge request #784
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
6e9fb85
Perf支持调Gems
jiahuiwen-baai ca432fb
test
jiahuiwen-baai bec5e58
test
jiahuiwen-baai 828de19
test
jiahuiwen-baai 2d5abd6
test
jiahuiwen-baai e63dbc3
rename
jiahuiwen-baai 02c5177
add log
jiahuiwen-baai a150002
add log
jiahuiwen-baai d796265
test
jiahuiwen-baai d9331bb
test
jiahuiwen-baai 66669b0
test
jiahuiwen-baai 21cc84a
add log
jiahuiwen-baai bc1bd1a
test
jiahuiwen-baai af942f0
test
jiahuiwen-baai 393aee1
test
jiahuiwen-baai fe48eb1
'test'
jiahuiwen-baai 272752d
test
jiahuiwen-baai ab8c55b
test
jiahuiwen-baai 4dbb506
Changes
jiahuiwen-baai 893de0f
Merge branch 'main' of https://github.com/FlagOpen/FlagPerf into jhw-…
jiahuiwen-baai 930331c
Merge pull request #1 from FlagOpen/main
jiahuiwen-baai eab2e12
test
jiahuiwen-baai 7b1a3db
test
jiahuiwen-baai f54ca51
test
jiahuiwen-baai 825db4a
test
jiahuiwen-baai fa8a58f
test
jiahuiwen-baai 7c2b934
test + log
jiahuiwen-baai c8ac5b1
test
jiahuiwen-baai e696a2c
test
jiahuiwen-baai e55b090
test
jiahuiwen-baai a0845f0
test
jiahuiwen-baai e50fd81
test add log
jiahuiwen-baai c298033
test
jiahuiwen-baai a1d8c9c
test
jiahuiwen-baai c8f2676
test
jiahuiwen-baai b511b7e
test
jiahuiwen-baai 09bc435
test
jiahuiwen-baai 8d78640
test
jiahuiwen-baai 8879d86
test
jiahuiwen-baai 25e32fe
test
jiahuiwen-baai 501a80b
test
jiahuiwen-baai a96cf88
test
jiahuiwen-baai 234647f
test
jiahuiwen-baai a220710
test
jiahuiwen-baai 0171e42
test
jiahuiwen-baai 4aafdfe
test
jiahuiwen-baai 8a46ca0
Changes
jiahuiwen-baai f09bff7
test
jiahuiwen-baai 83c3d2a
test
jiahuiwen-baai 4e996dc
test
githublic 08d3a9d
test
jiahuiwen-baai ff84256
test
jiahuiwen-baai 1cb0f0a
test
jiahuiwen-baai dc086cf
test
jiahuiwen-baai 872ae8a
test
jiahuiwen-baai c9f0727
test
jiahuiwen-baai 6a83f4d
test
jiahuiwen-baai 1e12413
test
jiahuiwen-baai 9e7f5ac
test
jiahuiwen-baai a85addf
test
jiahuiwen-baai 50a49a4
test
jiahuiwen-baai fea2644
test
jiahuiwen-baai 60bc23c
test
jiahuiwen-baai 587aea5
test
jiahuiwen-baai fd09e05
test
jiahuiwen-baai 8db26c0
test
jiahuiwen-baai 0bfd71a
test
jiahuiwen-baai 733bae9
test
jiahuiwen-baai ae6acde
test
jiahuiwen-baai c3d8359
test
jiahuiwen-baai 48a05da
test
jiahuiwen-baai 720d28a
test
jiahuiwen-baai 9edbf2d
test
jiahuiwen-baai e992b49
Merge pull request #2 from FlagOpen/main
jiahuiwen-baai 9fd6765
update
jiahuiwen-baai 10909b7
delate venv
jiahuiwen-baai 0131d25
update
jiahuiwen-baai 3f86f43
Merge pull request #3 from jiahuiwen-baai/jhw-baai
jiahuiwen-baai a37b848
test
jiahuiwen-baai 1acf9b3
test
jiahuiwen-baai de362cc
test
jiahuiwen-baai 8943d49
调试
jiahuiwen-baai 7ec5985
调试
jiahuiwen-baai c0a45c3
调试
jiahuiwen-baai bf12dfc
调试
jiahuiwen-baai 0117aea
调试
jiahuiwen-baai a210031
调试
jiahuiwen-baai 4533581
调试
jiahuiwen-baai 330b618
调试
jiahuiwen-baai 867f1f1
test
jiahuiwen-baai f666596
test
jiahuiwen-baai c4dd250
test
jiahuiwen-baai 0f0a719
Merge pull request #4 from jiahuiwen-baai/jhw-baai
jiahuiwen-baai 628cde9
test
jiahuiwen-baai ff24eee
Merge pull request #5 from jiahuiwen-baai/jhw-baai
jiahuiwen-baai 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 hidden or 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
This file contains hidden or 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,103 @@ | ||
| # Copyright (c) 2024 BAAI. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License") | ||
| # !/usr/bin/env python3 | ||
| # -*- coding: UTF-8 -*- | ||
|
|
||
| import json | ||
| import os | ||
| from collections import defaultdict | ||
| from loguru import logger | ||
|
|
||
|
|
||
| def parse_log_file(spectflops, mode, warmup, log_dir, result_log_path): | ||
| log_file = os.path.join(log_dir, "result.log.txt") | ||
| save_log_path = os.path.join(result_log_path, "result.json") | ||
| if os.path.isfile(save_log_path): | ||
| with open(save_log_path, 'r+', encoding='utf-8') as file_r: | ||
| try: | ||
| file_r_json = file_r.read() | ||
| res = json.loads(file_r_json) | ||
| result_data = get_result_data(log_file, res, spectflops, mode, warmup) | ||
| file_r.seek(0) | ||
| file_r.write(json.dumps(result_data, ensure_ascii=False)) | ||
| file_r.truncate() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里是想合并两次的结果? |
||
| except json.decoder.JSONDecodeError: | ||
| print("JSONDecodeError json file content is None") | ||
| else: | ||
| with open(save_log_path, 'w') as file_w: | ||
| res = defaultdict(dict) | ||
| result_data = get_result_data(log_file, res, spectflops, mode, warmup) | ||
| file_w.write(json.dumps(result_data, ensure_ascii=False)) | ||
|
|
||
|
|
||
| """ 参数说明 | ||
| # 时延:1 无预热时延 Latency-No warmup:no_warmup_latency,2 预热时延 Latency-Warmup:warmup_latency | ||
| # 吞吐率:3 Raw-Throughput原始吞吐:raw_throughput, 4 Core-Throughput是核心吞吐:core_throughput | ||
| # 算力:5 实际算力开销:ctflops, 6 实际算力利用率:cfu, 7 实际算力开销-内核时间:ktflops, 8 实际算力利用率-内核时间:kfu | ||
| """ | ||
| def get_result_data(log_file, res, spectflops, mode, warmup): | ||
| with open(log_file, 'r') as file_r: | ||
| lines = file_r.readlines() | ||
| for line in lines: | ||
| if line.startswith("[INFO]"): | ||
| json_data = line[6:].strip() | ||
| try: | ||
| data = json.loads(json_data) | ||
| op_name = data.get("op_name") | ||
| dtype = data.get("dtype") | ||
| results = data.get("result") | ||
| for result in results: | ||
| shape_detail = result.get("shape_detail") | ||
| latency_base = result.get("latency_base") | ||
| if mode == "cpu" and warmup == "0": | ||
| no_warmup_latency = result.get("latency") | ||
| parse_data = { | ||
| "op_name": op_name, | ||
| "dtype": dtype, | ||
| "shape_detail": shape_detail, | ||
| "latency_base_cpu_nowarm": latency_base, | ||
| "no_warmup_latency": no_warmup_latency | ||
| } | ||
| res[f"{op_name}_{dtype}_{shape_detail}"].update(parse_data) | ||
| elif mode == "cpu" and warmup != "0": | ||
| warmup_latency = result.get("latency") | ||
| raw_throughput = 1 / float(warmup_latency) | ||
| ctflops = result.get("tflops") | ||
| if ctflops is None: | ||
| cfu = None | ||
| else: | ||
| cfu = round(100.0 * float(ctflops) / 1e12 / float(spectflops), 2) | ||
| parse_data = { | ||
| "op_name": op_name, | ||
| "dtype": dtype, | ||
| "shape_detail": shape_detail, | ||
| "latency_base_cpu_warm": latency_base, | ||
| "warmup_latency": warmup_latency, | ||
| "raw_throughput": raw_throughput, | ||
| "ctflops": ctflops, | ||
| "cfu": cfu | ||
| } | ||
| res[f"{op_name}_{dtype}_{shape_detail}"].update(parse_data) | ||
| elif mode == "cuda" and warmup != "0": | ||
| kerneltime = result.get("latency") | ||
| core_throughput = 1 / float(kerneltime) | ||
| ktflops = result.get("tflops") | ||
| if ktflops is None: | ||
| kfu = None | ||
| else: | ||
| kfu = round(100.0 * float(ktflops) / 1E12 / float(spectflops), 2) | ||
| parse_data = { | ||
| "op_name": op_name, | ||
| "dtype": dtype, | ||
| "shape_detail": shape_detail, | ||
| "latency_base_cuda_warm": latency_base, | ||
| "kerneltime": kerneltime, | ||
| "core_throughput": core_throughput, | ||
| "ktflops": ktflops, | ||
| "kfu": kfu | ||
| } | ||
| res[f"{op_name}_{dtype}_{shape_detail}"].update(parse_data) | ||
| except json.JSONDecodeError as e: | ||
| logger.error(f"Error decoding JSON: {e}") | ||
| return res | ||
This file contains hidden or 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,128 @@ | ||
| # Copyright (c) 2024 BAAI. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License") | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: UTF-8 -*- | ||
| import torch | ||
| import os | ||
| import time | ||
| from argparse import ArgumentParser, Namespace | ||
| import yaml | ||
| import sys | ||
| import subprocess | ||
|
|
||
| sys.path.append("..") | ||
| from drivers.utils import * | ||
| from drivers.calculate import * | ||
| from drivers.parse_log import * | ||
|
|
||
|
|
||
| def parse_args(): | ||
| parser = ArgumentParser(description=" ") | ||
|
|
||
| parser.add_argument("--vendor", | ||
| type=str, | ||
| required=True, | ||
| help="vendor name like nvidia") | ||
| parser.add_argument("--case_name", | ||
| type=str, | ||
| required=True, | ||
| help="op name like mm") | ||
| parser.add_argument("--spectflops", | ||
| type=str, | ||
| required=True, | ||
| help="spectflops of current dataformat") | ||
|
|
||
| parser.add_argument("--dataformat", | ||
| type=str, | ||
| required=True, | ||
| help="like FP32,FP16") | ||
|
|
||
| parser.add_argument("--oplib", | ||
| type=str, | ||
| required=True, | ||
| help="impl like pytorch/flaggems/cpp") | ||
|
|
||
| parser.add_argument("--chip", | ||
| type=str, | ||
| required=True, | ||
| help="chip like A100_40_SXM") | ||
|
|
||
| parser.add_argument("--mode", | ||
| type=str, | ||
| required=True, | ||
| help="mode like cpu") | ||
|
|
||
| parser.add_argument("--warmup", | ||
| type=str, | ||
| required=True, | ||
| help="warmup") | ||
|
|
||
| parser.add_argument("--log_dir", | ||
| type=str, | ||
| required=True, | ||
| help="abs log dir") | ||
|
|
||
| parser.add_argument("--result_log_path", | ||
| type=str, | ||
| required=True, | ||
| help="result log path for FlagPerf/operation/result") | ||
|
|
||
| args, unknown_args = parser.parse_known_args() | ||
| args.unknown_args = unknown_args | ||
| return args | ||
|
|
||
|
|
||
| def main(config): | ||
| correctness = do_correctness(config.case_name) | ||
| correctness = correctness == 0 | ||
|
|
||
| # test operation performance | ||
| performance = do_performance(config.mode, config.warmup, config.log_dir) | ||
| performance = performance == 0 | ||
| parse_log_file(config.spectflops, config.mode, config.warmup, config.log_dir, config.result_log_path) | ||
|
|
||
| # dtype = { | ||
| # "FP32": torch.float32, | ||
| # "FP16": torch.float16, | ||
| # "BF16": torch.bfloat16, | ||
| # "INT32": torch.int32, | ||
| # "INT16": torch.int16, | ||
| # "BOOL": torch.bool | ||
| # } | ||
| # set_ieee_float32(config.vendor) | ||
| # | ||
| # | ||
| # m = case_config.Melements | ||
| # | ||
| # | ||
| # a = torch.randn(m, 1024, 1024, dtype=dtype[config.dataformat]).to(0) | ||
| # | ||
| # latency_nowarm, latency_warm, cputime, kerneltime = do_test( | ||
| # torch.abs, (a, ), host_device_sync, config, case_config) | ||
| # | ||
| # op2flops = lambda x: x * m * 1024 * 1024 | ||
| # | ||
| # perf_result = cal_perf(cputime, kerneltime, op2flops, | ||
| # config.spectflops) | ||
| # print_result(config, config.case_name, *perf_result, correctness, | ||
| # latency_nowarm, latency_warm) | ||
|
|
||
| if __name__ == "__main__": | ||
| config = parse_args() | ||
| # with open("case_config.yaml", "r") as file: | ||
| # case_config = yaml.safe_load(file) | ||
| # adapt_torch(config.vendor) | ||
| # with open(os.path.join(config.vendor, config.chip, "case_config.yaml"), | ||
| # "r") as file: | ||
| # case_config_vendor = yaml.safe_load(file) | ||
| # case_config.update(case_config_vendor) | ||
| # case_config = Namespace(**case_config) | ||
|
|
||
| if config.oplib == "flaggems": | ||
| import flag_gems | ||
| flag_gems.enable() | ||
| print("Using flaggems") | ||
| else: | ||
| print("Using nativetorch") | ||
| main(config) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,21 @@ | ||
| import os | ||
|
|
||
|
|
||
| def render(extracted_values, readme_file_path, vendor, shm_size, chip): | ||
| json_data = [] | ||
| for key, value in extracted_values.items(): | ||
| json_data.append(value) | ||
| dest_file_path = os.path.join(readme_file_path, "README.md") | ||
| markdown_table = creat_markdown_table(json_data, vendor, shm_size, chip) | ||
| with open(dest_file_path, 'w') as file: | ||
| file.write(markdown_table) | ||
|
|
||
|
|
||
| def creat_markdown_table(data, vendor, shm_size, chip): | ||
| v_chip = f'{vendor}_{chip}' | ||
| table = f"# 参评AI芯片信息\n\n * 厂商:{vendor}\n * 产品名称:{v_chip}\n * 产品型号:{chip}\n * SHM_SIZE:{shm_size}\n\n\n\n" | ||
| table += "# 评测结果\n\n" | ||
| table += "| op_name | dtype | shape_detail | 无预热时延(Latency-No warmup) | 预热时延(Latency-Warmup) | 原始吞吐(Raw-Throughput)| 核心吞吐(Core-Throughput) | 实际算力开销 | 实际算力利用率 | 实际算力开销(内核时间) | 实际算力利用率(内核时间) |\n| --- | ---| --- | ---| --- | ---| --- | ---| --- | ---| --- |\n" | ||
| for row in data: | ||
| table += f"| {row['op_name']} | {row['dtype']} | {row['shape_detail']} | {row['no_warmup_latency']} | {row['warmup_latency']} | {row['raw_throughput']} | {row['core_throughput']} | {row['ctflops']} | {row['cfu']} | {row['ktflops']} | {row['kfu']} |\n" | ||
| return table |
Oops, something went wrong.
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.
开始前先删除一下之前的log 日志,以免混淆