Skip to content

Cross entropy: trace under torch.compile(dynamic=True) - #16059

Merged
danielhanchen merged 1 commit into
mainfrom
dh/s9-ce-symbolic-divmod
Oct 30, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
dh/s9-ce-symbolic-divmod

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #14712.

Problem

Fast_CrossEntropyLoss computes its chunk and block counts with divmod on the vocab size. With dynamic=True the size is symbolic and Dynamo cannot trace divmod on it: fullgraph=True raises Unsupported, and fullgraph=False fails in the Triton launch for vocabs above 65536. The default loader path passes torch_compile=False, so this is only reached through a direct patch_loss_functions(torch_compile=True) or a user compile.

Change

Use ceil division instead of divmod. Eager computes the same integers.

Tests

tests/test_cross_entropy_compiled_grads.py now also runs dynamic=True (torch 2.10+). Single GPU, torch 2.13:

  • main: 3 failed, 9 passed. Failing: test_compiled_grads_match_the_fp64_reference[True-True-32768], [True-True-65537], [True-True-151936].
  • this branch: 12 passed.

Not covered

GPU run on torch 2.13 only. An earlier L4 run on torch 2.12 also failed 5 of the 6 dynamic cases on main and passed all 12 here. torch 2.14 and later were not run on GPU.

Fast_CrossEntropyLoss computed its chunk / block counts with divmod on the
vocab size. With dynamic=True the size is symbolic and Dynamo cannot trace
divmod on it: fullgraph=True raises Unsupported, and fullgraph=False dies in
the Triton launch with 'SymNodeVariable' object has no attribute 'value' for
vocabs above 65536. Use ceil division instead (same integers in eager).

The compiled-grads test now also runs dynamic=True (torch 2.10+).
@danielhanchen danielhanchen self-assigned this Oct 30, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T03:40:20.804981Z 36e5f13 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 36e5f13fde

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit bdea0c0 into main Oct 30, 2026
3 of 34 checks passed
@danielhanchen
danielhanchen deleted the dh/s9-ce-symbolic-divmod branch October 30, 2026 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant