def test_basic_rpc(self): channel_addr = "127.0.0.1:50052" xgb.init_client(user_name=username, sym_key_file=sym_key_file, priv_key_file=priv_key_file, cert_file=cert_file, remote_addr=channel_addr) xgb.attest(verify=False) dtrain = xgb.DMatrix({username: dpath + 'agaricus.txt.train.enc'}) dtest = xgb.DMatrix({username: dpath + 'agaricus.txt.test.enc'}) # Set training parameters params = { "tree_method": "hist", "n_gpus": "0", "objective": "binary:logistic", "min_child_weight": "1", "gamma": "0.1", "max_depth": "5", "verbosity": "0" } num_rounds = 2 booster = xgb.train(params, dtrain, num_rounds) predictions, num_preds = booster.predict(dtest, decrypt=False) preds = booster.decrypt_predictions(predictions, num_preds) ten_preds = preds[:10] labels = [0, 1, 0, 0, 0, 0, 1, 0, 1, 0] err = sum(1 for i in range(len(ten_preds)) if int(ten_preds[i] > 0.5) != labels[i]) / float(len(ten_preds)) # error must be smaller than 10% assert err < 0.1
def run(channel_addr, sym_key_file, priv_key_file, cert_file): xgb.init_client(user_name=username, client_list=["user1", username], sym_key_file=sym_key_file, priv_key_file=priv_key_file, cert_file=cert_file, remote_addr=channel_addr) xgb.rabit.init() # Remote attestation print("Remote attestation") # Note: Simulation mode does not support attestation # pass in `verify=False` to attest() xgb.attest() print("Report successfully verified") print("Load training matrices") dtrain = xgb.DMatrix({"user1": HOME_DIR + "demo/python/multiclient-cluster-remote-control/data/c1_train.enc", username: HOME_DIR + "demo/python/multiclient-cluster-remote-control/data/c2_train.enc"}, encrypted=True) print("Creating test matrix") dtest1 = xgb.DMatrix({"user1": HOME_DIR + "demo/python/multiclient-cluster-remote-control/data/c1_test.enc"}) dtest2 = xgb.DMatrix({username: HOME_DIR + "demo/python/multiclient-cluster-remote-control/data/c2_test.enc"}) print("Beginning Training") # Set training parameters params = { "tree_method": "hist", "n_gpus": "0", "objective": "binary:logistic", "min_child_weight": "1", "gamma": "0.1", "max_depth": "3", "verbosity": "0" } # Train and evaluate num_rounds = 10 print("Training...") booster = xgb.train(params, dtrain, num_rounds) # Enable the other party to get its predictions _, _ = booster.predict(dtest1, decrypt=False) # Get our predictions predictions, num_preds = booster.predict(dtest2, decrypt=False) # Decrypt predictions print("Predictions: ", booster.decrypt_predictions(predictions, num_preds)[:10]) # Get fscores of model print("\nModel Feature Importance: ") print(booster.get_fscore()) xgb.rabit.finalize()
"DMLC_NUM_SERVER": os.environ.get("DMLC_NUM_SERVER"), "DMLC_TRACKER_URI": os.environ.get("DMLC_TRACKER_URI"), "DMLC_TRACKER_PORT": os.environ.get("DMLC_TRACKER_PORT"), "DMLC_ROLE": os.environ.get("DMLC_ROLE"), "DMLC_NODE_HOST": os.environ.get("DMLC_NODE_HOST") } rargs = [str.encode(str(k) + "=" + str(v)) for k, v in rabit_args.items()] xgb.rabit.init(rargs) # Remote Attestation print("Remote attestation") # Note: Simulation mode does not support attestation # pass in `verify=False` to attest() xgb.attest() print("Creating training matrix from encrypted file") dtrain = xgb.DMatrix({username: HOME_DIR + "demo/data/agaricus.txt.train.enc"}) print("Creating test matrix from encrypted file") dtest = xgb.DMatrix({username: HOME_DIR + "demo/data/agaricus.txt.test.enc"}) print("Beginning Training") # Set training parameters params = { "tree_method": "hist", "n_gpus": "0", "objective": "binary:logistic", "min_child_weight": "1",
import os import securexgboost as xgb username = "******" HOME_DIR = os.path.dirname(os.path.realpath(__file__)) + "/../../" sym_key_file = HOME_DIR + "demo/data/key_zeros.txt" priv_key_file = HOME_DIR + "config/user1.pem" cert_file = HOME_DIR + "config/user1.crt" xgb.init_client(user_name=username, sym_key_file=sym_key_file, priv_key_file=priv_key_file, cert_file=cert_file) xgb.init_server(enclave_image=HOME_DIR + "build/enclave/xgboost_enclave.signed") xgb.attest(verify=False)
def run(channel_addr, sym_key_file, priv_key_file, cert_file): # Remote attestation print("Remote attestation") xgb.init_client(user_name=username, sym_key_file=sym_key_file, priv_key_file=priv_key_file, cert_file=cert_file, remote_addr=channel_addr) # Note: Simulation mode does not support attestation # pass in `verify=False` to attest() xgb.attest() print("Report successfully verified") print("Creating training matrix") dtrain = xgb.DMatrix( {username: HOME_DIR + "demo/python/remote-control/data/train.enc"}) if not dtrain: print("Error creating dtrain") return print("dtrain: " + dtrain.handle.value.decode("utf-8")) print("Creating test matrix") dtest = xgb.DMatrix( {username: HOME_DIR + "demo/python/remote-control/data/test.enc"}) if not dtest: print("Error creating dtest") return print("dtest: " + dtest.handle.value.decode("utf-8")) print("Beginning Training") # Set training parameters params = { "tree_method": "hist", "n_gpus": "0", "objective": "binary:logistic", "min_child_weight": "1", "gamma": "0.1", "max_depth": "3", "verbosity": "0" } # Train and evaluate num_rounds = 5 print("Training...") booster = xgb.train(params, dtrain, num_rounds) print("booster: " + booster.handle.value.decode("utf-8")) booster.save_model(HOME_DIR + "demo/python/remote-control/client/modelfile.model") # Get encrypted predictions print("\nModel Predictions: ") predictions, num_preds = booster.predict(dtest, decrypt=False) # Decrypt predictions print(booster.decrypt_predictions(predictions, num_preds)) # Get fscores of model print("\nModel Feature Importance: ") print(booster.get_fscore())