Browse Source

fix nas on clf, rename example

tags/v0.3.1
Frozenmad 4 years ago
parent
commit
b27c5e4590
4 changed files with 62 additions and 42 deletions
  1. +2
    -2
      autogl/solver/classifier/node_classifier.py
  2. +40
    -0
      configs/nodeclf_nas_benchmark.yml
  3. +20
    -0
      examples/graphnas.py
  4. +0
    -40
      examples/test_nas.py

+ 2
- 2
autogl/solver/classifier/node_classifier.py View File

@@ -826,9 +826,9 @@ class AutoNodeClassifier(BaseClassifier):
configs = nas_dict[k]
if isinstance(configs, list):
for item in configs:
container.append(indexer[item.pop('name')](**item, init=False))
container.append(indexer[item.pop('name')](**item))
else:
container.append(indexer[configs.pop('name')](**configs, init=False))
container.append(indexer[configs.pop('name')](**configs))
solver.set_nas_module(algorithms, spaces, estimators)



+ 40
- 0
configs/nodeclf_nas_benchmark.yml View File

@@ -0,0 +1,40 @@
ensemble:
name: null
feature:
- name: PYGNormalizeFeatures
hpo:
max_evals: 10
name: random
nas:
space:
name: graphnas
hidden_dim: 64
layer_number: 4
algorithm:
name: rl
num_epochs: 200
estimator:
name: scratch
models: []
trainer:
hp_space:
- maxValue: 300
minValue: 100
parameterName: max_epoch
scalingType: LINEAR
type: INTEGER
- maxValue: 30
minValue: 10
parameterName: early_stopping_round
scalingType: LINEAR
type: INTEGER
- maxValue: 0.05
minValue: 0.01
parameterName: lr
scalingType: LOG
type: DOUBLE
- maxValue: 0.0005
minValue: 5.0e-05
parameterName: weight_decay
scalingType: LOG
type: DOUBLE

+ 20
- 0
examples/graphnas.py View File

@@ -0,0 +1,20 @@
import sys
sys.path.append('../')
from autogl.datasets import build_dataset_from_name
from autogl.solver import AutoNodeClassifier
from autogl.module.train import Acc
import argparse

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--config', type=str, default='../configs/nodeclf_nas_benchmark.yml')
parser.add_argument('--dataset', choices=['cora', 'citeseer', 'pubmed'], default='cora', type=str)

args = parser.parse_args()

dataset = build_dataset_from_name('cora')
solver = AutoNodeClassifier.from_config(args.config)
solver.fit(dataset)
solver.get_leaderboard().show()
out = solver.predict_proba()
print('acc on cora', Acc.evaluate(out, dataset[0].y[dataset[0].test_mask].detach().numpy()))

+ 0
- 40
examples/test_nas.py View File

@@ -1,40 +0,0 @@
import sys
sys.path.append('../')
from torch_geometric.nn import GCNConv
import torch
from autogl.datasets import build_dataset_from_name
from autogl.solver import AutoNodeClassifier
from autogl.module.train import NodeClassificationFullTrainer
from autogl.module.nas import Darts, OneShotEstimator, SinglePathNodeClassificationSpace
from autogl.module.nas.space.graph_nas import GraphNasNodeClassificationSpace
from autogl.module.train import Acc
from autogl.module.nas.algorithm.enas import Enas

if __name__ == '__main__':
dataset = build_dataset_from_name('cora')
solver = AutoNodeClassifier(
feature_module='PYGNormalizeFeatures',
graph_models=[],
hpo_module=None,
ensemble_module=None,
default_trainer=NodeClassificationFullTrainer(
optimizer=torch.optim.Adam,
lr=0.01,
max_epoch=300,
early_stopping_round=300,
weight_decay=1e-4,
device="auto",
init=False,
feval=['acc'],
loss="nll_loss",
lr_scheduler_type=None,),
#nas_algorithms=[Enas()],
nas_algorithms=[Darts(num_epochs=200)],
#nas_spaces=[SinglePathNodeClassificationSpace(hidden_dim=32, ops=[GCNConv, GCNConv])],
nas_spaces=[GraphNasNodeClassificationSpace(hidden_dim=64,search_act_con=False,layer_number=4)],
nas_estimators=[OneShotEstimator()]
)
solver.fit(dataset)
solver.get_leaderboard().show()
out = solver.predict_proba()
print('acc on cora', Acc.evaluate(out, dataset[0].y[dataset[0].test_mask].detach().numpy()))

Loading…
Cancel
Save