pytorch/torch/csrc/utils
Michael Lazos 48ee0984ac Add C API to return all torch function disablement status (#133136)
This PR adds a C function to check if all torch function is disabled.
Recall that there are three torch function enablement states:
* All disabled
* Torch Function Subclass disabled
* All enabled

The API before this change provides two functions:
* `_is_torch_function_enabled` - returns True iff the current TF state is All enabled
* `_is_torch_function_mode_enabled` - returns True iff the state is not All disabled and the torch function mode stack is non-empty.

The crux of why a new API is needed is the following: If dynamo enters a frame with the torch function mode stack empty, `_is_torch_function_enabled` == False, it is impossible to determine if after a new mode is pushed whether we should enter the mode or not. This is because we don't know if the enablement state is All disabled or only subclass disabled. Adding this API to check if All disabled is True allows us to disambiguate this case.

In the next PR, Dynamo InstructionTranslator will have clearer flags than the underlying C API:
* A flag to indicate if subclasses are disabled (ie All disabled or Subclass Disabled is the current state)
* A flag to indicate if modes are disabled (ie if All disabled is the current state)
* A symbolic stack which can be checked if any modes are present

Pull Request resolved: https://github.com/pytorch/pytorch/pull/133136
Approved by: https://github.com/bdhirsh
ghstack dependencies: #133130, #133729, #133131, #133132, #133133, #133134
2024-08-20 07:15:04 +00:00
..
byte_order.cpp [2/N] Fix Wunused-parameter warnings (#131170) 2024-07-19 23:58:56 +00:00
byte_order.h [2/N] Fix Wunused-parameter warnings (#131170) 2024-07-19 23:58:56 +00:00
cpp_stacktraces.cpp Fast standalone symbolize for unwinding (#123966) 2024-05-14 19:39:17 +00:00
cpp_stacktraces.h Fast standalone symbolize for unwinding (#123966) 2024-05-14 19:39:17 +00:00
cuda_enabled.h [2/N] Change static functions in headers to inline (#127764) 2024-06-04 00:49:04 +00:00
device_lazy_init.cpp
device_lazy_init.h [2/N] Change static functions in headers to inline (#127764) 2024-06-04 00:49:04 +00:00
disable_torch_function.cpp Add C API to return all torch function disablement status (#133136) 2024-08-20 07:15:04 +00:00
disable_torch_function.h Add C API to return all torch function disablement status (#133136) 2024-08-20 07:15:04 +00:00
init.cpp Concat namespaces in torch/csrc/utils/* (#128787) 2024-06-16 23:51:14 +00:00
init.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
invalid_arguments.cpp Fix typo in assignment operators (#131890) 2024-07-27 11:13:42 +00:00
invalid_arguments.h
nested.cpp [1/N] Change #include <c10/util/Optional.h> to #include <optional> (#128301) 2024-07-08 07:03:53 +00:00
nested.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
numpy_stub.h
object_ptr.cpp
object_ptr.h
out_types.cpp Concat namespaces in torch/csrc/utils/* (#128787) 2024-06-16 23:51:14 +00:00
out_types.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
pybind.cpp Concat namespaces in torch/csrc/utils/* (#128787) 2024-06-16 23:51:14 +00:00
pybind.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
pycfunction_helpers.h
pyobject_preservation.cpp
pyobject_preservation.h
python_arg_parser.cpp Change deprecate warning on dispatch_on_subclass to warn once (#132374) 2024-08-05 20:02:33 +00:00
python_arg_parser.h Specialize sym node when used as device kwarg (#131811) 2024-07-30 17:11:57 +00:00
python_compat.h [3.13] get C dynamo to compile with python callback and custom frame eval (#129171) 2024-06-21 15:58:02 +00:00
python_dispatch.cpp [18/N] Fix clang-tidy warnings in jit (#132963) 2024-08-09 01:27:32 +00:00
python_dispatch.h Add fallback() to torch.library (#131707) 2024-07-27 18:02:35 +00:00
python_numbers.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
python_raii.h [1/N] Change #include <c10/util/Optional.h> to #include <optional> (#128301) 2024-07-08 07:03:53 +00:00
python_scalars.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
python_strings.h [2/N] Change static functions in headers to inline (#127764) 2024-06-04 00:49:04 +00:00
python_stub.h
python_symnode.cpp Revert "Fix static py::object dangling pointer with py::gil_safe_call_once_and_store (#130341)" 2024-07-26 17:02:56 +00:00
python_symnode.h Add debug repr to SymNode (#129925) 2024-07-12 18:31:23 +00:00
python_torch_function_mode.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
python_tuples.h
pythoncapi_compat.h
schema_info.cpp [1/N] Change #include <c10/util/Optional.h> to #include <optional> (#128301) 2024-07-08 07:03:53 +00:00
schema_info.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
six.h
structseq.cpp Concat namespaces in torch/csrc/utils/* (#128787) 2024-06-16 23:51:14 +00:00
structseq.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_apply.cpp Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_apply.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_dtypes.cpp [custom_op] support default dtype values (#129189) 2024-06-23 00:13:23 +00:00
tensor_dtypes.h Support torch.dtype as parameter in pybind11 cpp extension. (#126865) 2024-05-29 23:19:32 +00:00
tensor_flatten.cpp Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_flatten.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_layouts.cpp Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_layouts.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_list.cpp Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_list.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_memoryformats.cpp Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_memoryformats.h
tensor_new.cpp Prevent an unnecessary device -> host copy for CuPy arrays when not explicitly setting a device in torch.as_tensor. (#132595) 2024-08-08 00:26:58 +00:00
tensor_new.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_numpy.cpp Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_numpy.h
tensor_qschemes.cpp Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_qschemes.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
tensor_types.cpp
tensor_types.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
throughput_benchmark-inl.h Concat namespaces and other fixes in torch/csrc/utils (#127833) 2024-06-04 15:12:45 +00:00
throughput_benchmark.cpp [18/N] Fix clang-tidy warnings in jit (#132963) 2024-08-09 01:27:32 +00:00
throughput_benchmark.h [18/N] Fix clang-tidy warnings in jit (#132963) 2024-08-09 01:27:32 +00:00
torch_dispatch_mode.h [1/N] Change #include <c10/util/Optional.h> to #include <optional> (#128301) 2024-07-08 07:03:53 +00:00
variadic.cpp
variadic.h Remove unused type traits in torch/csrc/utils (#128799) 2024-06-27 23:51:18 +00:00
verbose.cpp
verbose.h