Evaluate a symint to int. Returns None if symint's symoblic expr can not be evaluated to valid integer according to the hints.
(symint: Union[int, torch.SymInt])
| 15 | |
| 16 | |
| 17 | def eval_expr(symint: Union[int, torch.SymInt]) -> Optional[int]: |
| 18 | """ |
| 19 | Evaluate a symint to int. Returns None if symint's symoblic expr |
| 20 | can not be evaluated to valid integer according to the hints. |
| 21 | """ |
| 22 | if isinstance(symint, int): |
| 23 | return symint |
| 24 | node = symint.node |
| 25 | shape_env = node.shape_env |
| 26 | expr = node.expr |
| 27 | try: |
| 28 | if hasattr(shape_env, "guarding_hint_or_throw"): |
| 29 | output = shape_env.guarding_hint_or_throw(expr) |
| 30 | else: |
| 31 | # size_hint is deprecated, delete this code path. |
| 32 | output = shape_env.size_hint(expr) |
| 33 | except torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode: |
| 34 | return None |
| 35 | return int(output) |
| 36 | |
| 37 | |
| 38 | def eval_upper_bound(maybe_symint: Union[int, torch.SymInt]) -> int: |
no outgoing calls
no test coverage detected