| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…dai#7972) In JIT mode, compute_capability_args() now sets TORCH_CUDA_ARCH_LIST to the detected GPU architectures and returns an empty list, letting PyTorch generate -gencode flags. Previously the env var was cleared to an empty string (which PyTorch treats as unset, triggering auto-detection) while DeepSpeed also added its own -gencode flags, resulting in duplicates. The jit_load() restore logic is also improved: if TORCH_CUDA_ARCH_LIST was not originally set, it is now removed from os.environ after build instead of being left as an empty string. Fixes deepspeedai#7972 Signed-off-by: Cursx <674760201@qq.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Sorry, something went wrong.
|
Shouldn't this always be done, not only for JIT mode? Otherwise you set TORCH_CUDA_ARCH_LIST, builder will filter them but leave them set AND add flags so you build for wrong ones in addition to the desired ones. Or am I missing anything? |
Sorry, something went wrong.
|
@Flamefire I'm looking into a proper fix for this as a follow-up. |
Sorry, something went wrong.
…-JIT mode Extend the fix to non-JIT (setup.py) mode: compute_capability_args() now updates TORCH_CUDA_ARCH_LIST to the filtered arch list from filter_ccs() for both JIT and non-JIT paths. Each CUDAExtension still carries its own -gencode flags in extra_compile_args, but BuildExtension will no longer silently re-introduce archs that filter_ccs() removed. Signed-off-by: Cursx <674760201@qq.com>
Signed-off-by: Cursx <674760201@qq.com>
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
| Format: | ||
|
|
||
| - `TORCH_CUDA_ARCH_LIST` may use ; or whitespace separators. Examples: | ||
| - ``TORCH_CUDA_ARCH_LIST`` may use ; or whitespace separators. Examples: |
There was a problem hiding this comment.
| - ``TORCH_CUDA_ARCH_LIST`` may use ; or whitespace separators. Examples: | |
| - `TORCH_CUDA_ARCH_LIST` may use ; or whitespace separators. Examples: |
Sorry, something went wrong.
| self.enable_bf16 = True | ||
| for cc in ccs: | ||
| if int(cc[0]) <= 7: | ||
| self.enable_bf16 = False |
There was a problem hiding this comment.
How about using any?
| self.enable_bf16 = True | |
| for cc in ccs: | |
| if int(cc[0]) <= 7: | |
| self.enable_bf16 = False | |
| self.enable_bf16 = not any(int(cc[0]) <= 7 for cc in ccs) |
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, it is better this way.
Sorry, something went wrong.
| TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6 9.0 10.0+PTX" pip install ... | ||
|
|
||
| - `cross_compile_archs` uses ; separator. | ||
| - ``cross_compile_archs`` uses ; separator. |
There was a problem hiding this comment.
| - ``cross_compile_archs`` uses ; separator. | |
| - `cross_compile_archs` uses ; separator. |
Sorry, something went wrong.
| # Let PyTorch generate -gencode flags from the env var. | ||
| return [] | ||
|
|
||
| # Non-JIT: return explicit flags per builder for extra_compile_args. |
There was a problem hiding this comment.
Won't this cause duplicate, possibly wrong flags again? If TORCH_CUDA_ARCH_LIST is used for all extensions and one allows a CC another doesn't you'll still get it for both
I guess for non-JIT mode you'd want to set TORCH_CUDA_ARCH_LIST to a single CC out of the intersection of the CCs allowed by all extensions if that is the case to at least not add the wrong one if you can't avoid the duplication.
Or if more high level is possible:
Sorry, something went wrong.
There was a problem hiding this comment.
I totally agree with your intersection-based approach, but implementing it would likely require changes to setup.py (splitting the builder loop into two passes), and I'm concerned the scope of that refactor could be too large for this PR.
Sorry, something went wrong.
## Summary - Fix duplicate/wrong `-gencode=` flags in both JIT and non-JIT compilation paths (`op_builder/builder.py`) - Fix `TORCH_CUDA_ARCH_LIST` env-var restore logic in `OpBuilder.jit_load()` DeepSpeed's `compute_capability_args()` generates its own `-gencode` flags, but PyTorch (`load()` in JIT mode, `BuildExtension` in non-JIT mode) *also* reads `TORCH_CUDA_ARCH_LIST` and generates `-gencode` flags. This causes two problems: 1. **JIT mode**: `jit_load()` set `TORCH_CUDA_ARCH_LIST=""`, which PyTorch treats as *unset* and falls back to auto-detection — resulting in every flag appearing **twice**. 2. **Non-JIT mode**: subclasses that override `filter_ccs()` (e.g. `FPQuantizerBuilder`, `EvoformerAttnBuilder`) remove certain archs, but `BuildExtension` re-reads the **unfiltered** `TORCH_CUDA_ARCH_LIST` and adds them back — **undermining the filter**. The fix synchronises `TORCH_CUDA_ARCH_LIST` with the filtered arch list in `compute_capability_args()`, for both JIT and non-JIT paths. Fixes deepspeedai#7972 ## Before / After <details> <summary>Before (buggy behavior)</summary> **JIT mode** — `TORCH_CUDA_ARCH_LIST` cleared to `""`, PyTorch auto-detects and adds flags, DeepSpeed also adds the same flags: ``` nvcc ... -gencode=arch=compute_80,code=compute_80 -gencode=arch=compute_80,code=sm_80 ... -gencode=arch=compute_80,code=sm_80 -gencode=arch=compute_80,code=compute_80 ``` Plus a spurious warning: ``` UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation. ``` **Non-JIT mode** — `FPQuantizerBuilder.filter_ccs()` removes `< 8.0`, but `BuildExtension` re-adds them from the unfiltered env var: ``` # FPQuantizer compiled for sm_70 even though filter_ccs() removed it nvcc ... -gencode=arch=compute_80,code=sm_80 # from DeepSpeed (correct) ... -gencode=arch=compute_70,code=sm_70 # from BuildExtension (wrong!) ``` </details> <details> <summary>After (fixed behavior)</summary> **JIT mode** — `TORCH_CUDA_ARCH_LIST` is set to the detected architectures, PyTorch generates flags once, no duplicates: ``` nvcc ... -gencode=arch=compute_80,code=sm_80 -gencode=arch=compute_80,code=compute_80 ``` No spurious warning. Env var is properly restored/removed after build. **Non-JIT mode** — `TORCH_CUDA_ARCH_LIST` is updated to the filtered list. Each extension keeps its own `-gencode` flags, and `BuildExtension` reads the filtered env var: ``` # FPQuantizer: only sm_80+ as intended nvcc ... -gencode=arch=compute_80,code=sm_80 # from DeepSpeed ... -gencode=arch=compute_80,code=sm_80 # from BuildExtension (harmless dup) ``` > **Note:** in multi-builder `setup.py` builds, the last builder's filtered arch list wins for `TORCH_CUDA_ARCH_LIST`. This may cause harmless duplicates for some extensions, but will never reintroduce archs that any builder's `filter_ccs()` removed — a strict improvement over the current behavior where the unfiltered original is always used. </details> ## Changes - `op_builder/builder.py` - `CUDAOpBuilder.compute_capability_args()`: - Always sync `TORCH_CUDA_ARCH_LIST` with the filtered arch list - JIT mode: return `[]` (PyTorch generates flags via `load()`) - Non-JIT mode: return `-gencode` args as before (per-builder flags in `extra_compile_args`) - `OpBuilder.jit_load()`: simplified stash/restore — properly `del` the env var if it was not originally set --------- Signed-off-by: Cursx <674760201@qq.com> Signed-off-by: ming.lee <ming.lee@inceptionai.ai>
| Back | FazBrowse Home | New Git URL |
Summary
DeepSpeed's compute_capability_args() generates its own -gencode flags, but PyTorch (load() in JIT mode, BuildExtension in non-JIT mode) also reads TORCH_CUDA_ARCH_LIST and generates -gencode flags. This causes two problems:
The fix synchronises TORCH_CUDA_ARCH_LIST with the filtered arch list in compute_capability_args(), for both JIT and non-JIT paths.
Fixes #7972
Before / After
Before (buggy behavior)JIT mode — TORCH_CUDA_ARCH_LIST cleared to "", PyTorch auto-detects and adds flags, DeepSpeed also adds the same flags:
nvcc ... -gencode=arch=compute_80,code=compute_80 -gencode=arch=compute_80,code=sm_80 ... -gencode=arch=compute_80,code=sm_80 -gencode=arch=compute_80,code=compute_80Plus a spurious warning:
Non-JIT mode — FPQuantizerBuilder.filter_ccs() removes < 8.0, but BuildExtension re-adds them from the unfiltered env var:
# FPQuantizer compiled for sm_70 even though filter_ccs() removed it nvcc ... -gencode=arch=compute_80,code=sm_80 # from DeepSpeed (correct) ... -gencode=arch=compute_70,code=sm_70 # from BuildExtension (wrong!)JIT mode — TORCH_CUDA_ARCH_LIST is set to the detected architectures, PyTorch generates flags once, no duplicates:
No spurious warning. Env var is properly restored/removed after build.
Non-JIT mode — TORCH_CUDA_ARCH_LIST is updated to the filtered list. Each extension keeps its own -gencode flags, and BuildExtension reads the filtered env var:
# FPQuantizer: only sm_80+ as intended nvcc ... -gencode=arch=compute_80,code=sm_80 # from DeepSpeed ... -gencode=arch=compute_80,code=sm_80 # from BuildExtension (harmless dup)Changes