xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/mlir/tensorflow/tests/graphdef2mlir/target.pbtxt (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1# RUN: tf-mlir-translate -graphdef-to-mlir -tf-enable-shape-inference-on-import=false %s -tf-control-output-arrays=AssignAdd -o - | FileCheck %s
2# RUN: tf-mlir-translate -graphdef-to-mlir -tf-enable-shape-inference-on-import=false %s -tf-prune-unused-nodes -tf-control-output-arrays=AssignAdd -o - | FileCheck --check-prefix=PRUNE %s
3# RUN: tf-mlir-translate -graphdef-to-mlir -tf-enable-shape-inference-on-import=false %s -tf-prune-unused-nodes -tf-control-output-arrays=Variable/Assign,AssignAdd -o - | FileCheck --check-prefix=PRESERVE %s
4
5# Generated in Python via
6# ```
7# import tensorflow as tf
8#
9# with tf.compat.v1.Graph().as_default() as g:
10#   var = tf.Variable(2.0)
11#   var_add = var.assign_add(3.0)
12# ```
13
14node {
15  name: "Variable/initial_value"
16  op: "Const"
17  attr {
18    key: "dtype"
19    value {
20      type: DT_FLOAT
21    }
22  }
23  attr {
24    key: "value"
25    value {
26      tensor {
27        dtype: DT_FLOAT
28        tensor_shape {
29        }
30        float_val: 2.0
31      }
32    }
33  }
34}
35node {
36  name: "Variable"
37  op: "VariableV2"
38  attr {
39    key: "container"
40    value {
41      s: ""
42    }
43  }
44  attr {
45    key: "dtype"
46    value {
47      type: DT_FLOAT
48    }
49  }
50  attr {
51    key: "shape"
52    value {
53      shape {
54      }
55    }
56  }
57  attr {
58    key: "shared_name"
59    value {
60      s: ""
61    }
62  }
63}
64node {
65  name: "Variable/Assign"
66  op: "Assign"
67  input: "Variable"
68  input: "Variable/initial_value"
69  attr {
70    key: "T"
71    value {
72      type: DT_FLOAT
73    }
74  }
75  attr {
76    key: "_class"
77    value {
78      list {
79        s: "loc:@Variable"
80      }
81    }
82  }
83  attr {
84    key: "use_locking"
85    value {
86      b: true
87    }
88  }
89  attr {
90    key: "validate_shape"
91    value {
92      b: true
93    }
94  }
95}
96node {
97  name: "Variable/read"
98  op: "Identity"
99  input: "Variable"
100  attr {
101    key: "T"
102    value {
103      type: DT_FLOAT
104    }
105  }
106  attr {
107    key: "_class"
108    value {
109      list {
110        s: "loc:@Variable"
111      }
112    }
113  }
114}
115node {
116  name: "AssignAdd/value"
117  op: "Const"
118  attr {
119    key: "dtype"
120    value {
121      type: DT_FLOAT
122    }
123  }
124  attr {
125    key: "value"
126    value {
127      tensor {
128        dtype: DT_FLOAT
129        tensor_shape {
130        }
131        float_val: 3.0
132      }
133    }
134  }
135}
136node {
137  name: "AssignAdd"
138  op: "AssignAdd"
139  input: "Variable"
140  input: "AssignAdd/value"
141  attr {
142    key: "T"
143    value {
144      type: DT_FLOAT
145    }
146  }
147  attr {
148    key: "_class"
149    value {
150      list {
151        s: "loc:@Variable"
152      }
153    }
154  }
155  attr {
156    key: "use_locking"
157    value {
158      b: false
159    }
160  }
161}
162versions {
163  producer: 309
164}
165
166# Tests single target node with no pruning set. All nodes will remain in the
167# graph and the target node is added to the graph fetch as a control.
168#
169# CHECK-LABEL: func @main
170# CHECK-SAME:  control_outputs = "AssignAdd"
171# CHECK-SAME:  inputs = ""
172# CHECK-SAME:  outputs = ""
173# CHECK:           %{{.*}}, %[[ASSIGN_ADD_CTRL:.*]] = tf_executor.island wraps "tf.AssignAdd"
174# CHECK:           tf_executor.fetch %[[ASSIGN_ADD_CTRL]]
175
176# Tests single target node with pruning set. Unreachable nodes from the fetch,
177# including side effecting nodes, will be removed. The target node is added to
178# the graph fetch as a control.
179#
180# PRUNE-LABEL: func @main
181# PRUNE-SAME:  control_outputs = "AssignAdd"
182# PRUNE-SAME:  inputs = ""
183# PRUNE-SAME:  outputs = ""
184# PRUNE-NOT:       "tf.Assign"
185# PRUNE-NOT:       "tf.Identity"
186# PRUNE-DAG:       %[[CONST:.*]], %{{.*}} = tf_executor.island wraps "tf.Const"
187# PRUNE-DAG:       %[[VAR:.*]], %{{.*}} = tf_executor.island wraps "tf.VariableV2"
188# PRUNE:           %{{.*}}, %[[ASSIGN_ADD_CTRL:.*]] = tf_executor.island wraps "tf.AssignAdd"(%[[VAR]], %[[CONST]])
189# PRUNE-NEXT:      tf_executor.fetch %[[ASSIGN_ADD_CTRL]]
190
191# Tests multiple target nodes with pruning set. Unreachable nodes from the
192# fetch, including side effecting nodes, will be removed. The target nodes are
193# added to the graph fetch as controls.
194#
195# PRESERVE-LABEL: func @main
196# PRESERVE-SAME:  control_outputs = "Variable/Assign,AssignAdd"
197# PRESERVE-SAME:  inputs = ""
198# PRESERVE-SAME:  outputs = ""
199# PRESERVE-NOT:       "tf.Identity"
200# PRESERVE:           %[[VAR:.*]], %{{.*}} = tf_executor.island wraps "tf.VariableV2"
201# PRESERVE-DAG:       %{{.*}}, %[[ASSIGN_CTRL:.*]] = tf_executor.island wraps "tf.Assign"
202# PRESERVE-DAG:       %{{.*}}, %[[ASSIGN_ADD_CTRL:.*]] = tf_executor.island wraps "tf.AssignAdd"
203# PRESERVE-NEXT:      tf_executor.fetch %[[ASSIGN_CTRL]], %[[ASSIGN_ADD_CTRL]]
204