Skip to content

[kimi 2.7] Support deterministic upsample bicubic backward - #193707

Closed
weifengpy wants to merge 1 commit into
mainfrom
codex/deterministic-bicubic-cuda
Closed

weifengpy wants to merge 1 commit into
mainfrom
codex/deterministic-bicubic-cuda

Conversation

@weifengpy

@weifengpy weifengpy commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

TorchTitan's Kimi K2.7 vision encoder resizes its learnable positional table here:

https://github.com/pytorch/torchtitan/blob/85c549b9332067f7615241e73e0c4a28d44b065f/torchtitan/models/kimi_k2_7/vision_encoder.py#L90-L106

grid_table = pos_embed.permute(2, 0, 1).unsqueeze(0).float()
...
F.interpolate(grid_table, size=(h, w), mode=bicubic)

this PR make sure --debug.deterministic / torch.use_deterministic_algorithms(True) work. Fix is similar to to #101115

  • direct ATen calls, TorchScript, and antialias=True are unchanged
  • deterministic decomposition is slower and can have small forward rounding differences

@pytorch-bot

pytorch-bot Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193707

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit 56c9555 with merge base 1f4b1ff (image):

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Route non-antialiased bicubic interpolation through the existing decomposition when deterministic algorithms are enabled on a non-CPU tensor. Its backward uses deterministic index_put accumulation instead of the native CUDA atomic scatter.

Add a non-square, nonuniform-gradient test that checks bitwise repeatability while retaining the existing native-backward alert test.
@weifengpy
weifengpy force-pushed the codex/deterministic-bicubic-cuda branch from ed961ad to 56c9555 Compare August 16, 2026 04:15
@weifengpy weifengpy added the release notes: nn release notes category label Aug 16, 2026
@weifengpy
weifengpy requested a review from ezyang August 16, 2026 04:48
@weifengpy
weifengpy marked this pull request as ready for review August 16, 2026 04:48
@weifengpy weifengpy changed the title Support deterministic upsample bicubic backward [kimi 2.7] Support deterministic upsample bicubic backward Aug 16, 2026
@weifengpy

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 16, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Comment thread torch/nn/functional.py
# The decomposition accumulates through deterministic index_put.
# Import it lazily: a top-level import creates a cycle, while a
# nested import statement is unsupported by TorchScript.
return importlib.import_module(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question, this can't be a normal import statement here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked why import torch._decomp.decompositions wasn't working for 2 reasons

  • top-level import creates a cycle
  • nested import statement is unsupported by TorchScript. one repro is following
  def fn(x: torch.Tensor) -> torch.Tensor:
      if not torch.jit.is_scripting():
          import math # torch.jit.frontend.UnsupportedNodeError: import statements aren't supported
      return x

orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…93707)

TorchTitan's Kimi K2.7 vision encoder resizes its learnable positional table here:

https://github.com/pytorch/torchtitan/blob/85c549b9332067f7615241e73e0c4a28d44b065f/torchtitan/models/kimi_k2_7/vision_encoder.py#L90-L106

```python
grid_table = pos_embed.permute(2, 0, 1).unsqueeze(0).float()
...
F.interpolate(grid_table, size=(h, w), mode=bicubic)
```

this PR make sure `--debug.deterministic` / `torch.use_deterministic_algorithms(True)` work. Fix is similar to  to pytorch#101115
* direct ATen calls, TorchScript, and `antialias=True` are unchanged
* deterministic decomposition is slower and can have small forward rounding differences
Pull Request resolved: pytorch#193707
Approved by: https://github.com/Skylion007
@github-actions
github-actions Bot deleted the codex/deterministic-bicubic-cuda branch November 5, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: nn release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants