def test_log_param(self): submarine.log_param("name_1", "a") # Validate params with self.store.ManagedSessionMaker() as session: params = session.query(SqlParam).options().filter( SqlParam.id == JOB_ID).all() assert params[0].key == "name_1" assert params[0].value == "a" assert params[0].id == JOB_ID
def log_param(self): submarine.log_param("name_1", "a", "worker-1") # Validate params with self.store.ManagedSessionMaker() as session: params = session \ .query(SqlParam) \ .options() \ .filter(SqlParam.job_name == JOB_NAME).all() assert params[0].key == "name_1" assert params[0].value == "a" assert params[0].worker_index == "worker-1" assert params[0].job_name == JOB_NAME
def test_log_param(tracking_uri_mock): environ["SUBMARINE_JOB_NAME"] = JOB_NAME submarine.log_param("name_1", "a", "worker-1") tracking_uri = utils.get_tracking_uri() store = utils.get_sqlalchemy_store(tracking_uri) # Validate params with store.ManagedSessionMaker() as session: params = session \ .query(SqlParam) \ .options() \ .filter(SqlParam.job_name == JOB_NAME).all() assert params[0].key == "name_1" assert params[0].value == "a" assert params[0].worker_index == "worker-1" assert params[0].job_name == JOB_NAME
# 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. import numpy as np from os import environ from sklearn.linear_model import LogisticRegression import submarine if __name__ == "__main__": # note: SUBMARINE_JOB_NAME should be set by submarine submitter environ["SUBMARINE_JOB_NAME"] = "application_1234" X = np.array([-2, -1, 0, 1, 2, 1]).reshape(-1, 1) y = np.array([0, 0, 1, 1, 1, 0]) lr = LogisticRegression(solver='liblinear', max_iter=100) submarine.log_param("max_iter", 100, "worker-1") lr.fit(X, y) score = lr.score(X, y) print("Score: %s" % score) submarine.log_metric("score", score, "worker-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. """ import random import time import submarine if __name__ == "__main__": submarine.log_param("learning_rate", random.random()) for i in range(100): time.sleep(1) submarine.log_metric("mse", random.random() * 100, i) submarine.log_metric("acc", random.random(), i)
# 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. import numpy as np from sklearn.linear_model import LogisticRegression import submarine if __name__ == "__main__": X = np.array([-2, -1, 0, 1, 2, 1]).reshape(-1, 1) y = np.array([0, 0, 1, 1, 1, 0]) lr = LogisticRegression(solver="liblinear", max_iter=100) submarine.log_param("max_iter", 100) lr.fit(X, y) score = lr.score(X, y) print("Score: %s" % score) submarine.log_metric("score", score)
def on_epoch_end(self, epoch, logs=None): print("\nLearning rate for epoch {} is {}".format( epoch + 1, model.optimizer.lr.numpy())) submarine.log_metric("lr", model.optimizer.lr.numpy()) submarine.save_model(model, "tensorflow", "mnist-tf") # Put all the callbacks together. callbacks = [ tf.keras.callbacks.TensorBoard(log_dir="./logs"), tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_prefix, save_weights_only=True), tf.keras.callbacks.LearningRateScheduler(decay), PrintLR(), ] if __name__ == "__main__": EPOCHS = 2 hist = model.fit(train_dataset, epochs=EPOCHS, callbacks=callbacks) for i in range(EPOCHS): submarine.log_metric("val_loss", hist.history["loss"][i], i) submarine.log_metric("Val_accuracy", hist.history["accuracy"][i], i) model.load_weights(tf.train.latest_checkpoint(checkpoint_dir)) eval_loss, eval_acc = model.evaluate(eval_dataset) print("Eval loss: {}, Eval accuracy: {}".format(eval_loss, eval_acc)) submarine.log_param("loss", eval_loss) submarine.log_param("acc", eval_acc) """Reference: https://www.tensorflow.org/api_docs/python/tf/distribute/MirroredStrategy """
transform=transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.1307, ), (0.3081, )) ]), ), batch_size=args.test_batch_size, shuffle=False, **kwargs) model = Net().to(device) if is_distributed(): Distributor = (nn.parallel.DistributedDataParallel if use_cuda else nn.parallel.DistributedDataParallelCPU) model = Distributor(model) optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=args.momentum) submarine.log_param("learning_rate", args.lr) submarine.log_param("batch_size", args.batch_size) for epoch in range(1, args.epochs + 1): train(args, model, device, train_loader, optimizer, epoch, writer) test(args, model, device, test_loader, writer, epoch) if args.save_model: torch.save(model.state_dict(), "mnist_cnn.pt") """ Reference: https://github.com/kubeflow/pytorch-operator/blob/master/examples/mnist/mnist.py """
#experiment = Experiment(api_key="ej6XeyCVjqHM8uLDNj5VGrzjP", # project_name="testing", workspace="pingsutw") if __name__ == "__main__": submarine.set_tracking_uri( "mysql+pymysql://submarine:password@submarine-database/submarine") print("TF_CONFIG", env.get_env("TF_CONFIG")) print("JOB_NAME: ", env.get_env("JOB_NAME")) print("TYPE: ", env.get_env("TPYE")) print("TASK_INDEX: ", env.get_env("TASK_INDEX")) print("CLUSTER_SPEC: ", env.get_env("CLUSTER_SPEC")) print("RANK: ", env.get_env("RANK")) submarine.log_param("max_iter", 100) submarine.log_param("learning_rate", 0.0001) submarine.log_param("alpha", 20) submarine.log_param("batch_size", 256) submarine.log_metric("score", 2) submarine.log_metric("score", 5) submarine.log_metric("score", 8) submarine.log_metric("score", 5) submarine.log_metric("score", 10) submarine.log_metric("AUC", 0.62) submarine.log_metric("AUC", 0.68) submarine.log_metric("AUC", 0.75) submarine.log_metric("AUC", 0.64) submarine.log_metric("AUC", 0.79)