Uh oh!
There was an error while loading. Please reload this page.
[torch.compile] Make HiDream torch.compile ready - #11477
Conversation
HuggingFaceDocBuilderDev
commented
May 1, 2025
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| tokens_per_expert = flat_expert_indices.bincount().cpu().numpy().cumsum(0) | ||
| count_freq = torch.bincount(flat_expert_indices, minlength=self.num_activated_experts) | ||
| tokens_per_expert = count_freq.cumsum(dim=0) | ||
There was a problem hiding this comment.
Just reimplemented it to eliminate the numpy() dependency.
| @require_torch_2 | ||
| @is_torch_compile | ||
| @slow | ||
| def test_torch_compile_recompilation_and_graph_break(self): |
StrongerXi
commented
May 1, 2025
The graph break seems to be induced by @anijain2305 is this known? |
sayakpaul
commented
May 3, 2025
Even if we remove the decorator, it still fails with the same error. |
sayakpaul
commented
May 8, 2025
via email
Thanks! Appreciate it. …On Thu, 8 May 2025 at 7:06 PM, Animesh Jain ***@***.***> wrote:
***@***.**** approved this pull request.
LGTM
—
Reply to this email directly, view it on GitHub
<#11477 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFPE2TCL5CXY6KDTOMUTXM325NMWRAVCNFSM6AAAAAB4H4U5SOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDQMRVGE3DSNZQHE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
anijain2305
commented
May 13, 2025
Not a useful update. But there seems to be some dynamic shapes graph break here coming from moe_infer function. cc @laithsakka |
sayakpaul
commented
May 14, 2025
Okay I think I know why this is happening. The line that primarily causes this shape change is: This is why the So, I tried with torch._dynamo.config.capture_dynamic_output_shape_ops=Truetorch.fx.experimental._config.use_duck_shape=FalseIt then complains: Keeping this open maybe for better tracking. |
sayakpaul
commented
May 17, 2025
Cc: @StrongerXi for the above observation too. |
StrongerXi
commented
Jun 5, 2025
On it. |
StrongerXi
commented
Jun 16, 2025
Okay I spent some time digging into the MOE stuff, here's what I learned:
Then I just have to fix a small graph break here, where diffusers/src/diffusers/models/transformers/transformer_hidream_image.py Lines 718 to 720 in dacae33 The fix is simple: # create img_sizes#img_sizes = torch.tensor([patch_height, patch_width], dtype=torch.int64, device=device).reshape(-1)#img_sizes = img_sizes.unsqueeze(0).repeat(batch_size, 1)img_sizes= [[patch_height, patch_width]] *batch_sizeHere are the e2e pipeline benchmark results using the hidream demo script, and compiling the transformer: I also saw that ComfyUI uses the training branch too. So maybe we should just use the training branch in eager as well? Or we could add a |
sayakpaul
commented
Jun 17, 2025
Wow, this is terrific KT. Thanks, Ryan!
This is a good approach and is worth adding. @yiyixuxu what are your thoughts? |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
What does this PR do?
Part of #11430
Trying to make the HiDream model fully compatible with
torch.compile()but it fails with:https://pastebin.com/EbCFqBvw
To reproduce run the following from a GPU machine:
RUN_COMPILE=1 RUN_SLOW=1 pytest tests/models/transformers/test_models_transformer_hidream.py -k "test_torch_compile_recompilation_and_graph_break"I am on the following env:
@anijain2305@StrongerXi would you have any pointers?