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

Losing tensors in datasets #89

Closed
khatchad opened this issue Oct 11, 2023 · 1 comment · Fixed by ponder-lab/ML#63
Closed

Losing tensors in datasets #89

khatchad opened this issue Oct 11, 2023 · 1 comment · Fixed by ponder-lab/ML#63
Labels
bug Something isn't working

Comments

@khatchad
Copy link
Collaborator

khatchad commented Oct 11, 2023

Description

Currently, we cannot track tensors contained in tf.data.Datasets:

import tensorflow as tf


def add(a, b):
  return a + b


dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3])

for element in dataset:
    c = add(element, element)

We get:

Oct 11, 2023 11:09:48 AM com.ibm.wala.cast.python.ml.test.TestTensorflowModel testTf2
INFO: Tensor analysis: answer:

Regression

List Literals

Seems to work just fine with lists:

import tensorflow as tf


def add(a, b):
  return a + b


list = [tf.ones([1, 2]), tf.ones([2, 2])]

for element in list:
    c = add(element, element)

We get:

Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.client.PythonTensorAnalysisEngine getDataflowSources
INFO: Added dataflow source [Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_tensor_list.py.do()LRoot;@103 ], v5]:[Empty].
Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.client.PythonTensorAnalysisEngine getDataflowSources
INFO: Added dataflow source [Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_tensor_list.py.do()LRoot;@97 ], v5]:[Empty].
Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel testTf2
INFO: Tensor analysis: answer:
[SITE_IN_NODE{<Code body of function Lscript tf2_test_tensor_list.py>:Llist in CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]},<field 0>][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v249][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[SITE_IN_NODE{<Code body of function Lscript tf2_test_tensor_list.py>:Llist in CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]}; [Core[Root]]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[SITE_IN_NODE{<Code body of function Lscript tf2_test_tensor_list.py>:Llist in CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ]},<field 1>][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v257][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v265][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[<field global element>][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v268][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v267][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v270][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v271][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py/add> Context: CallStringContext: [ script tf2_test_tensor_list.py.do()LRoot;@117 ], v2][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list.py/add> Context: CallStringContext: [ script tf2_test_tensor_list.py.do()LRoot;@117 ], v3][{[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_tensor_list.py.do()LRoot;@103 ]][{[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_tensor_list.py.do()LRoot;@97 ]][{[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_tensor_list.py.do()LRoot;@103 ], v5][{[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_tensor_list.py.do()LRoot;@97 ], v5][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]

Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.ipa.callgraph.propagation.InstanceFieldKey
Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.cast.ipa.callgraph.ReflectedFieldPointerKey$3
Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.ipa.callgraph.propagation.InstanceFieldKey
Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.ipa.callgraph.propagation.StaticFieldKey
Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.ipa.callgraph.propagation.ReturnValueKey
Oct 11, 2023 2:25:11 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.ipa.callgraph.propagation.ReturnValueKey

Lists Without Literals

But, creating a list without using a literal doesn't work:

import tensorflow as tf


def add(a, b):
  return a + b


list = list()

list.append(tf.ones([1, 2]))
list.append(tf.ones([2, 2]))

for element in list:
    c = add(element, element)

We get:

Oct 11, 2023 2:51:26 PM com.ibm.wala.cast.python.ml.client.PythonTensorAnalysisEngine getDataflowSources
INFO: Added dataflow source [Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_tensor_list3.py.do()LRoot;@106 ], v5]:[Empty].
Oct 11, 2023 2:51:26 PM com.ibm.wala.cast.python.ml.client.PythonTensorAnalysisEngine getDataflowSources
INFO: Added dataflow source [Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_tensor_list3.py.do()LRoot;@99 ], v5]:[Empty].
Oct 11, 2023 2:51:26 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel testTf2
INFO: Tensor analysis: answer:
[Node: <Code body of function Lscript tf2_test_tensor_list3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v264][{[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_tensor_list3.py.do()LRoot;@106 ]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_tensor_list3.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v252][{[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_tensor_list3.py.do()LRoot;@99 ]][{[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_tensor_list3.py.do()LRoot;@106 ], v5][{[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_tensor_list3.py.do()LRoot;@99 ], v5][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]

Oct 11, 2023 2:51:26 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.ipa.callgraph.propagation.ReturnValueKey
Oct 11, 2023 2:51:26 PM com.ibm.wala.cast.python.ml.test.TestTensorflowModel lambda$0
WARNING: Encountered: class com.ibm.wala.ipa.callgraph.propagation.ReturnValueKey
@khatchad khatchad added the bug Something isn't working label Oct 11, 2023
khatchad added a commit to ponder-lab/ML that referenced this issue Oct 11, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
khatchad added a commit that referenced this issue Oct 11, 2023
khatchad added a commit to ponder-lab/ML that referenced this issue Oct 11, 2023
Use list instead of Dataset.
khatchad added a commit to ponder-lab/ML that referenced this issue Oct 11, 2023
Pass the entire list.
khatchad added a commit to ponder-lab/ML that referenced this issue Oct 11, 2023
List without list literal.
khatchad added a commit that referenced this issue Oct 17, 2023
Add test case for #89. We lose track of the tensors in the dataset.
@khatchad
Copy link
Collaborator Author

khatchad commented Dec 5, 2023

Potentially helpful reference: https://www.tensorflow.org/api_docs/python/tf/data/Iterator

@khatchad khatchad linked a pull request Dec 16, 2023 that will close this issue
khatchad added a commit to ponder-lab/ML that referenced this issue Dec 16, 2023
Use list instead of Dataset.
khatchad added a commit to ponder-lab/ML that referenced this issue Dec 16, 2023
Pass the entire list.
khatchad added a commit to ponder-lab/ML that referenced this issue Dec 16, 2023
List without list literal.
khatchad added a commit that referenced this issue Dec 20, 2023
Basic fix for #89; more APIs to come.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant