Skip to content

Conversation

sshonTT
Copy link
Contributor

@sshonTT sshonTT commented Aug 21, 2025

… PJRT backend

Issue description : #9555

This change introduces the ability to pass custom compile options from Python down to the PJRT backend, allowing users to fine-tune XLA compilation behavior without modifying core code. Key changes:

  • Python API
    • Added custom_compile_options parameter to torch_xla.compile for passing compile-time options as a dict (supports bool, float, int, and str values).
    • Added torch_xla.set_custom_compile_options() utility for setting compile options globally.
    • Added internal binding _XLAC._set_custom_compile_options().
  • C++ Runtime
    • Added SetCustomCompileOptions() virtual method to ComputationClient and implemented it in PjRtComputationClient.
    • PjRtComputationClient now stores custom_compile_options_ and injects them into xla::CompileOptions.env_option_overrides during compilation.
    • Options are stringified before being passed to XLA for compatibility. Motivation:
This enables advanced users to pass through backend-specific tuning flags (e.g., enabling experimental optimizations, toggling partitioning strategies) without hardcoding them, improving flexibility for research and debugging workflows.

@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch from b3e8b3e to 2a4b284 Compare August 21, 2025 20:25
@sshonTT
Copy link
Contributor Author

sshonTT commented Aug 21, 2025

@qihqi Thank you for your review! I realized there was a lint issue and have fixed it. Would you mind re-running the tests?

@qihqi qihqi enabled auto-merge (squash) August 23, 2025 04:04
@qihqi
Copy link
Collaborator

qihqi commented Aug 25, 2025

hi @sshonTT would you rebase to latest HEAD? the 2 CI issue should be fixed

auto-merge was automatically disabled August 26, 2025 01:02

Head branch was pushed to by a user without write access

@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch from 2a4b284 to 2a2eed5 Compare August 26, 2025 01:02
@sshonTT
Copy link
Contributor Author

sshonTT commented Aug 26, 2025

hi @sshonTT would you rebase to latest HEAD? the 2 CI issue should be fixed

@qihqi thank you for the info. I had rebased so could you re-run test?

@sshonTT
Copy link
Contributor Author

sshonTT commented Aug 29, 2025

hi @qihqi , gentle reminder.

@sshonTT
Copy link
Contributor Author

sshonTT commented Sep 2, 2025

Hi @zhanyong-wan — not sure if this is the right tag. I’m waiting on @qihqi’s follow-up (he previously approved). I rebased per his suggestion and want to confirm CI is green. Could you trigger CI for this PR and, if you have time, give it a review? Thanks!

Copy link
Collaborator

@zhanyong-wan zhanyong-wan left a comment

Choose a reason for hiding this comment

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

Thanks!

@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch 3 times, most recently from 2bdd9ed to 7be5b39 Compare September 2, 2025 19:21
Copy link
Collaborator

@zhanyong-wan zhanyong-wan left a comment

Choose a reason for hiding this comment

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

Thanks!

@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch from 7be5b39 to 4278f97 Compare September 4, 2025 18:22
Copy link
Collaborator

@zhanyong-wan zhanyong-wan left a comment

Choose a reason for hiding this comment

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

In the future, could you avoid git rebase or git merge during a code review? Otherwise it's hard to track the changes. Thanks!

@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch from 4278f97 to f3ad8bd Compare September 5, 2025 15:59
@qihqi qihqi enabled auto-merge (squash) September 9, 2025 01:12
auto-merge was automatically disabled September 11, 2025 20:10

Head branch was pushed to by a user without write access

@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch from f3ad8bd to a27f105 Compare September 11, 2025 20:10
@sshonTT
Copy link
Contributor Author

sshonTT commented Sep 11, 2025

hi @qihqi, I see #9634 fixes build failure in ci, so I rebased it.

@qihqi qihqi enabled auto-merge (squash) September 19, 2025 17:00
auto-merge was automatically disabled October 2, 2025 14:26

Head branch was pushed to by a user without write access

@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch from a27f105 to 63bb881 Compare October 2, 2025 14:26
@sshonTT
Copy link
Contributor Author

sshonTT commented Oct 2, 2025

I noticed the efforts in #9650 and #9655 regarding the current build failure. Hopefully they will resolve the issue. I’ve rebased once again.

… PJRT backend

This change introduces the ability to pass custom compile options from Python down to the PJRT backend, allowing users to fine-tune XLA compilation behavior without modifying core code.
Key changes:
* Python API
    * Added custom_compile_options parameter to torch_xla.compile for passing compile-time options as a dict (supports bool, float, int, and str values).
    * Added torch_xla.set_custom_compile_options() utility for setting compile options globally.
    * Added internal binding _XLAC._set_custom_compile_options().
* C++ Runtime
    * Added SetCustomCompileOptions() virtual method to ComputationClient and implemented it in PjRtComputationClient.
    * PjRtComputationClient now stores custom_compile_options_ and injects them into xla::CompileOptions.env_option_overrides during compilation.
    * Options are stringified before being passed to XLA for compatibility.
Motivation:
This enables advanced users to pass through backend-specific tuning flags (e.g., enabling experimental optimizations, toggling partitioning strategies) without hardcoding them, improving flexibility for research and debugging workflows.
@sshonTT sshonTT force-pushed the sshon/custom-compiler-options-upstream branch from 63bb881 to 9799ed0 Compare October 2, 2025 18:23
@sshonTT
Copy link
Contributor Author

sshonTT commented Oct 2, 2025

I just noticed that GetComputationClientOrDie API is deprecated after https://github.com/pytorch/xla/pull/9620/files which is my fault, had to care about it. I just remove GetComputationClientOrDie.

@sshonTT
Copy link
Contributor Author

sshonTT commented Oct 7, 2025

@zhanyong-wan , @qihqi Could you re-trigger this test? I had checked on my local, and want to see if it is working.

@sshonTT
Copy link
Contributor Author

sshonTT commented Oct 9, 2025

Thanks for running CI! Can this be merged in?

@zhanyong-wan zhanyong-wan enabled auto-merge (squash) October 9, 2025 15:07
@zhanyong-wan
Copy link
Collaborator

Yes, please resolve the comments and merge.

@zhanyong-wan zhanyong-wan merged commit b1131d1 into pytorch:master Oct 9, 2025
24 checks passed
@sshonTT sshonTT deleted the sshon/custom-compiler-options-upstream branch October 9, 2025 15:53
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.

3 participants