You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a warning if a tensor is evaluated while compiling
In the case where a tensor is evaluated while compiling and then used in the
computation graph, we throw an error. However, there are cases where the result
of evaluation could make a round-trip through non-Tripy code, in which case we lose
visibility. An example of this, assuming `a` and `b` are tensors, is:
```py
b = b + int(a.shape[0])
```
Here, `a.shape[0]` will be evaluated due to the `int` conversion and then
used by the add operation with `b`. Because it was a Python integer in between,
Tripy has no way to track that it actually came from an evaluated tensor.
Hence, this change prints warnings in these ambiguous cases when a tensor
is evaluated while compiling. Here's an example of the warning messages:
```
[W] Tensor was evaluated while compiling which may cause unexpected behavior in the executable.
For example, this could cause values to be baked into the executable or dynamic shapes to become static.
If the result of the evaluation is not being used by other operations, you can safely ignore this warning.
[W] Note: Tensor was evaluated while compiling here:
--> /tripy/tests/backend/api/test_compile.py:174 in func()
|
174 | print(a.shape)
| ^^^^^^^^^^^^^^
[2, 3]
[W] Note: Tensor was evaluated while compiling here:
--> /tripy/tests/backend/api/test_compile.py:176 in func()
|
176 | c = a - int(a.shape[0])
| ^^^^^^^^^^^^^^^
[W] Note: Tensor was evaluated while compiling here:
--> /tripy/tests/backend/api/test_compile.py:177 in func()
|
177 | print(c)
| ^^^^^^^^
```
0 commit comments