def test_save_n_load_model_parameters(self): model_parameters = {"Wh": np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), "bh": np.array([1, 1, 1, 1]), "Wo": np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), "bo": np.array([0, 0, 0, 0]), "model_meta": {"learning_rate": 0.01, "input_dim": 100, "hidden_dim": 64} } model_table_name = "table_name_" + str(uuid.uuid1()) model_table_ns = "table_ns_" + str(uuid.uuid1()) save_model_parameters(model_parameters, model_table_name, model_table_ns) actual_model_parameters = load_model_parameters(model_table_name, model_table_ns) assert len(model_parameters) == len(actual_model_parameters) for k in actual_model_parameters.keys(): if k == "model_meta": print(actual_model_parameters[k]) else: assert_matrix(actual_model_parameters[k], model_parameters[k])
def save_model(self, model_table_name, model_namespace): LOGGER.info("@ save guest model to name/ns" + ", " + str(model_table_name) + ", " + str(model_namespace)) lr_model_name = model_table_name + "_lr_model" local_model_name = model_table_name + "_local_model" super(HeteroDNNLRHost, self).save_model(lr_model_name, model_namespace) save_model_parameters(self.local_model.get_model_parameters(), local_model_name, model_namespace)
def save_model(self, model_table_name, model_namespace): LOGGER.info("@ save host model to name/ns" + ", " + str(model_table_name) + ", " + str(model_namespace)) _ = save_model_parameters(self.host_model.get_model_parameters(), model_table_name, model_namespace)