def test_delete_model(self, mocker): mock_method = mocker.patch.object(MlflowClient, "delete_model_version") client = ModelsClient() name = "simple-nn-model" client.delete_model(name, '1') mock_method.assert_called_once_with(name="simple-nn-model", version="1")
def test_log_model(self, mocker): mock_method = mocker.patch.object(ModelsClient, "log_model") client = ModelsClient() model = LinearNNModel() name = "simple-nn-model" client.log_model(name, model) mock_method.assert_called_once_with("simple-nn-model", model)
def test_save_model(self, mocker): mock_method = mocker.patch.object(ModelsClient, "save_model") client = ModelsClient() model = LinearNNModel() name = "simple-nn-model" client.save_model("pytorch", model, name) mock_method.assert_called_once_with("pytorch", model, "simple-nn-model")
def test_update_model(self, mocker): mock_method = mocker.patch.object(MlflowClient, "rename_registered_model") client = ModelsClient() name = "simple-nn-model" new_name = "new-simple-nn-model" client.update_model(name, new_name) mock_method.assert_called_once_with(name="simple-nn-model", new_name="new-simple-nn-model")
def test_load_model(self): client = ModelsClient() name = "simple-nn-model" version = "1" model = client.load_model(name, version) x = np.float32([[1.0], [2.0]]) y = model.predict(x) assert y.shape[0] == 2 assert y.shape[1] == 1
def test_load_model(self, mocker): mock_method = mocker.patch.object(mlflow.pyfunc, "load_model") mock_method.return_value = mlflow.pytorch._PyTorchWrapper( LinearNNModel()) client = ModelsClient() name = "simple-nn-model" version = "1" model = client.load_model(name, version) mock_method.assert_called_once_with( model_uri="models:/simple-nn-model/1") x = np.float32([[1.0], [2.0]]) y = model.predict(x) assert y.shape[0] == 2 assert y.shape[1] == 1
""" Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from submarine import ModelsClient import random import time if __name__ == "__main__": modelClient = ModelsClient() with modelClient.start() as run: modelClient.log_param("learning_rate", random.random()) for i in range(100): time.sleep(1) modelClient.log_metric("mse", random.random() * 100, i) modelClient.log_metric("acc", random.random(), i)
"License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from submarine import ModelsClient import numpy as np import torch from submarine import ModelsClient class LinearNNModel(torch.nn.Module): def __init__(self): super(LinearNNModel, self).__init__() self.linear = torch.nn.Linear(2, 1) # One in and one out def forward(self, x): y_pred = self.linear(x) return y_pred if __name__ == "__main__": client = ModelsClient() net = LinearNNModel() client.log_model("simple-nn-model", net)
def models_client_fixture(): client = ModelsClient("http://localhost:5001", "http://localhost:9000") return client
BATCH_SIZE = BATCH_SIZE_PER_REPLICA * strategy.num_replicas_in_sync with strategy.scope(): ds_train = make_datasets_unbatched().batch(BATCH_SIZE).repeat() options = tf.data.Options() options.experimental_distribute.auto_shard_policy = \ tf.data.experimental.AutoShardPolicy.DATA ds_train = ds_train.with_options(options) # Model building/compiling need to be within `strategy.scope()`. multi_worker_model = build_and_compile_cnn_model() class MyCallback(tf.keras.callbacks.Callback): def on_epoch_end(self, epoch, logs=None): # monitor the loss and accuracy print(logs) modelClient.log_metrics( { "loss": logs["loss"], "accuracy": logs["accuracy"] }, epoch) with modelClient.start() as run: multi_worker_model.fit(ds_train, epochs=10, steps_per_epoch=70, callbacks=[MyCallback()]) if __name__ == '__main__': modelClient = ModelsClient() main()
def test_delete_model(self): client = ModelsClient() name = "simple-nn-model" client.delete_model(name, '1')
def test_update_model(self): client = ModelsClient() name = "simple-nn-model" new_name = "new-simple-nn-model" client.update_model(name, new_name)
def test_log_model(self): client = ModelsClient() model = LinearNNModel() name = "simple-nn-model" client.log_model(name, model)
""" Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from submarine import ModelsClient import random import time if __name__ == "__main__": periscope = ModelsClient() with periscope.start() as run: periscope.log_param("learning_rate", random.random()) for i in range(100): time.sleep(1) periscope.log_metric("mse", random.random() * 100, i) periscope.log_metric("acc", random.random(), i)