Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not tracking tensors returned by tf.reshape() for data sources other than MNIST #195

Open
khatchad opened this issue May 8, 2024 · 5 comments · Fixed by ponder-lab/ML#105
Labels
bug Something isn't working help wanted Extra attention is needed summaries

Comments

@khatchad
Copy link
Collaborator

khatchad commented May 8, 2024

Consider the following code:

# tf2_test_reshape.py
# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/reshape

import tensorflow as tf


def f(a):
    pass


t1 = tf.ones([2, 3])
t2 = tf.reshape(t1, [6])
f(t2)

t2 should be a (reshaped) tensor, and the argument to f() should also be tracked as a tensor. Instead, I'm seeing this tensor analysis result:

[INFO] Tensor analysis: answer:
[Node: synthetic < PythonLoader, Ltensorflow/functions/reshape, do()LRoot; > Context: CallStringContext: [ script tf2_test_reshape.py.do()LRoot;@105 ], v2][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_reshape.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v245][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Ret-V:Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_reshape.py.do()LRoot;@100 ]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_reshape.py.do()LRoot;@100 ], v5][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]

In the IR, v245 refers to the return value of tf.ones(). That's the only tensor in this file.

Regression

  • There is a summary for tf.reshape(), but it calls copy_data() instead of read_data().
  • There is special handling of tf.reshape() in the code, stemming from the MethodReference field com.ibm.wala.cast.python.ml.client.PythonTensorAnalysisEngine.reshape.
@khatchad
Copy link
Collaborator Author

khatchad commented May 8, 2024

Add this test works:

ponder-lab@2db36e2

I believe the problem is that the data sources are hard-coded:

TensorType mnistData = TensorType.mnistInput();
Map<PointsToSetVariable, TensorType> init = HashMapFactory.make();
for (PointsToSetVariable v : sources) {
init.put(v, mnistData);
}

@khatchad khatchad changed the title Not tracking tensor that is returned by tf.reshape() Not tracking tensors returned by tf.reshape() for data sources other than MNIST May 8, 2024
@khatchad
Copy link
Collaborator Author

khatchad commented May 8, 2024

But, it could also have something to do with the way other APIs are being constructed. For example, the points-to set for tf.ones() is empty.

@khatchad
Copy link
Collaborator Author

khatchad commented May 9, 2024

Looking at the summary of tf.reshape(), I see that there's a data copy:

<class name="reshape" allocatable="true">
<method name="copy_data" descriptor="()LRoot;">
<new def="x" class="Ltensorflow/examples/tutorials/mnist/dataset" />
<return value="x" />
</method>
<method name="do" descriptor="()LRoot;" numArgs="3">
<call class="LRoot" name="copy_data" descriptor="()LRoot;" type="virtual" arg0="arg0" def="x" />
<return value="x" />
</method>
</class>

That may mean if the data source has something wrong with it, any copied data would also have the problem. Thus, the problem may not be with the tf.reshape() operation itself but rather with how data sources other than MNIST are constructed.

@khatchad
Copy link
Collaborator Author

khatchad commented May 9, 2024

That being said, copy_data() in the above summary doesn't use its argument.

@khatchad
Copy link
Collaborator Author

khatchad commented May 9, 2024

Thus, my best guess is that the problem involves a combination of the (new) XML summaries and the hard-coded initialization of the dataflow.

@khatchad khatchad added the help wanted Extra attention is needed label May 9, 2024
khatchad added a commit to ponder-lab/ML that referenced this issue May 9, 2024
khatchad added a commit to ponder-lab/Hybridize-Functions-Refactoring that referenced this issue May 9, 2024
@khatchad khatchad reopened this Nov 8, 2024
@khatchad khatchad closed this as completed Nov 8, 2024
@khatchad khatchad reopened this Nov 8, 2024
msridhar pushed a commit that referenced this issue Nov 8, 2024
Sorry for the large sync up. I'll try to summarize the changes as best
as I can:

- Start a `CODEOWNERS` file (please modify if desired).
- Add dependabot build schedule.
- Move Black out of spotless and into the build (much faster; spotless
support for Black is not working well).
- Various formatting fixes as a result of expanding spotless to XML
files and others.
- Make other metadata consistent with "recent" change to Java upgrade.
- `PYTHONPATH` module fixes (e.g.,
#209).
- Workaround #195.
- Enhance TF2 tests: fail if we don't have a node for a function under
test (was passing before). Because the ML tests are still on Jython 2
and modules aren't supported there, we have a bunch of tests to
consider.
- Initialization script enhancements (e.g.,
#202).
- Add `reshape()` parsing (this causes a need for a workaround after
exposing a bug).
- Some dependency version upgrades.
- Various entry point additions, e.g., `abseil`, `click`.
- Add missing initialization files (`__init__.py`).

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed summaries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant