pytorch/torch/csrc/jit
Meghan Lele 28c5d90b67 [JIT] Allow implicit boolean conversion of containers (#51683)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51683

**Summary**
This commit enables implicit boolean conversion of lists, strings, and
dictionaries in conditional expressions. Like Python, empty lists,
strings and dictionaries evaluate to `False` and their non-empty
counterparts evaluate to `True`. This allows users to write code like

```
torch.jit.script
def fn(l: List[int]):
  if l:
    ...
  else:
    ...
```

This has been requested by some users and would be a good usability
improvement.

**Test Plan**
This commit adds unit tests to `TestList`, `TestDict` and
`test_jit_string.py` to test this new feature.

Test Plan: Imported from OSS

Reviewed By: pbelevich

Differential Revision: D26264410

Pulled By: SplitInfinity

fbshipit-source-id: b764c18fd766cfc128ea98a02b7c6c3fa49f8632
2021-02-05 00:34:35 -08:00
..
api T66557700 Support default argument values of a method (#48863) 2021-02-01 18:35:13 -08:00
backends [codemod][fbcode/caffe2] Apply clang-format update fixes 2021-01-09 14:37:36 -08:00
codegen [Fuser] Do not attempt to use OpenMP if build without OpenMP support (#51504) 2021-02-02 15:31:59 -08:00
cuda Adding JIT support for cuda streams and events (#48020) 2020-12-29 20:24:57 -08:00
docs Fix errata (#49903) 2020-12-28 20:40:41 -08:00
frontend [JIT] Allow implicit boolean conversion of containers (#51683) 2021-02-05 00:34:35 -08:00
ir Graceful invalidation of Python Node/Value/Block when C++ object is deleted (#50326) 2021-02-04 01:34:46 -08:00
mobile [PyTorch Mobile] Support torchbind custom classes in lite interpreter (#51432) 2021-02-03 21:57:19 -08:00
passes Linear autodiff revert revert (#51613) 2021-02-04 16:32:05 -08:00
python Fix clang-tidy warnings in python_sugared_value.{h,cpp} (#51703) 2021-02-04 21:29:40 -08:00
runtime Linear autodiff revert revert (#51613) 2021-02-04 16:32:05 -08:00
serialization [PyTorch Mobile] Support torchbind custom classes in lite interpreter (#51432) 2021-02-03 21:57:19 -08:00
tensorexpr Make te a hidden package for now (#51690) 2021-02-04 07:58:38 -08:00
testing [codemod][fbcode/caffe2] Apply clang-format update fixes 2021-01-09 14:37:36 -08:00
jit_log.cpp [jit] Speed up saving in case of many classes (#44589) 2020-09-15 15:10:45 -07:00
jit_log.h added macros in jit logging to check whether loggings are enabled; replaced similar checks in LLVM codegen with such macros (#49121) 2020-12-21 13:01:22 -08:00
jit_opt_limit.cpp Implement optimization bisect (#49031) 2021-01-11 12:25:28 -08:00
jit_opt_limit.h Update JIT_OPT macro for easier use (#50602) 2021-01-20 11:15:20 -08:00
OVERVIEW.md Update JIT_OPT macro for easier use (#50602) 2021-01-20 11:15:20 -08:00
README.md [jit] add top-level readme to csrc/jit (#33916) 2020-02-27 19:21:05 -08:00
resource_guard.h

PyTorch JIT

This folder contains (most of) the C++ code for the PyTorch JIT, a language and compiler stack for executing PyTorch models portably and efficiently. To learn more about the JIT from a user perspective, please consult our reference documentation and tutorials.

A brief summary of the source tree:

  • OVERVIEW.md: High-level technical overview of the JIT.
  • frontend/: Taking PyTorch modules in Python and translating them into the JIT IR.
  • ir/: Core IR abstractions.
  • runtime/: Interpreter, graph execution, and JIT operators.
  • codegen/: Generating efficient, hardware-specific code for JIT subgraphs.
  • serialization/: Saving and loading modules.
  • api/: Any user-facing C++ or Python interfaces.
  • python/: Binding stuff into Python or accessing information from the Python environment.
  • testing/: Utilities and helpers for testing.
  • mobile/: Mobile-specific implementations of runtime components.
  • passes/: IR-to-IR passes, generally for optimization and lowering.
  • generated/: This folder is generated by the PyTorch build, and contains bindings for native PyTorch operators into the JIT.

Refer to each folder for more in-depth documentation.

Other relevant parts of the codebase not contained here:

  • aten/src/ATen/core: contains JIT code re-used by other elements of the runtime system (eager, mobile, etc.)