Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196856
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 1af77aa with merge base 42d36d3 ( 🟡 GREEN LIGHT - PR requires human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@claude Please do a deep review focused on subtle correctness bugs and regressions that are easy for human reviewers to miss. Prioritize findings over summary. I dont care about anything that isnt a real bug drop all the noise but that, if you there isnt anything to report just say so with a small comment |
|
Claude encountered an error after 51m 2s —— View job Deep correctness review
|
c723923 to
88e9fde
Compare
|
@claude Please do a deep review focused on subtle correctness bugs and regressions that are easy for human reviewers to miss. Prioritize findings over summary. I dont care about anything that isnt a real bug drop all the noise but that, if you there isnt anything to report just say so with a small comment |
|
Claude finished @drisspg's task in 5m 6s —— View job I didn't find any real correctness bugs or regressions in this PR. What I checked
This was a static review only. I did not build anything or run the tests. |
…ding ## Summary (human-written) Add deterministic grid_sample backward. We will switch to pytorch/pytorch#196856 once it lands. However, the wrapper to turn on deterministic mode is still needed. ## Why NaViT samples its position table with F.grid_sample. The CUDA grid_sample backward accumulates with atomic adds, so the input grad changes from run to run. positional_embedding_vlm is invariant over TP and CP, so on main every rank computes a different grad and the copies drift. Deterministic mode does not help: it raises on this op. **Example.** ``` NaViT-sized table [1, 1536, 32, 32], sampled at a 37x37 grid, same inputs, two backward runs before (F.grid_sample): input grads differ between runs after (this op): input grads bitwise equal over 10 eager runs and one compiled run ``` ## What changed - Add torchtitan::deterministic_grid_sample (torchtitan/ops/grid_sample.py): bilinear, zeros padding, align_corners=False. The forward is F.grid_sample. The backward builds a dense bilinear weight matrix (P x H*W, 4 nonzeros per row) and computes the input grad as one matmul in at least fp32, with no gather, scatter or atomics. It raises ValueError if the grid needs a gradient. - NaViT samples its position table with the op. - The unused grid_sample_mode config field is removed; only bilinear was used. - TODO in code: switch to the upstream deterministic grid_sample backward once pytorch/pytorch#196856 lands. ## Alternatives considered - A scatter_add backward on corner indices: also deterministic, but needs 528-535 MiB per frame at a 37x37 grid (1554-1578 MiB at 64x64) and is 4-11x slower. ## Numerics The NaViT position-embedding input grad accumulates in fp32 and is deterministic. At a 37x37 grid it differs from native grid_sample by up to 0.64 in bf16 (native accumulates in bf16 with atomics) and by up to 7.2e-7 in fp32. In fp64 the difference is 1.3e-15. The forward is unchanged. | Config | Hardware | Result | | --- | --- | --- | | Spark debug_mm CP2 and TP2, full FT, global deterministic mode off, 60 steps | 2 x H100 | replicated params (including positional_embedding_vlm) bitwise equal, grad_norm identical per rank, every step | ## Performance Peak backward memory for one frame (1536 channels, 32x32 table): 43-51 MiB at a 37x37 grid and 54-78 MiB at 64x64. The matrix is P x H*W, so the cost grows with the table size. ## Testing - CPU tests: fp64 forward equal and backward within 1e-12 of F.grid_sample (with out-of-bounds points), gradcheck, opcheck (fake and autograd registration), and grid-grad rejection. They catch wrong bilinear weights, wrong padding, and a broken fake or autograd registration. - GPU test: the input grad of a NaViT-sized table is bitwise equal over 10 eager runs and one compiled run, in fp32 and bf16. It catches a non-deterministic backward. - CPU tests at this commit: tests/unit_tests/cpu/ops and models/muse_spark, 37 passed, 3 xfailed. stack-info: PR: pytorch/torchtitan#5892, branch: fegin/stack/21
…ding ## Summary (human-written) Add deterministic grid_sample backward. We will switch to pytorch/pytorch#196856 once it lands. However, the wrapper to turn on deterministic mode is still needed. ## Why NaViT samples its position table with F.grid_sample. The CUDA grid_sample backward accumulates with atomic adds, so the input grad changes from run to run. positional_embedding_vlm is invariant over TP and CP, so on main every rank computes a different grad and the copies drift. Deterministic mode does not help: it raises on this op. **Example.** ``` NaViT-sized table [1, 1536, 32, 32], sampled at a 37x37 grid, same inputs, two backward runs before (F.grid_sample): input grads differ between runs after (this op): input grads bitwise equal over 10 eager runs, and over 2 compiled runs ``` ## What changed - Add torchtitan::deterministic_grid_sample (torchtitan/ops/grid_sample.py): bilinear, zeros padding, align_corners=False. The forward is F.grid_sample. The backward builds a dense bilinear weight matrix (P x H*W, 4 nonzeros per row) and computes the input grad as one matmul in at least fp32, with no gather, scatter or atomics. It raises ValueError if the grid needs a gradient. - NaViT samples its position table with the op. - The unused grid_sample_mode config field is removed; only bilinear was used. - TODO in code: switch to the upstream deterministic grid_sample backward once pytorch/pytorch#196856 lands. ## Alternatives considered - A scatter_add backward on corner indices: also deterministic, but needs 528-535 MiB per frame at a 37x37 grid (1554-1578 MiB at 64x64) and is 4-11x slower. ## Numerics The NaViT position-embedding input grad accumulates in fp32 and is deterministic. At a 37x37 grid it differs from native grid_sample by up to 0.64 in bf16 (native accumulates in bf16 with atomics) and by up to 7.2e-7 in fp32. In fp64 the difference is 1.3e-15. The forward is unchanged. | Config | Hardware | Result | | --- | --- | --- | | Spark debug_mm CP2 and TP2, full FT, global deterministic mode off, 60 steps | 2 x H100 | replicated params (including positional_embedding_vlm) bitwise equal, grad_norm identical per rank, every step | ## Performance Peak backward memory for one frame (1536 channels, 32x32 table): 43-51 MiB at a 37x37 grid and 54-78 MiB at 64x64. The matrix is P x H*W, so the cost grows with the table size. ## Testing - CPU tests: fp64 forward equal and backward within 1e-12 of F.grid_sample (with out-of-bounds points), gradcheck, opcheck (fake and autograd registration), and grid-grad rejection. They catch wrong bilinear weights, wrong padding, and a broken fake or autograd registration. - GPU test: the input grad of a NaViT-sized table is bitwise equal over 10 eager runs, and over 2 compiled runs, in fp32 and bf16. Eager and compiled are not compared to each other, since Inductor may round differently. It catches a non-deterministic backward. - CPU tests at this commit: tests/unit_tests/cpu/ops and models/muse_spark, 37 passed, 3 xfailed. stack-info: PR: pytorch/torchtitan#5892, branch: fegin/stack/21
…ding ## Summary (human-written) Add deterministic grid_sample backward. We will switch to pytorch/pytorch#196856 once it lands. However, the wrapper to turn on deterministic mode is still needed. ## Why NaViT samples its position table with F.grid_sample. The CUDA grid_sample backward accumulates with atomic adds, so the input grad changes from run to run. positional_embedding_vlm is invariant over TP and CP, so on main every rank computes a different grad and the copies drift. Deterministic mode does not help: it raises on this op. **Example.** ``` NaViT-sized table [1, 1536, 32, 32], sampled at a 37x37 grid, same inputs, two backward runs before (F.grid_sample): input grads differ between runs after (this op): input grads bitwise equal over 10 eager runs, and over 2 compiled runs ``` ## What changed - Add torchtitan::deterministic_grid_sample (torchtitan/ops/grid_sample.py): bilinear, zeros padding, align_corners=False. The forward is F.grid_sample. The backward builds a dense bilinear weight matrix (P x H*W, 4 nonzeros per row) and computes the input grad as one matmul in at least fp32, with no gather, scatter or atomics. It raises ValueError if the grid needs a gradient. - NaViT samples its position table with the op. - The unused grid_sample_mode config field is removed; only bilinear was used. - TODO in code: switch to the upstream deterministic grid_sample backward once pytorch/pytorch#196856 lands. ## Alternatives considered - A scatter_add backward on corner indices: also deterministic, but needs 528-535 MiB per frame at a 37x37 grid (1554-1578 MiB at 64x64) and is 4-11x slower. ## Numerics The NaViT position-embedding input grad accumulates in fp32 and is deterministic. At a 37x37 grid it differs from native grid_sample by up to 0.64 in bf16 (native accumulates in bf16 with atomics) and by up to 7.2e-7 in fp32. In fp64 the difference is 1.3e-15. The forward is unchanged. | Config | Hardware | Result | | --- | --- | --- | | Spark debug_mm CP2 and TP2, full FT, global deterministic mode off, 60 steps | 2 x H100 | replicated params (including positional_embedding_vlm) bitwise equal, grad_norm identical per rank, every step | ## Performance Peak backward memory for one frame (1536 channels, 32x32 table): 43-51 MiB at a 37x37 grid and 54-78 MiB at 64x64. The matrix is P x H*W, so the cost grows with the table size. ## Testing - CPU tests: fp64 forward equal and backward within 1e-12 of F.grid_sample (with out-of-bounds points), gradcheck, opcheck (fake and autograd registration), and grid-grad rejection. They catch wrong bilinear weights, wrong padding, and a broken fake or autograd registration. - GPU test: the input grad of a NaViT-sized table is bitwise equal over 10 eager runs, and over 2 compiled runs, in fp32 and bf16. Eager and compiled are not compared to each other, since Inductor may round differently. It catches a non-deterministic backward. - CPU tests at this commit: tests/unit_tests/cpu/ops and models/muse_spark, 37 passed, 3 xfailed. stack-info: PR: #5892, branch: fegin/stack/21
drisspg
left a comment
There was a problem hiding this comment.
@claude Please do a deep review focused on subtle correctness bugs and regressions that are easy for human reviewers to miss. Prioritize findings over summary. I dont care about anything that isnt a real bug drop all the noise but that, if you there isnt anything to report just say so with a small comment
…ding ## Summary (human-written) Add deterministic grid_sample backward. We will switch to pytorch/pytorch#196856 once it lands. However, the wrapper to turn on deterministic mode is still needed. ## Why NaViT samples its position table with F.grid_sample. The CUDA grid_sample backward accumulates with atomic adds, so the input grad changes from run to run. positional_embedding_vlm is invariant over TP and CP, so on main every rank computes a different grad and the copies drift. Deterministic mode does not help: it raises on this op. **Example.** ``` NaViT-sized table [1, 1536, 32, 32], sampled at a 37x37 grid, same inputs, two backward runs before (F.grid_sample): input grads differ between runs after (this op): input grads bitwise equal over 10 eager runs, and over 2 compiled runs ``` ## What changed - Add torchtitan::deterministic_grid_sample (torchtitan/ops/grid_sample.py): bilinear, zeros padding, align_corners=False. The forward is F.grid_sample. The backward builds a dense bilinear weight matrix (P x H*W, 4 nonzeros per row) and computes the input grad as one matmul in at least fp32, with no gather, scatter or atomics. It raises ValueError if the grid needs a gradient. - NaViT samples its position table with the op. - The unused grid_sample_mode config field is removed; only bilinear was used. - TODO in code: switch to the upstream deterministic grid_sample backward once pytorch/pytorch#196856 lands. ## Alternatives considered - A scatter_add backward on corner indices: also deterministic, but needs 528-535 MiB per frame at a 37x37 grid (1554-1578 MiB at 64x64) and is 4-11x slower. ## Numerics The NaViT position-embedding input grad accumulates in fp32 and is deterministic. At a 37x37 grid it differs from native grid_sample by up to 0.64 in bf16 (native accumulates in bf16 with atomics) and by up to 7.2e-7 in fp32. In fp64 the difference is 1.3e-15. The forward is unchanged. | Config | Hardware | Result | | --- | --- | --- | | Spark debug_mm CP2 and TP2, full FT, global deterministic mode off, 60 steps | 2 x H100 | replicated params (including positional_embedding_vlm) bitwise equal, grad_norm identical per rank, every step | ## Performance Peak backward memory for one frame (1536 channels, 32x32 table): 43-51 MiB at a 37x37 grid and 54-78 MiB at 64x64. The matrix is P x H*W, so the cost grows with the table size. ## Testing - CPU tests: fp64 forward equal and backward within 1e-12 of F.grid_sample (with out-of-bounds points), gradcheck, opcheck (fake and autograd registration), and grid-grad rejection. They catch wrong bilinear weights, wrong padding, and a broken fake or autograd registration. - GPU test: the input grad of a NaViT-sized table is bitwise equal over 10 eager runs, and over 2 compiled runs, in fp32 and bf16. Eager and compiled are not compared to each other, since Inductor may round differently. It catches a non-deterministic backward. - CPU tests at this commit: tests/unit_tests/cpu/ops and models/muse_spark, 37 passed, 3 xfailed. stack-info: PR: #5892, branch: fegin/stack/21
…ding ## Summary (human-written) Add deterministic grid_sample backward. We will switch to pytorch/pytorch#196856 once it lands. However, the wrapper to turn on deterministic mode is still needed. ## Why NaViT samples its position table with F.grid_sample. The CUDA grid_sample backward accumulates with atomic adds, so the input grad changes from run to run. positional_embedding_vlm is invariant over TP and CP, so on main every rank computes a different grad and the copies drift. Deterministic mode does not help: it raises on this op. **Example.** ``` NaViT-sized table [1, 1536, 32, 32], sampled at a 37x37 grid, same inputs, two backward runs before (F.grid_sample): input grads differ between runs after (this op): input grads bitwise equal over 10 eager runs, and over 2 compiled runs ``` ## What changed - Add torchtitan::deterministic_grid_sample (torchtitan/ops/grid_sample.py): bilinear, zeros padding, align_corners=False. The forward is F.grid_sample. The backward builds a dense bilinear weight matrix (P x H*W, 4 nonzeros per row) and computes the input grad as one matmul in at least fp32, with no gather, scatter or atomics. It raises ValueError if the grid needs a gradient. - NaViT samples its position table with the op. - The unused grid_sample_mode config field is removed; only bilinear was used. - TODO in code: switch to the upstream deterministic grid_sample backward once pytorch/pytorch#196856 lands. ## Alternatives considered - A scatter_add backward on corner indices: also deterministic, but needs 528-535 MiB per frame at a 37x37 grid (1554-1578 MiB at 64x64) and is 4-11x slower. ## Numerics The NaViT position-embedding input grad accumulates in fp32 and is deterministic. At a 37x37 grid it differs from native grid_sample by up to 0.64 in bf16 (native accumulates in bf16 with atomics) and by up to 7.2e-7 in fp32. In fp64 the difference is 1.3e-15. The forward is unchanged. | Config | Hardware | Result | | --- | --- | --- | | Spark debug_mm CP2 and TP2, full FT, global deterministic mode off, 60 steps | 2 x H100 | replicated params (including positional_embedding_vlm) bitwise equal, grad_norm identical per rank, every step | ## Performance Peak backward memory for one frame (1536 channels, 32x32 table): 43-51 MiB at a 37x37 grid and 54-78 MiB at 64x64. The matrix is P x H*W, so the cost grows with the table size. ## Testing - CPU tests: fp64 forward equal and backward within 1e-12 of F.grid_sample (with out-of-bounds points), gradcheck, opcheck (fake and autograd registration), and grid-grad rejection. They catch wrong bilinear weights, wrong padding, and a broken fake or autograd registration. - GPU test: the input grad of a NaViT-sized table is bitwise equal over 10 eager runs, and over 2 compiled runs, in fp32 and bf16. Eager and compiled are not compared to each other, since Inductor may round differently. It catches a non-deterministic backward. - CPU tests at this commit: tests/unit_tests/cpu/ops and models/muse_spark, 37 passed, 3 xfailed. stack-info: PR: #5892, branch: fegin/stack/21
…ding (#5892) ## Summary (human-written) Add deterministic grid_sample backward. We will switch to pytorch/pytorch#196856 once it lands. However, the wrapper to turn on deterministic mode is still needed. ## Why NaViT samples its position table with F.grid_sample. The CUDA grid_sample backward accumulates with atomic adds, so the input grad changes from run to run. positional_embedding_vlm is invariant over TP and CP, so on main every rank computes a different grad and the copies drift. Deterministic mode does not help: it raises on this op. **Example.** ``` NaViT-sized table [1, 1536, 32, 32], sampled at a 37x37 grid, same inputs, two backward runs before (F.grid_sample): input grads differ between runs after (this op): input grads bitwise equal over 10 eager runs, and over 2 compiled runs ``` ## What changed - Add torchtitan::deterministic_grid_sample (torchtitan/ops/grid_sample.py): bilinear, zeros padding, align_corners=False. The forward is F.grid_sample. The backward builds a dense bilinear weight matrix (P x H*W, 4 nonzeros per row) and computes the input grad as one matmul in at least fp32, with no gather, scatter or atomics. It raises ValueError if the grid needs a gradient. - NaViT samples its position table with the op. - The unused grid_sample_mode config field is removed; only bilinear was used. - TODO in code: switch to the upstream deterministic grid_sample backward once pytorch/pytorch#196856 lands. ## Alternatives considered - A scatter_add backward on corner indices: also deterministic, but needs 528-535 MiB per frame at a 37x37 grid (1554-1578 MiB at 64x64) and is 4-11x slower. ## Numerics The NaViT position-embedding input grad accumulates in fp32 and is deterministic. At a 37x37 grid it differs from native grid_sample by up to 0.64 in bf16 (native accumulates in bf16 with atomics) and by up to 7.2e-7 in fp32. In fp64 the difference is 1.3e-15. The forward is unchanged. | Config | Hardware | Result | | --- | --- | --- | | Spark debug_mm CP2 and TP2, full FT, global deterministic mode off, 60 steps | 2 x H100 | replicated params (including positional_embedding_vlm) bitwise equal, grad_norm identical per rank, every step | ## Performance Peak backward memory for one frame (1536 channels, 32x32 table): 43-51 MiB at a 37x37 grid and 54-78 MiB at 64x64. The matrix is P x H*W, so the cost grows with the table size. ## Testing - CPU tests: fp64 forward equal and backward within 1e-12 of F.grid_sample (with out-of-bounds points), gradcheck, opcheck (fake and autograd registration), and grid-grad rejection. They catch wrong bilinear weights, wrong padding, and a broken fake or autograd registration. - GPU test: the input grad of a NaViT-sized table is bitwise equal over 10 eager runs, and over 2 compiled runs, in fp32 and bf16. Eager and compiled are not compared to each other, since Inductor may round differently. It catches a non-deterministic backward. - CPU tests at this commit: tests/unit_tests/cpu/ops and models/muse_spark, 37 passed, 3 xfailed.
78c1591 to
29f9d08
Compare
Retain the original native atomic and cuDNN backward paths by default, and select fixed-order input-gradient accumulation only in deterministic mode. Share the native grid-gradient math through a grid-only specialization. Cover off, strict, and warn-only dispatch, document the opt-in behavior, and include the new test file in the CODEOWNERS taxonomy. Test Plan: ```sh spin lint -a CODEOWNERS aten/src/ATen/native/cuda/GridSampler.cu aten/src/ATen/native/cuda/GridSampler.cuh aten/src/ATen/native/cudnn/GridSampler.cpp docs/source/notes/randomness.md test/test_grid_sampler.py torch/__init__.py torch/nn/functional.py git diff --check ``` Prior validation of the unchanged implementation recorded 161 public tests, 158 legacy-reference cases, four Inductor tests, and targeted sanitizer checks passing on GB300. This submission reran lint; it did not rerun GPU tests.
Exercise default and deterministic CUDA backward in the existing numerical fixtures, reusing their CPU references and checking exact replay. Retain focused dispatch, gradient, reduction-boundary, stream, and graph coverage in the existing device test class, and remove the duplicate standalone suite. Test Plan: Both expanded existing tests and all 39 focused CUDA cases passed on GB300: ```sh gpu-run --no-wait auto -- timeout --signal=TERM --kill-after=5s 60s .venv/bin/python pytorch/test/test_nn.py TestNN.test_grid_sample TestNN.test_grid_sample_3d -v gpu-run --no-wait auto -- timeout --signal=TERM --kill-after=5s 60s .venv/bin/python pytorch/test/test_nn.py TestNNDeviceTypeCUDA -k grid_sample_dispatch -k grid_sample_gradcheck -k grid_sample_expanded_streams_and_graph -k grid_sample_long_segments -k grid_sample_chunk_boundary -k grid_sample_backward_output_mask -v ``` Pre-commit checks from the source worktree: ```sh spin lint -a -- --skip CODEOWNERS_TAXONOMY test/test_nn.py CODEOWNERS git diff --check ``` The HEAD-based taxonomy check must run after committing the paired test-file and CODEOWNERS-rule deletion.
29f9d08 to
1af77aa
Compare

Human Note
Replaces the backwards witha determnisitic variant. It be much faster insome cases at the cost of extra memory; farming opinions but also I fully replaced we may just want this for determ option I was trying to keep tight so I can add back
Agent Report
Agent Worklog
This PR was generated by ptq with human review.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo