Skip to content

[ptxla] fix pytorch xla inference on TPUs.#13457

Closed
sayakpaul wants to merge 2 commits intomainfrom
flux-inference-ptxla
Closed

[ptxla] fix pytorch xla inference on TPUs.#13457
sayakpaul wants to merge 2 commits intomainfrom
flux-inference-ptxla

Conversation

@sayakpaul
Copy link
Copy Markdown
Member

@sayakpaul sayakpaul commented Apr 13, 2026

What does this PR do?

Cc: @bhavya01 and @entrpn. Could I get a review on this?

From the logs and the generated image, seems like things are working as expected.

image

I am on a v6e-8.

@github-actions github-actions bot added examples size/S PR with diff < 50 LOC labels Apr 13, 2026
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

@entrpn
Copy link
Copy Markdown
Contributor

entrpn commented Apr 13, 2026

would removing the if statement here and just setting timestep_device = device work?

@github-actions github-actions bot added size/S PR with diff < 50 LOC and removed size/S PR with diff < 50 LOC labels Apr 13, 2026
@sayakpaul
Copy link
Copy Markdown
Member Author

would removing the if statement here and just setting timestep_device = device work?

I could give it a try but do you want to open a PR? Would make things less hacky I think

@entrpn
Copy link
Copy Markdown
Contributor

entrpn commented Apr 14, 2026

@sayakpaul here is the PR: #13463

Tested on v5p-8.

compile_out

Logs:

WARNING:root:libtpu.so and TPU device found. Setting PJRT_DEVICE=TPU.
Loading weights: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 219/219 [00:00<00:00, 880.00it/s, Materializing param=shared.weight]
Loading weights: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 196/196 [00:00<00:00, 725.11it/s, Materializing param=text_model.final_layer_norm.weight]
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00,  6.31it/s]
2026-04-13 23:39:16 [info     ] loading flux from black-forest-labs/FLUX.1-dev
2026-04-13 23:39:16 [info     ] loading flux from black-forest-labs/FLUX.1-dev
Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 47.26it/s]
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 21.17it/s]
Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 10.43it/s]
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00,  5.65it/s]
2026-04-13 23:39:19 [info     ] loading flux from black-forest-labs/FLUX.1-dev
2026-04-13 23:39:19 [info     ] loading flux from black-forest-labs/FLUX.1-dev
Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 32.78it/s]
Loading pipeline components...:  67%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋                                                                       | 2/3 [00:00<00:00,  9.00it/s]
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 13.42it/s]
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 14.23it/s]
2026-04-13 23:39:21 [info     ] starting compilation run...   
2026-04-13 23:39:28 [info     ] starting compilation run...   
2026-04-13 23:39:31 [info     ] starting compilation run...   
2026-04-13 23:39:32 [info     ] starting compilation run...   
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [19:44<00:00, 42.30s/it]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [19:45<00:00, 42.32s/it]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [19:50<00:00, 42.52s/it]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [19:51<00:00, 42.54s/it]
2026-04-14 00:02:14 [info     ] compilation took 1362.8185202339664 sec.
2026-04-14 00:02:14 [info     ] compilation took 1366.7900346629322 sec.
2026-04-14 00:02:15 [info     ] starting inference run...     
2026-04-14 00:02:15 [info     ] starting inference run...     
2026-04-14 00:02:15 [info     ] compilation took 1363.4652386065573 sec.
  0%|                                                                                                                                                                                                                                                             | 0/28 [00:00<?, ?it/s]2026-04-14 00:02:16 [info     ] starting inference run...     
 11%|██████████████████████████▎                                                                                                                                                                                                                          | 3/28 [00:00<00:04,  5.67it/s]2026-04-14 00:02:17 [info     ] compilation took 1375.7347777998075 sec.
 29%|██████████████████████████████████████████████████████████████████████                                                                                                                                                                               | 8/28 [00:01<00:04,  4.82it/s]2026-04-14 00:02:17 [info     ] starting inference run...     
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:05<00:00,  5.56it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  5.67it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.20it/s]
 54%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋                                                                                                                 | 15/28 [00:02<00:02,  6.21it/s]2026-04-14 00:02:25 [info     ] inference time: 7.2921628234907985
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.19it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.23it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.20it/s]
 21%|████████████████████████████████████████████████████▌                                                                                                                                                                                                | 6/28 [00:00<00:03,  6.22it/s]/mnt/disks/external_disk/diffusers/src/diffusers/image_processor.py:142: RuntimeWarning: invalid value encountered in cast
  images = (images * 255).round().astype("uint8")
 54%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋                                                                                                                 | 15/28 [00:02<00:02,  6.18it/s]2026-04-14 00:02:33 [info     ] inference time: 7.279818863607943
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.17it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.13it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.19it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.19it/s]
 25%|█████████████████████████████████████████████████████████████▎                                                                                                                                                                                       | 7/28 [00:01<00:03,  6.20it/s]2026-04-14 00:02:40 [info     ] inference time: 7.278554333373904
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.18it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.21it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.20it/s]
 25%|█████████████████████████████████████████████████████████████▎                                                                                                                                                                                       | 7/28 [00:01<00:03,  6.21it/s]2026-04-14 00:02:47 [info     ] inference time: 7.277371223084629
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.18it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.24it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.13it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.18it/s]
 21%|████████████████████████████████████████████████████▌                                                                                                                                                                                                | 6/28 [00:00<00:03,  6.14it/s]2026-04-14 00:02:54 [info     ] inference time: 7.279732591472566
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.09it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.22it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.12it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.17it/s]
 29%|██████████████████████████████████████████████████████████████████████                                                                                                                                                                               | 8/28 [00:01<00:03,  6.19it/s]2026-04-14 00:03:02 [info     ] inference time: 7.274473122321069
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.16it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.20it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.09it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.17it/s]
 14%|███████████████████████████████████                                                                                                                                                                                                                  | 4/28 [00:00<00:03,  6.11it/s]2026-04-14 00:03:09 [info     ] inference time: 7.275974681600928
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.11it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.21it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.13it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.17it/s]
 11%|██████████████████████████▎                                                                                                                                                                                                                          | 3/28 [00:00<00:04,  6.10it/s]2026-04-14 00:03:16 [info     ] inference time: 7.2750104842707515
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.18it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.20it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.13it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.15it/s]
  7%|█████████████████▌                                                                                                                                                                                                                                   | 2/28 [00:00<00:04,  6.05it/s]2026-04-14 00:03:23 [info     ] inference time: 7.276151769794524
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.15it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.22it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.11it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.16it/s]
 32%|██████████████████████████████████████████████████████████████████████████████▊                                                                                                                                                                      | 9/28 [00:01<00:03,  6.20it/s]2026-04-14 00:03:31 [info     ] inference time: 7.275157613679767
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.20it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.16it/s]
  0%|                                                                                                                                                                                                                                                             | 0/28 [00:00<?, ?it/s]2026-04-14 00:03:38 [info     ] inference time: 7.274583547376096
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.18it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.23it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.10it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.16it/s]
 32%|██████████████████████████████████████████████████████████████████████████████▊                                                                                                                                                                      | 9/28 [00:01<00:03,  6.26it/s]2026-04-14 00:03:45 [info     ] inference time: 7.278900706209242
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.17it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.22it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
 61%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏                                                                                               | 17/28 [00:02<00:01,  6.15it/s]2026-04-14 00:03:53 [info     ] inference time: 7.275342025794089
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.16it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.23it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.11it/s]
 61%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏                                                                                               | 17/28 [00:02<00:01,  6.20it/s]2026-04-14 00:04:00 [info     ] inference time: 7.274883633479476
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.14it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.21it/s]
 96%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎        | 27/28 [00:04<00:00,  6.18it/s]2026-04-14 00:04:04 [info     ] avg. inference over 15 iterations took 7.254527554412683 sec.
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.15it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:04<00:00,  6.11it/s]
2026-04-14 00:04:05 [info     ] avg. inference over 15 iterations took 7.233675383528074 sec.
2026-04-14 00:04:07 [info     ] inference time: 7.275593389756978
2026-04-14 00:04:07 [info     ] avg. inference over 15 iterations took 7.2775807206208505 sec.
2026-04-14 00:04:07 [info     ] saved metric information as /tmp/metrics_report.txt
2026-04-14 00:04:08 [info     ] avg. inference over 15 iterations took 7.433206840852896 sec.

@sayakpaul
Copy link
Copy Markdown
Member Author

sayakpaul commented Apr 14, 2026

Closing this in favor of #13463

Thanks a lot!

@sayakpaul sayakpaul closed this Apr 14, 2026
@sayakpaul sayakpaul deleted the flux-inference-ptxla branch April 14, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants