forked from deepseek-ai/FlashMLA
-
Notifications
You must be signed in to change notification settings - Fork 3
补充 MACA 环境检查文档 #18
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
ghangz
wants to merge
1
commit into
MetaX-MACA:main
Choose a base branch
from
ghangz:mengz/document-maca-env-checks
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
补充 MACA 环境检查文档 #18
Changes from all commits
Commits
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,77 @@ | ||
| #!/usr/bin/env python3 | ||
| import argparse | ||
| import random | ||
| from pathlib import Path | ||
| import sys | ||
|
|
||
| import torch | ||
|
|
||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[1] | ||
| if str(REPO_ROOT) not in sys.path: | ||
| sys.path.insert(0, str(REPO_ROOT)) | ||
|
|
||
| from tests.test_flash_mla import test_flash_mla # noqa: E402 | ||
|
|
||
|
|
||
| def _dtype(value: str) -> torch.dtype: | ||
| if value == "bf16": | ||
| return torch.bfloat16 | ||
| if value == "fp16": | ||
| return torch.float16 | ||
| raise argparse.ArgumentTypeError("dtype must be bf16 or fp16") | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser( | ||
| description="Run a small FlashMLA correctness smoke test on one MACA device." | ||
| ) | ||
| parser.add_argument("--device", default="cuda:0", help="Torch device to run on.") | ||
| parser.add_argument("--dtype", type=_dtype, default=torch.bfloat16, help="bf16 or fp16.") | ||
| parser.add_argument("--batch-size", type=int, default=128) | ||
| parser.add_argument("--s-q", type=int, default=1) | ||
| parser.add_argument("--mean-sk", type=int, default=4096) | ||
| parser.add_argument("--h-q", type=int, default=16) | ||
| parser.add_argument("--h-kv", type=int, default=1) | ||
| parser.add_argument("--d", type=int, default=576) | ||
| parser.add_argument("--dv", type=int, default=512) | ||
| parser.add_argument("--block-size", type=int, default=16) | ||
| parser.add_argument("--varlen", action="store_true") | ||
| parser.add_argument("--non-causal", action="store_true") | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main() -> int: | ||
| args = parse_args() | ||
| device = torch.device(args.device) | ||
| if device.type != "cuda": | ||
| raise ValueError("FlashMLA smoke test requires a CUDA-compatible MACA device.") | ||
|
|
||
| torch.set_default_dtype(args.dtype) | ||
| torch.set_default_device(device) | ||
| torch.cuda.set_device(device) | ||
| torch.manual_seed(0) | ||
| random.seed(0) | ||
|
|
||
| print(f"torch={torch.__version__}") | ||
| print(f"device={torch.cuda.get_device_name(device)}") | ||
| print(f"dtype={args.dtype}") | ||
|
|
||
| test_flash_mla( | ||
| b=args.batch_size, | ||
| s_q=args.s_q, | ||
| mean_sk=args.mean_sk, | ||
| h_q=args.h_q, | ||
| h_kv=args.h_kv, | ||
| d=args.d, | ||
| dv=args.dv, | ||
| causal=not args.non_causal, | ||
| varlen=args.varlen, | ||
| block_size=args.block_size, | ||
| ) | ||
| print("flash_mla_smoke_ok") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
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.
在初始化 CUDA 设备之前,建议先检查
torch.cuda.is_available(),并验证指定的设备索引是否在可用设备范围内(device.index < torch.cuda.device_count())。如果环境未正确配置(例如 MACA 驱动未加载或 PyTorch 未编译 CUDA 支持),直接调用torch.cuda.set_device会抛出难以理解的底层错误。增加这些防御性检查可以提供更友好的错误提示。