| 131 | using TensorProtoHasher = std::function<uint64(const TensorProto&)>; |
| 132 | |
| 133 | uint64 AttrValueHash(const AttrValue& a, const TensorProtoHasher& tensor_hash) { |
| 134 | if (a.has_tensor()) return tensor_hash(a.tensor()); |
| 135 | |
| 136 | if (a.has_func()) { |
| 137 | const NameAttrList& func = a.func(); |
| 138 | uint64 h = Hash64(func.name()); |
| 139 | std::map<string, AttrValue> map(func.attr().begin(), func.attr().end()); |
| 140 | for (const auto& pair : map) { |
| 141 | h = Hash64(pair.first.data(), pair.first.size(), h); |
| 142 | h = Hash64Combine(AttrValueHash(pair.second, tensor_hash), h); |
| 143 | } |
| 144 | return h; |
| 145 | } |
| 146 | |
| 147 | // If `a` is not a tensor or func, get a hash of serialized string. |
| 148 | return DeterministicProtoHash64(a); |
| 149 | } |
| 150 | |
| 151 | template <typename TensorProtosEquality> |
| 152 | bool AreAttrValuesEqual(const AttrValue& a, const AttrValue& b, |