Hanjun-Dai / graph_comb_opt

Implementation of "Learning Combinatorial Optimization Algorithms over Graphs"
https://arxiv.org/abs/1704.01665
MIT License
491 stars 135 forks source link

How to use the trained model #9

Open pg2455 opened 6 years ago

pg2455 commented 6 years ago

Great work! I have been trying to use the trained model. I figured that only a few of the arguments are needed to initialize MvcLib so I tried api = MvcLib(['test.py', '-dev_id', 0, '-mem_size', 5000, '-num_env', 10, '-max_n', 20, '-batch_size', 64, '-n_step', 5]) to initiate api. However, it seems to be throwing a Segmentation Fault.

On running the evaluation script - ./run_eval.sh, its throwing this error:

mem_size = 500000
num_env = 10
n_step = 5
min_n = 15
max_n = 20
max_iter = 100000
dev_id = 1
max_bp_iter = 5

batch_size = 64
embed_dim = 64
learning_rate = 0.0001
w_scale = 0.01
l2_penalty = 0
momentum = 0.9
terminate called after throwing an instance of 'thrust::system::system_error'
  what():  out of memory
./run_eval.sh: line 66: 86715 Aborted                 python2 evaluate.py -n_step $n_step -dev_id $dev_id -data_test $data_test -min_n $min_n -max_n $max_n -num_env $num_env -
max_iter $max_iter -mem_size $mem_size -g_type $g_type -learning_rate $learning_rate -max_bp_iter $max_bp_iter -net_type $net_type -max_iter $max_iter -save_dir $save_dir -emb
ed_dim $embed_dim -batch_size $batch_size -reg_hidden $reg_hidden -momentum 0.9 -l2 0.00 -w_scale $w_scale

I have followed the instructions to build graphnn and maxcut/ and mvc builds. My training scripts worked and created a results folder with model_name.model files in there. I want to load a model and use it for my problem. Is it possible to have a convinient way to use the models?

Hanjun-Dai commented 6 years ago

Hi there,

From the error message it seems you are getting 'out of memory'. I'm not sure whether that's the reason of segfault.

pg2455 commented 6 years ago

My bad! Those are two different error messages. I get Segmentation Fault when I run this

import os, sys
sys.path.append( '%s/mvc_lib' % os.path.dirname(os.path.realpath(__file__)) )
from mvc_lib import MvcLib
api = MvcLib(['test.py', '-dev_id', 0, '-mem_size', 5000, '-num_env', 10, '-max_n', 20, '-batch_size', 64, '-n_step', 5])

And I get Out of memory when I run ./run_eval.sh

Hanjun-Dai commented 5 years ago

Hello, sorry for the late reply -- I didn't see the 'test.py', which file are you working with?

Basically this function will load the model with best validation error: https://github.com/Hanjun-Dai/graph_comb_opt/blob/master/code/s2v_mvc/evaluate.py#L14

You can also directly supply the model dump you want, and load the mode using: https://github.com/Hanjun-Dai/graph_comb_opt/blob/master/code/s2v_mvc/evaluate.py#L45