_config.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import os
  2. import sys
  3. from typing import Optional
  4. from torch.utils._config_module import Config, install_config_module
  5. # [@compile_ignored: debug] Fails hard instead of graph breaking on guard on data dependent errors.
  6. no_data_dependent_graph_break = (
  7. os.environ.get("TORCHDYNAMO_NO_DATA_DEPENDENT_GRAPH_BREAK", "0") == "1"
  8. )
  9. # [@compile_ignored: debug] Uses z3 for validating the guard optimizations transformations.
  10. translation_validation = (
  11. os.environ.get("TORCHDYNAMO_TRANSLATION_VALIDATION", "0") == "1"
  12. )
  13. # Timeout (in milliseconds) for z3 finding a solution.
  14. # [@compile_ignored: debug]
  15. translation_validation_timeout = int(
  16. os.environ.get("TORCHDYNAMO_TRANSLATION_VALIDATION_TIMEOUT", "600000")
  17. )
  18. # Disables bisection for translation validation.
  19. #
  20. # Translation validation bisection is enabled by default, if translation validation
  21. # is also enabled. This should help finding guard simplification issues. However,
  22. # since validation uses Z3 for bisecting, it might take a lot of time.
  23. #
  24. # Set this configuration option so as to avoid bisecting.
  25. # [@compile_ignored: debug]
  26. translation_validation_no_bisect = (
  27. os.environ.get("TORCHDYNAMO_TRANSLATION_NO_BISECT", "0") == "1"
  28. )
  29. # Checks whether replaying ShapeEnv events on a freshly constructed one yields
  30. # the a ShapeEnv with the same state. This should be used only in testing.
  31. check_shape_env_recorded_events = False
  32. # TODO: Perhaps consider allowing unions for the configs below (so you can hit
  33. # multiple reps at the same time)
  34. # Give extended debug information if the string representation of a guard
  35. # matches this. For example, set this to "Ne(s0, 10)" and whenever we issue
  36. # this guard, we will generate full Python and C++ backtrace
  37. # [@compile_ignored: debug]
  38. extended_debug_guard_added = os.environ.get(
  39. "TORCHDYNAMO_EXTENDED_DEBUG_GUARD_ADDED", None
  40. )
  41. # Give extended debug information when a particular symbol is allocated. For
  42. # example, set this to "u2" and whenever we create this symbol, we will
  43. # generate full Python and C++ backtrace
  44. # [@compile_ignored: debug]
  45. extended_debug_create_symbol = os.environ.get(
  46. "TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL", None
  47. )
  48. # Give extended debug information (C++ backtrace) for all extended debug
  49. # settings as well as errors. The C++ backtrace is slow and very spammy so we
  50. # don't include it by default even when you're requesting extended debug.
  51. # [@compile_ignored: debug]
  52. extended_debug_cpp = os.environ.get("TORCHDYNAMO_EXTENDED_DEBUG_CPP", "") != ""
  53. # Give extended debug information (line of code) when a torch function
  54. # is called during export. This is useful for showing progress and detecting
  55. # where export might be stuck. Currently only works for strict=False.
  56. # [@compile_ignored: debug]
  57. extended_debug_current_loc = (
  58. os.environ.get("TORCHEXPORT_EXTENDED_DEBUG_CURRENT_LOC", "0") == "1"
  59. )
  60. # [@compile_ignored: debug] Show a warning for every specialization
  61. print_specializations = False
  62. # wraps (un)equalities with 'Not' class after recording the correct expression
  63. # in the FX graph. This should incorrectly construct the divisible and replacement
  64. # lists, and incorrectly issue guards.
  65. inject_EVALUATE_EXPR_flip_equality_TESTING_ONLY = False
  66. # [@compile_ignored: debug] Validate that ShapeEnv's version key is updated correctly
  67. validate_shape_env_version_key = False
  68. # If we produce more than this many guards on a symbol, force the symbol to
  69. # get specialized and bail out if this many guards mention this particular
  70. # symbol. This may be slightly more aggressive than the true number of guards
  71. # issued (as we test if we've hit the limit on-the-fly, whereas we may
  72. # do further simplifications at final guard issuance time that make guards
  73. # irrelevant.)
  74. symbol_guard_limit_before_specialize: Optional[int] = None
  75. # This flag changes whether we should use the same symbolic variable to represent input sizes that are the same.
  76. use_duck_shape = True
  77. # Controls the registration of torch.nonzero() on the meta device.
  78. # When True, nonzero returns a tensor with shape (self.numel(), self.dim())
  79. # assuming all elements are none-zero.
  80. # Default is False to prevent unintended registration. Set to True to enable.
  81. meta_nonzero_assume_all_nonzero = False
  82. # Applies size-oblivious reasoning to backed symbols. This allocates a [0, inf] range for backed size symbols,
  83. # and relies on size-oblivious semantics to avoid 0/1 specialization guards by marking them size-like.
  84. # Currently an experimental option for export.
  85. backed_size_oblivious = False
  86. # Skip dtype check in meta registrations. Only used for systems that does its own dtype checking.
  87. skip_dtype_check_in_meta_registrations = False
  88. # Experimental: If True, graph module will register fx metadata during recompile()
  89. enrich_profiler_metadata: bool = Config( # type: ignore[var-annotated]
  90. default=False,
  91. env_name_default="TORCH_ENRICH_RPOFILER_STACK_TRACE",
  92. )
  93. # When True, log a warning instead of raising PendingUnbackedSymbolNotFound exception
  94. # when pending unbacked symbols are not found in returned outputs.
  95. # The worst that can happen is an error somewhere else in the stack where we expect
  96. # to locate an unbacked binding. Or a runtime assertion not being lowered in the output
  97. # code.
  98. soft_pending_unbacked_not_found_error = False
  99. install_config_module(sys.modules[__name__])