-
Notifications
You must be signed in to change notification settings - Fork 10
[Feat] Support real input #55
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: refactor
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -4,20 +4,20 @@ | |
| from benchmarks import mha_fwd_benchmark, mha_bwd_benchmark | ||
|
|
||
|
|
||
| def test_mha_fwd(B, S, H, D, causal, dtype, tune=False): | ||
| def test_mha_fwd(B, S, H, D, causal, dtype, tune=False, input_path=None): | ||
| op = mha_fwd(B, H, S, D, causal, dtype, tune=tune) | ||
| benchmark = mha_fwd_benchmark(B, H, S, D, causal, dtype) | ||
|
|
||
| inputs = benchmark.gen_inputs() | ||
| inputs = benchmark.gen_inputs(input_path) | ||
| benchmark.check(op, *inputs) | ||
| benchmark.profile(op, *inputs) | ||
|
|
||
|
|
||
| def test_mha_bwd(B, S, H, D, causal, dtype, tune=False): | ||
| def test_mha_bwd(B, S, H, D, causal, dtype, tune=False, input_path=None): | ||
| op = mha_bwd(B, H, S, D, causal, dtype, tune=tune) | ||
| benchmark = mha_bwd_benchmark(B, H, S, D, causal, dtype) | ||
|
|
||
| inputs = benchmark.gen_inputs() | ||
| inputs = benchmark.gen_inputs(input_path) | ||
|
Contributor
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. The |
||
| benchmark.check(op, *inputs) | ||
| benchmark.profile(op, *inputs) | ||
|
|
||
|
|
@@ -34,10 +34,16 @@ def test_mha_bwd(B, S, H, D, causal, dtype, tune=False): | |
| parser.add_argument('--tune', action='store_true', default=False, help='enable autotune') | ||
| parser.add_argument( | ||
| '--disable_bwd', action='store_false', default=True, help='when test fwd profile') | ||
| parser.add_argument( | ||
| '--input_path', | ||
| type=str, | ||
| default=None, | ||
| help='Path to real input data. Use ";" to separate multiple paths. If None, random inputs will be generated.' | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| test_mha_fwd(args.batch, args.seq_len, args.heads, args.dim, args.causal, str2dtype[args.dtype], | ||
| args.tune) | ||
| args.tune, args.input_path) | ||
| if args.disable_bwd: | ||
| test_mha_bwd(args.batch, args.seq_len, args.heads, args.dim, args.causal, | ||
| str2dtype[args.dtype], args.tune) | ||
| str2dtype[args.dtype], args.tune, args.input_path) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import torch | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # A mapping from string dtype names to torch dtypes | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -62,3 +63,29 @@ def is_hopper(): | |||||||||||||||||||||||||||||||||||||||||||||||||
| def get_sm_version(): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| major, minor = torch.cuda.get_device_capability() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return major * 10 + minor | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def load_input_from_path(path, expected_shape, dtype, device='cuda'): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 从文件路径加载输入数据的公共函数 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| path: 文件路径 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| expected_shape: 期望的张量形状 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| dtype: 数据类型 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| device: 设备类型 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 加载的张量 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+69
to
+80
Contributor
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. The docstring is written in Chinese, which is inconsistent with the rest of the codebase being in English. To maintain consistency and improve readability for all contributors, please translate it to English.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if not os.path.exists(path): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError(f"Input file not found: {path}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| tensor = torch.load(path) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. Using |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if tensor.shape != expected_shape: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Shape mismatch: expected {expected_shape}, got {tensor.shape} from {path}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| tensor = tensor.to(dtype=dtype, device=device) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return tensor | ||||||||||||||||||||||||||||||||||||||||||||||||||
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.
For better logging control, consider using the
loggingmodule instead ofprint. This allows for configuring verbosity levels and directing output to different handlers, which is more flexible for a benchmarking suite.