pytorch-lightning icon indicating copy to clipboard operation
pytorch-lightning copied to clipboard

bugfix: add support for `global_ordinal`, `local_ordinal`, `world_size` in xla

Open AlexandrByzov opened this issue 7 months ago • 2 comments

What does this PR do?

PyTorch XLA has deprecated several methods in PyTorch 2.7:

  • Remove torch_xla.core.xla_model.xrt_world_size, replace with torch_xla.runtime.world_size
  • Remove torch_xla.core.xla_model.get_ordinal, replace with torch_xla.runtime.global_ordinal

See here

Fixes #20852

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs): No
  • [x] Did you read the contributor guideline, Pull Request section?
  • [x] Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs): Tests were already written
  • [x] Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR. Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • [x] Is this pull request ready for review? (if not, please submit in draft mode)
  • [x] Check that all items from Before submitting are resolved
  • [x] Make sure the title is self-explanatory and the description concisely explains the PR
  • [ ] Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--20872.org.readthedocs.build/en/20872/

AlexandrByzov avatar Jun 03 '25 16:06 AlexandrByzov

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 87%. Comparing base (577c04d) to head (4e7aebd). :warning: Report is 199 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #20872   +/-   ##
=======================================
  Coverage      87%      87%           
=======================================
  Files         268      268           
  Lines       23341    23363   +22     
=======================================
+ Hits        20330    20357   +27     
+ Misses       3011     3006    -5     

codecov[bot] avatar Jun 03 '25 17:06 codecov[bot]

thank you for this finding! could you pls add test to cover this new behaviour? can this XLA be also run without TPU?

Thank you for taking the time to review. I implemented a test with mocks, because as far as I understand torch_xla is not used in tests without TPU. Generally, it is very much possible to use XLA with CPU or even GPU, but this will require a large change in tests and probably a separate issue/s

AlexandrByzov avatar Jun 15 '25 15:06 AlexandrByzov

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://lightning.ai/docs/pytorch/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Discord. Thank you for your contributions.

stale[bot] avatar Jul 19 '25 05:07 stale[bot]

Is there anything else that can be done for this MR @Borda ? I will be glad to work on it further

AlexandrByzov avatar Jul 19 '25 17:07 AlexandrByzov