max_epoch=100, early_stopping_round=101, weight_decay=0.0, device="auto", init=False, feval=[Auc], loss="binary_cross_entropy_with_logits", ).duplicate_from_hyper_parameter( { "trainer": {}, "encoder": model_hp, "decoder": decoder_hp }, restricted=False) gs = list(split_edges(dataset, 0.8, 0.1)[0]) if args.model == 'gcn' or args.model == 'gat': gs[0] = dgl.add_self_loop(gs[0]) dataset_splitted = { 'train': gs[0].to(args.device), 'train_pos': gs[1].to(args.device), 'train_neg': gs[2].to(args.device), 'val_pos': gs[3].to(args.device), 'val_neg': gs[4].to(args.device), 'test_pos': gs[5].to(args.device), 'test_neg': gs[6].to(args.device), } trainer.train([dataset_splitted], False)
args = parser.parse_args() if args.device < 0: device = args.device = "cpu" else: device = args.device = f"cuda:{args.device}" dataset = build_dataset_from_name(args.dataset.lower()) dataset = NormalizeFeatures().fit_transform(dataset) res = [] begin_time = time.time() for seed in tqdm(range(1234, 1234+args.repeat)): set_seed(seed) data = split_edges(dataset, 0.85, 0.05)[0] model_hp, decoder_hp = get_encoder_decoder_hp(args.model) trainer = LinkPredictionTrainer( model = args.model, num_features = data.x.size(1), lr = 1e-2, max_epoch = 100, early_stopping_round = 101, weight_decay = 0.0, device = args.device, feval = [Auc], loss = "binary_cross_entropy_with_logits", init = False ).duplicate_from_hyper_parameter(
if torch.cuda.is_available(): torch.cuda.set_device(args.device) seed = args.seed # set random seed random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed(seed) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False dataset = build_dataset_from_name(args.dataset) # split the edges for dataset dataset = split_edges(dataset, 0.8, 0.05) # add self-loop if DependentBackend.is_dgl(): import dgl # add self loop to 0 data = list(dataset[0]) data[0] = dgl.add_self_loop(data[0]) dataset = [data] configs = yaml.load(open(args.configs, "r").read(), Loader=yaml.FullLoader) configs["hpo"]["name"] = args.hpo configs["hpo"]["max_evals"] = args.max_eval autoClassifier = AutoLinkPredictor.from_config(configs) # train
val_pos_g = dgl.graph((val_pos_u, val_pos_v), num_nodes=g.number_of_nodes()) val_neg_g = dgl.graph((val_neg_u, val_neg_v), num_nodes=g.number_of_nodes()) test_pos_g = dgl.graph((test_pos_u, test_pos_v), num_nodes=g.number_of_nodes()) test_neg_g = dgl.graph((test_neg_u, test_neg_v), num_nodes=g.number_of_nodes()) return train_g, train_pos_g, train_neg_g, val_pos_g, val_neg_g, test_pos_g, test_neg_g def split_edges(dataset, train, val): for i in range(len(dataset)): dataset[i] = split_train_test(dataset[i], train, val) return dataset from autogl.datasets.utils import split_edges cora = build_dataset_from_name("cora") cora = convert_dataset(cora) cora = split_edges(cora, 0.8, 0.05) solver = AutoLinkPredictor( graph_models=("gin", "gat", "gcn"), hpo_module=None, device="auto" ) solver.fit(cora, evaluation_method=["acc"]) solver.leaderboard.show() result = solver.predict(cora) print(result)