75 metadata_values = np.array([ONE_START_MAGICNUM])
78 metadata_values = np.append(metadata_values, bcq_version)
81 output_cnt = output_arrays.count(
',') + 1
82 metadata_values = np.append(metadata_values, output_cnt)
84 return metadata_values
89 BCQv1 contains following metadata.
90 - The number of each BCQ information set
94 allowed_info_names = [
95 "bcqinfo_do_w_x",
"bcqinfo_alpha",
"bcqinfo_packed_binary_code",
96 "bcqinfo_number_of_clusters",
"bcqinfo_size_of_clusters",
97 "bcqinfo_qbits_of_clusters",
"bcqinfo_dequant_weight"
101 original_graph_def = original_graph.as_graph_def()
103 prefix_infonames_dict = {}
105 for node
in original_graph_def.node:
106 if node.op ==
"Const" and "/bcqinfo_" in node.name:
107 prefix_index = node.name.index(
"/bcqinfo_")
108 prefix = node.name[:prefix_index]
109 infoname = node.name[prefix_index + 1:]
111 if infoname
not in allowed_info_names:
115 if prefix
not in prefix_infonames_dict:
116 prefix_infonames_dict[prefix] = set()
118 prefix_infonames_dict[prefix].add(infoname)
122 for key
in prefix_infonames_dict:
123 infonames = prefix_infonames_dict[key]
124 if num_of_bcqinfo == -1:
125 num_of_bcqinfo = len(infonames)
126 elif num_of_bcqinfo != len(infonames):
130 if num_of_bcqinfo != 6
and num_of_bcqinfo != 7:
134 if is_valid ==
False:
135 return original_graph_def
137 new_graph_def = tf.compat.v1.GraphDef()
138 for node
in original_graph_def.node:
139 new_node = new_graph_def.node.add()
140 new_node.CopyFrom(node)
146 metadata_values = np.append(metadata_values, num_of_bcqinfo + 1)
149 metadata_values = np.append(metadata_values, ONE_END_MAGICNUM)
152 metadata_tensor = tf.make_tensor_proto(metadata_values, tf.int32)
154 new_node = new_graph_def.node.add()
155 new_node.op =
"Const"
156 new_node.name =
"one_compiler/bcqinfo_one_metadata"
157 new_node.attr[
"dtype"].CopyFrom(
158 tf.compat.v1.AttrValue(type=tf.int32.as_datatype_enum))
159 new_node.attr[
"value"].tensor.CopyFrom(metadata_tensor)