Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally set default TPU settings in __init__.py #5696

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion torch_xla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def _setup_default_env():
_set_missing_env('GRPC_VERBOSITY', 'ERROR')
_set_missing_env('ALLOW_MULTIPLE_LIBTPU_LOAD', '1')
_set_missing_env('TPU_ML_PLATFORM', 'PyTorch/XLA')
_set_missing_env('TPU_MEGACORE', 'megacore_dense')


_fd, _tmp_fname = -1, ''
Expand Down
3 changes: 3 additions & 0 deletions torch_xla/_internal/tpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ def configure_topology(local_rank: int,
os.environ.setdefault(xenv.TPU_VISIBLE_CHIPS, str(local_rank))
os.environ.setdefault(xenv.TPU_PROCESS_PORT, str(ports[local_rank]))

if version() == 4:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it guaranteed that this will be called all the time and will be before any modeling code involved tpu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this will only get called for sure when using torchrun or xmp.spawn.. Good catch.

It makes the most logical sense to me to set these up during client initialization, but that happens in C++ and all of the TPU utilities are in Python. I'll make this setting conditional in __init__.py for now.

os.environ.setdefault(xenv.TPU_MEGACORE, 'megacore_dense')


def discover_master_worker_ip(use_localhost: bool = True) -> str:
"""Find the IP of the TPU host with TPU:0.
Expand Down
1 change: 1 addition & 0 deletions torch_xla/core/xla_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TPU_PROCESS_ADDRESSES = 'TPU_PROCESS_ADDRESSES'
TPU_VISIBLE_CHIPS = 'TPU_VISIBLE_CHIPS'
TPU_PROCESS_PORT = 'TPU_PROCESS_PORT'
TPU_MEGACORE = 'TPU_MEGACORE'
PJRT_CPU_ASYNC_CLIENT = 'PJRT_CPU_ASYNC_CLIENT'
PJRT_GPU_ASYNC_CLIENT = 'PJRT_GPU_ASYNC_CLIENT'
PJRT_DIST_SERVICE_ADDR = 'PJRT_DIST_SERVICE_ADDR'
Expand Down
Loading