Skip to content

Commit

Permalink
Conditionally set default TPU settings in __init__.py (pytorch#5696)
Browse files Browse the repository at this point in the history
* Set TPU_MEGACORE in configure_topology

* remove

* Move back to __init__.py
  • Loading branch information
will-cromar authored and mbzomowski committed Nov 16, 2023
1 parent 5cfe6f1 commit 9f4235a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions torch_xla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re
import tempfile

from ._internal import tpu

logging.basicConfig()
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -30,25 +32,24 @@ def _setup_xla_flags():
os.environ['XLA_FLAGS'] = ' '.join(flags)


def _set_missing_env(name, value):
if name not in os.environ:
os.environ[name] = value
def _setup_default_env():
os.environ.setdefault('TF_CPP_MIN_LOG_LEVEL', '1')
os.environ.setdefault('GRPC_VERBOSITY', 'ERROR')

if tpu.num_available_chips() > 0:
os.environ.setdefault('ALLOW_MULTIPLE_LIBTPU_LOAD', '1')
os.environ.setdefault('TPU_ML_PLATFORM', 'PyTorch/XLA')

def _setup_default_env():
_set_missing_env('TF_CPP_MIN_LOG_LEVEL', '1')
_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')
if tpu.version() == 4:
os.environ.setdefault('TPU_MEGACORE', 'megacore_dense')


_fd, _tmp_fname = -1, ''


def _setup_debug_env():
fd, tmp_fname = tempfile.mkstemp('.ptxla', text=True)
_set_missing_env('XLA_FNTRACKER_FILE', tmp_fname)
os.environ.setdefault('XLA_FNTRACKER_FILE', tmp_fname)
return fd, tmp_fname


Expand Down

0 comments on commit 9f4235a

Please sign in to comment.