-
Notifications
You must be signed in to change notification settings - Fork 1
Set pytorch cuda arch list explicitly to get rid of warning. #44
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,8 +16,27 @@ class Hamiltonian: | |||||
|
|
||||||
| _hamiltonian_module: dict[tuple[str, int, int], object] = {} | ||||||
|
|
||||||
| @classmethod | ||||||
| def _set_torch_cuda_arch_list(cls) -> None: | ||||||
| """ | ||||||
| Set the CUDA architecture list for PyTorch to use when compiling the PyTorch extensions. | ||||||
| """ | ||||||
| if not torch.cuda.is_available(): | ||||||
| return | ||||||
| if "TORCH_CUDA_ARCH_LIST" in os.environ: | ||||||
| return | ||||||
| supported_sm = [int(arch[3:]) for arch in torch.cuda.get_arch_list() if arch.startswith("sm_")] | ||||||
| max_supported_sm = max((sm // 10, sm % 10) for sm in supported_sm) | ||||||
| arch_list = set() | ||||||
| for i in range(torch.cuda.device_count()): | ||||||
| capability = min(max_supported_sm, torch.cuda.get_device_capability(i)) | ||||||
| arch = f'{capability[0]}.{capability[1]}' | ||||||
| arch_list.add(arch) | ||||||
| os.environ["TORCH_CUDA_ARCH_LIST"] = ";".join(sorted(arch_list)) | ||||||
|
||||||
| os.environ["TORCH_CUDA_ARCH_LIST"] = ";".join(sorted(arch_list)) | |
| os.environ["TORCH_CUDA_ARCH_LIST"] = ";".join(sorted(arch_list, key=lambda v: tuple(map(int, v.split('.'))))) |
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.
这里copilot给的提示是对的吧,不像上一个没必要。师兄的版本号是str,字典序不妥,还得是像(sm // 10, sm % 10)那种拆开的叭。虽然排序无妨
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.
确实,这里排序是为了每次运行他们的顺序是一致的,不然无法有效利用缓存。
另外,我这段代码抄的:
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.
If
supported_smis empty, callingmax()will raise aValueError. Consider guarding against an empty list (e.g. return early) to avoid a crash when no arch entries are found.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.
torch.cuda.is_available()之前判断过,不会空