| 1848 | } |
| 1849 | |
| 1850 | Status SavedModelOptimizer::ConvertToHashImportOp( |
| 1851 | Node* node, std::vector<SrcInfo>& input_info) { |
| 1852 | std::unordered_map<std::string, std::string> attr_info_map; |
| 1853 | int edge_count = node->num_inputs(); |
| 1854 | |
| 1855 | // KvResourceImportV2 -> LookupTableImportV2 |
| 1856 | AttrValue* key_attr = nullptr; |
| 1857 | Status s_attr = GetNodeAttr(node, "Tkeys", &key_attr); |
| 1858 | TF_RETURN_IF_ERROR(s_attr); |
| 1859 | |
| 1860 | AttrValue* dtype_attr = nullptr; |
| 1861 | s_attr = GetNodeAttr(node, "dtype", &dtype_attr); |
| 1862 | TF_RETURN_IF_ERROR(s_attr); |
| 1863 | |
| 1864 | // create restore_op to restore values and keys |
| 1865 | // create const "tensor_names-keys" and "tensor_names-values" op |
| 1866 | Node* empty_shape_and_slices_node = nullptr; |
| 1867 | Status s_add_node = Create1DStringConstOp( |
| 1868 | node->name() + "/const/shape_and_slices", DT_STRING, |
| 1869 | "", &graph_, &empty_shape_and_slices_node); |
| 1870 | TF_RETURN_IF_ERROR(s_add_node); |
| 1871 | |
| 1872 | AttrValue* prefix_attr = nullptr; |
| 1873 | s_attr = GetNodeAttr(input_info[3].src_node, "value", &prefix_attr); |
| 1874 | TF_RETURN_IF_ERROR(s_attr); |
| 1875 | Tensor prefix_tensor; |
| 1876 | bool success = prefix_tensor.FromProto(prefix_attr->tensor()); |
| 1877 | if (!success) { |
| 1878 | return errors::Internal("Can not parse prefix_attr->tensor()" |
| 1879 | "to prefix_tensor"); |
| 1880 | } |
| 1881 | |
| 1882 | std::string prefix = prefix_tensor.scalar<string>()(); |
| 1883 | |
| 1884 | Node* tensor_names_key_node = nullptr; |
| 1885 | s_add_node = Create1DStringConstOp( |
| 1886 | node->name() + "/const/keys", DT_STRING, |
| 1887 | prefix + "-keys", |
| 1888 | &graph_, &tensor_names_key_node); |
| 1889 | TF_RETURN_IF_ERROR(s_add_node); |
| 1890 | |
| 1891 | Node* tensor_names_value_node = nullptr; |
| 1892 | s_add_node = Create1DStringConstOp( |
| 1893 | node->name() + "/const/values", DT_STRING, |
| 1894 | prefix + "-values", |
| 1895 | &graph_, &tensor_names_value_node); |
| 1896 | TF_RETURN_IF_ERROR(s_add_node); |
| 1897 | |
| 1898 | // 1) create keys restore_op |
| 1899 | std::vector<SrcInfo> restore_input_info; |
| 1900 | restore_input_info.push_back(input_info[0]); |
| 1901 | restore_input_info.push_back(SrcInfo{tensor_names_key_node, 0}); |
| 1902 | restore_input_info.push_back(SrcInfo{empty_shape_and_slices_node, 0}); |
| 1903 | std::vector<DataType> key_types; |
| 1904 | key_types.push_back(key_attr->type()); |
| 1905 | |
| 1906 | Node* restore_key_node = nullptr; |
| 1907 | s_add_node = CreateRestoreOp(node->name() + "/keys/restore", |
nothing calls this directly
no test coverage detected