-
Notifications
You must be signed in to change notification settings - Fork 32
Update AITER subcommit and refactor internal AITER/CK FA API usage #446
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
f02c48e
Initial inclusion of new API in fwd as well as part 1 of refactor
Micky774 0b0ad93
Initial implementation of refactor/API update across ALL CK funcs
Micky774 c198cbd
Updated logging
Micky774 a52bb32
Add script for comparing AITER/TE API
Micky774 77f0a05
Reconcile new AITER mask type
Micky774 1637266
Updated API helper tool
Micky774 568e9b5
Merge branch 'dev' into zain/aiter-api
Micky774 2cb6d82
Formatting
Micky774 cf4aa9e
Added sys exit to script
Micky774 e25cea8
Slightly better error message
Micky774 2122479
Updated AITER_ASM_DIR implementation
Micky774 4817e72
Update AITER
Micky774 837b827
Updated AITER_ASM_DIR logic to allow for hip-free use
Micky774 68ca0fe
Re-introduce setup AITER API check
Micky774 ae688ab
Update AITER to custom feature branch
Micky774 762b91b
Reduce AITER build verbosity
Micky774 0a7187d
Updated API
Micky774 39b27bc
Address PR comments
Micky774 29878cf
Updated bias stride calculations
Micky774 6846a27
Merge branch 'dev' into zain/aiter-api
Micky774 47592ac
Reverted AITER feature branch use due to verbosity changes
Micky774 357b5ce
PR review comments
Micky774 1f080c1
Reintroduced warning suppression in AITER
Micky774 a657bdd
Removes auto-setting of AITER_LOG_MORE, corrects batch stride impl
Micky774 c225448
Removes AITER_LOG_MORE from CI runs
Micky774 4193158
Minor corrections
Micky774 dbb6106
PR feedback
Micky774 899162e
Formatting
Micky774 1081c5e
Copyright
Micky774 9514855
Merge branch 'dev' into zain/aiter-api
Micky774 78f1d69
Updated ck_fused_attn lib build to include copying HSA
Micky774 f935956
Corrected AITER bug and moved to TE feature branch
Micky774 b90da33
Merge branch 'dev' into zain/aiter-api
Micky774 0475f85
Added back dropped code from merge conflict
Micky774 5db08ea
Downgrade to more conservative AITER commit for compat
Micky774 d5e5ec6
Removed python-level args check
Micky774 151e9ca
Removed old tools
Micky774 5a18d16
Corrected arg_size types manually
Micky774 db34177
Updated AITER commit and fixed API mismatch in group gemm
Micky774 9cd2833
Added build-time AITER API usage check
Micky774 a6b831e
PR review comments
Micky774 d1bd569
Undo extra import removal
Micky774 686e6a2
Adjusted python requirement in cmakelist
Micky774 52e1a1a
Updated group-gemm dispatch
Micky774 48c5839
Made AITER API check earlier
Micky774 9b2166e
Update AITER w/ Xinya's patch
Micky774 3dacb2a
Merge branch 'dev' into zain/aiter-api
Micky774 638c9e6
Revert and cherry-pick aiter subcommit
Micky774 c786c3b
Patched unordered map mgpu kernel collision
Micky774 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
Some comments aren't visible on the classic Files Changed page.
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,97 @@ | ||
| import argparse | ||
|
wangye805 marked this conversation as resolved.
|
||
| import re | ||
| from pathlib import Path | ||
| from typing import List, Set | ||
| import sys | ||
|
|
||
| def parse_with_skip_comments(buffer, line, regex, outputs): | ||
| # skip comments | ||
| stripped = line.strip() | ||
| if not stripped or stripped.startswith("//"): | ||
| return | ||
| line_no_comment = re.sub(r"//.*", "", line) | ||
| buffer[0] += " " + line_no_comment.strip() | ||
| if ";" not in line_no_comment: | ||
| return | ||
| match = regex.search(buffer[0]) | ||
| if match: | ||
| outputs.append(match.group(1)) | ||
| buffer[0] = "" | ||
|
|
||
|
|
||
| def extract_fields_from_header(text: str, struct_name: str) -> List[str]: | ||
| struct_field_re = re.compile(r"([A-Za-z_][A-Za-z0-9_]*)\s*(?:=[^;]*)?;\s*$") | ||
| struct_end_re = re.compile(r"^\s*};\s*$") | ||
|
|
||
| struct_start_re = re.compile(rf"\bstruct\s+{re.escape(struct_name)}\b") | ||
| lines = text.splitlines() | ||
| in_struct = False | ||
| fields: List[str] = [] | ||
| buffer = [""] | ||
| for line in lines: | ||
| if not in_struct: | ||
| if struct_start_re.search(line): | ||
| in_struct = True | ||
| continue | ||
| if struct_end_re.search(line): | ||
| break | ||
| parse_with_skip_comments(buffer, line, struct_field_re, fields) | ||
| return fields | ||
|
|
||
|
|
||
| def extract_usage_from_source(text: str, var_name: str) -> Set[str]: | ||
| assign_re = re.compile(rf"\b{re.escape(var_name)}\.([A-Za-z_][A-Za-z0-9_]*)\b\s*=") | ||
| assignments = [] | ||
| lines = text.splitlines() | ||
| buffer = [""] | ||
| for line in lines: | ||
| parse_with_skip_comments(buffer, line, assign_re, assignments) | ||
| return set(assignments) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description="Check aiter args usage vs header definition") | ||
| parser.add_argument("--mode", choices=["fwd", "bwd", "both"], required=True, help="Mode: fwd, bwd, or both") | ||
|
ipanfilo marked this conversation as resolved.
Outdated
|
||
| args = parser.parse_args() | ||
| modes = ["fwd", "bwd"] if args.mode == "both" else [args.mode] | ||
| mismatch = 0 | ||
| for mode in modes: | ||
| header_path = Path(f"3rdparty/aiter/csrc/include/mha_{mode}.h") | ||
|
ipanfilo marked this conversation as resolved.
Outdated
|
||
| source_path = Path(f"transformer_engine/common/ck_fused_attn/src/ck_fused_attn_{mode}.cpp") | ||
| header_text = header_path.read_text(encoding="utf-8") | ||
| source_text = source_path.read_text(encoding="utf-8") | ||
|
|
||
| header_fields = extract_fields_from_header(header_text, f"mha_{mode}_args") | ||
| header_set = set(header_fields) | ||
| used_fields = extract_usage_from_source(source_text, f"fmha_args") | ||
|
|
||
| missing_in_usage = sorted(header_set - used_fields) | ||
| unknown_in_header = sorted(used_fields - header_set) | ||
| mismatch += len(missing_in_usage) + len(unknown_in_header) | ||
|
|
||
| print(f"\nAnalyzing mha_{mode}_args\n") | ||
| print(f"mha_{mode}_args fields in header:", len(header_set)) | ||
| print(f"mha_{mode}_args fields referenced in source:", len(used_fields)) | ||
|
|
||
| if missing_in_usage: | ||
| print("\nFields present in header but not referenced in source:") | ||
| for name in missing_in_usage: | ||
| print(f" - {name}") | ||
| else: | ||
| print("\nAll header fields are referenced in source.") | ||
|
|
||
| if unknown_in_header: | ||
| print("\nFields referenced in source but not in header:") | ||
| for name in unknown_in_header: | ||
| print(f" - {name}") | ||
| else: | ||
| print("\nNo unknown fields referenced in source.") | ||
|
|
||
| if mismatch: | ||
| print(f"\nTotal mismatched fields: {mismatch}") | ||
| return 1 | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
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
Oops, something went wrong.
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.
This helper script scans semi-hard-coded files wrt TE source-code in order to directly compare AITER's internal API and our attempt at utilizing it. This script is run during setup through
setup.pyThere 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.
You can put this in the comment of this file.
Also don't forget to add the copyright