Improve is_fbcode functionality (#136871)

Summary: Previously is_fbcode just checked whether the checkout was git or not. This is extremely error prone. Lets make it fool-proof.

Test Plan: unit tests

Reviewed By: masnesral

Differential Revision: D63545169

Pull Request resolved: https://github.com/pytorch/pytorch/pull/136871
Approved by: https://github.com/masnesral
This commit is contained in:
Oguz Ulgen 2024-09-27 21:19:01 +00:00 committed by PyTorch MergeBot
parent 283bda01aa
commit a28b40fa74
5 changed files with 6 additions and 16 deletions

View File

@ -7,6 +7,7 @@ from unittest import skipIf
import torch
import torch.utils.cpp_extension
from torch._environment import is_fbcode
from torch.testing._internal.common_utils import IS_WINDOWS, run_tests, TestCase
@ -21,10 +22,6 @@ def remove_build_path():
shutil.rmtree(default_build_root)
def is_fbcode():
return not hasattr(torch.version, "git_version")
if is_fbcode():
import caffe2.test.profiler_test_cpp_thread_lib as cpp # @manual=//caffe2/test:profiler_test_cpp_thread_lib
else:

View File

@ -6,6 +6,7 @@ from collections import Counter
from typing import Dict
import torch
from torch._environment import is_fbcode
from torch._export import capture_pre_autograd_graph
from torch.ao.quantization import (
compare_results,
@ -40,10 +41,6 @@ def _extract_debug_handles(model) -> Dict[str, int]:
return debug_handle_map
def is_fbcode():
return not hasattr(torch.version, "git_version")
@unittest.skipIf(IS_WINDOWS, "Windows not yet supported for torch.compile")
class TestNumericDebugger(TestCase):
def test_simple(self):

View File

@ -9,10 +9,7 @@ from os.path import abspath, dirname
from typing import Any, Callable, Dict, Optional, Set, Type, TYPE_CHECKING, Union
import torch
def is_fbcode():
return not hasattr(torch.version, "git_version")
from torch._environment import is_fbcode
# to configure logging for dynamo, aot, and inductor

2
torch/_environment.py Normal file
View File

@ -0,0 +1,2 @@
def is_fbcode() -> bool:
return False

View File

@ -3,10 +3,7 @@ import sys
from typing import Any, Callable, Dict, List, Optional, TYPE_CHECKING, Union
import torch
def is_fbcode() -> bool:
return not hasattr(torch.version, "git_version")
from torch._environment import is_fbcode
def _get_tristate_env(name: str) -> Optional[bool]: