Giter VIP home page Giter VIP logo

neural-rewriter's Introduction

Neural Rewriter

This repo provides the code to replicate the experiments in the paper

Xinyun Chen, Yuandong Tian, Learning to Perform Local Rewriting for Combinatorial Optimization, in NeurIPS 2019.

Paper [arXiv]

Prerequisites

PyTorch

Tasks

Expression Simplification

For expression simplification, given an initial expression (in Halide for our evaluation), the goal is to find an equivalent expression that is simplified, e.g., with a shorter length.

Performance

Expression Simplification

We compare our approach (NeuRewriter) with the following baselines:

  • Z3-simplify [1]: the tactic implemented in Z3, which performs rule-based rewriting.
  • Halide-rule [2]: the Halide rule-based rewriter.
  • Heuristic search: beam search to find the shortest rewritten expression using the Halide rule set.
  • Z3-ctx-solver-simplify [1]: the tactic implemented in Z3, which invokes a solver to find the simplified equivalent expression.

In the figure, Average expression length reduction is the decrease of the length defined as the number of characters in the expression, and Average tree size reduction is the number of nodes decreased from the initial expression parse tree to the rewritten one.

Dataset

We generate expressions in Halide using a random pipeline generator. We obtain rewriting traces using the Halide rule-based rewriter here.

Usage

The code includes the implementation of following approaches:

  • Neural Rewriter (Ours): run run_Halide.py.
  • Search: run Halide_search.py.

Job Scheduling

For job scheduling, we have a machine with D types of resources, and a queue that can hold at most W=10 pending jobs. Each job arrives in an online fashion, with a fixed resource demand and the duration. The goal is to minimize the average slowdown (Cj - Aj) / Tj, where Cj is the completion time of job j, Aj is the arrival time, and Tj is the job duration.

Performance

Job Scheduling

We compare our approach (NeuRewriter) with the following baselines:

  • EJF: earliest job first, schedules each job in the increasing order of their arrival time.
  • SJF: shortest job first, schedules the shortest job in the pending job queue.
  • SJFS: shortest job first search, searches over the shortest jobs to schedule, then returns the optimal one.
  • OR-tools [3]: a generic toolbox for combinatorial optimization.
  • DeepRM [4]: a reinforcement learning policy to construct the schedule from scratch.
  • SJF-offline: applies the shortest job first heuristic, and assumes an unbounded length of the job queue.

In the figure, D denotes the number of resource types.

Dataset

The dataset generator can be found under this folder.

Usage

The code includes the implementation of following approaches:

  • Neural Rewriter (Ours): run run_jsp.py.
  • Baseline algorithms: run jsp_nonNN_baselines.py, set --alg from [SJF, EJF, random].

Vehicle Routing

For vehicle routing, we have a single vehicle with limited capacity to satisfy the resource demands of a set of customer nodes. To do so, we need to construct multiple routes starting and ending at the depot, so that the resources delivered in each route do not exceed the vehicle capacity, while the total route length is minimized.

Performance

Vehicle Routing

We compare our approach (NeuRewriter) with the following baselines:

  • Random Sweep [5]: a classic heuristic for vehicle routing.
  • Random CW [6]: Clarke-Wright savings heuristic for vehicle routing.
  • OR-tools [3]: a generic toolbox for combinatorial optimization.
  • Nazari et al. [7]: a reinforcement learning policy to construct the route from scratch.
  • AM [8]: a reinforcement learning policy to construct the route from scratch.

In the figure, VRP X, CAP Y means that the number of customer nodes is X, and the vehicle capacity is Y.

Dataset

The dataset generator can be found under this folder.

Usage

Run run_vrp.py.

Run experiments

In the following we list some important arguments for experiments using neural network models:

  • --train_dataset, --val_dataset, --test_dataset: path to the training/validation/test datasets respectively.
  • --model_dir: path to the directory that stores the models.
  • --log_name: name of the log file.
  • --load_model: path to the pretrained model (optional).
  • --eval: adding this command will enable the evaluation mode; otherwise, the model will be trained by default.
  • --num_epochs: number of training epochs. The default value is 10, but usually 1 epoch is enough for a decent performance.
  • --eval_every_n EVAL_EVERY_N: evaluating the model and saving checkpoints every EVAL_EVERY_N steps.
  • --max_eval_size MAX_EVAL_SIZE: when the value is not None, when performing the validation during training, the model only evaluates the first MAX_EVAL_SIZE samples in the validation set. Setting it to a small value if the validation process takes long.

More details can be found in arguments.py.

Citation

If you use the code in this repo, please cite the following paper:

@inproceedings{chen2019learning,
  title={Learning to Perform Local Rewriting for Combinatorial Optimization},
  author={Chen, Xinyun and Tian, Yuandong},
  booktitle={Advances in Neural Information Processing Systems},
  year={2019}
}

License

This repo is CC-BY-NC licensed, as found in the LICENSE file.

References

[1] Z3

[2] Halide

[3] OR-tools

[4] Mao et al. Resource Management with Deep Reinforcement Learning. ACM HotNets 2016

[5] Wren and Holliday. Computer scheduling of vehicles from one or more depots to a number of delivery points. Operational Research Quarterly, 1972.

[6] Clarke and Wright. Scheduling of vehicles from a central depot to a number of delivery points. Operations research, 1964.

[7] Nazari et al. Reinforcement Learning for Solving the Vehicle Routing Problem. NeurIPS 2018.

[8] Kool et al. Attention, Learn to Solve Routing Problems! ICLR 2019.

neural-rewriter's People

Contributors

lucasbotang avatar yuandong-tian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neural-rewriter's Issues

I have some trouble to reproduce result

Hi authors,

I am trying to train for the JSP task with the default hyperparameters in code (64 batch size and 5e-5 learning rate), hyperparameters in your paper (128 batch size and 1e-4 learning rate) and other settings. After one epoch and more, I am afraid the loss and reward of my training are not converged. Since the training for one epoch takes a long time in my workstation, it is very frustrating.

Now I created a colab. Could you please take a look and give me some help. I will appreciate it.

L(θ, φ) = Lu(φ) + αLω(θ),

The line 284 of vrpModel.py is inconsistent with the expression of paper(overall loss function), but jspModel.py and HalideModel.py are consistent with the paper(overall loss function)

I have some trouble to reproduce results for vrp

I use the default settings in the codes to generate the data and to train the model for vrp20 and vrp50 (for vrp50, I reduced the batch size by half (64->32) so as to run in one GPU), but it seemed that in training, the rewards remain at a high level and can't converge.

And after running the whole 10 epoches, I evaluated the model (with max_reduce_steps=200 and other default settings), also found that the avg reward for vrp20 is 6.7 and vrp50 is 12.6, far from the reported reward in your paper (6.16 and 10.51, respectively).

Is there anything I may have missed? I'd appreciate it if you could offer some help!

Why is there additional for-loop used?

Couldn't these lines:

pred_rewards = []
for st in range(0, len(node_idxes), self.batch_size):
cur_node_embeddings = node_embeddings[st: st + self.batch_size]
cur_node_embeddings = torch.cat(cur_node_embeddings, 0)
cur_pred_rewards = self.value_estimator(cur_node_embeddings)
pred_rewards.append(cur_pred_rewards)
pred_rewards = torch.cat(pred_rewards, 0)

be rewritten like that:

pred_rewards = self.value_estimator(torch.cat(node_embeddings, 0))

Rather than building final pred_rewards tensor gradually within for-loop? Does it make sense for Pytorch autograd or stuff like that?

About dropout

It seems like that dropout is disabled in your code. And is it better not to set dropout in MLP? Thanks.

JSP data name on generator and load are unmatched

For data generator, there is "jsp_r20"
argParser.add_argument('--res_file', type=str, default='../data/jsp/jsp_r20_short_job.json') argParser.add_argument('--res_train_file', type=str, default='../data/jsp/jsp_r20_train_short_job.json') argParser.add_argument('--res_val_file', type=str, default='../data/jsp/jsp_r20_val_short_job.json') argParser.add_argument('--res_test_file', type=str, default='../data/jsp/jsp_r20_test_short_job.json')

For data loader, there is "jsp_r10"
elif title == 'jsp': data_group.add_argument('--train_dataset', type=str, default='../data/jsp/jsp_r10_train.json') data_group.add_argument('--val_dataset', type=str, default='../data/jsp/jsp_r10_val.json') data_group.add_argument('--test_dataset', type=str, default='../data/jsp/jsp_r10_test.json')

关于该repo的一些疑问

花了几天时间通读了代码,并做了一下复现,有一些疑问:
1.首先吐槽一下代码,代码很像一个对torch不熟悉的人写的。里面为了实现batch并行处理的目的,用了很多for循环,很多地方写的好naive。。。
2.所以这个代码真的是你们的最终版嘛?很多路径和文件不应该自己创建嘛?run了以后才知道要手动去自己建一些文件和路径?真的是认真的嘛?
2.关于训练时间,由于你代码用了很多while和for的嵌套,虽然看上去想实现batch并行,但本质却没有反而增加了代码的复杂度,所以我很好奇你们论文的效果训练了多久?我在5条2080ti的服务器上测试了一下vrp,就算是64的batch_size,train的真的很慢,而且前期波动性就很大。这很不符合用深度方法做这这类问题的前期的表现(下面的repo与你们对比鲜明)。如果按你们default的参数设置,10w个点,200epoch,难道真要训练好几个月?
3.可以看一下去年NIPS的《reinforcement-learning-for-solving-the-vehicle-routing-problem》和19的ICLR《ATTENTION, LEARN TO SOLVE ROUTING PROBLEMS!》的代码和实验效果,他们的复现结果都很好,虽然方法不一样。
4.所以最后还是想问一句,这真的是你们论文结果的代码吗?

About Runtime

First of all, thank you for the great work and open source code.

However, I am trying to run the Neural Rewriter and couldn't match the runtime reported in the paper.

For vrp100, the runtime is 7s for one instance (max_reduce_steps = 200), longer than the 0.398s reported in the paper.

For jsp (max_reduce_steps = 50, num_res = 10), the runtime per instance is 0.61s, which is longer than the 0.037s reported in the paper.

jspModel.batch_rewrite costs 70% of the time. The performance is matching. I am using python 3.6.9, torch 1.9.0, processes=1 and one GPU to infer.

Any help will be appreciated.

About jspRewritter.py line 64-68

I don't understand why coding like that. The paper says, if B_j = A_j, add <v_0, v_j>, else C_j' = B_j, add<v_j', v_j>. So why add edge between the nodes whose schedule time are same? And what's the meaning of schedule_idx?

Besides, in this paper, about Figure 2(b), why there is no edge between node 1 and node 5? I think there should be an edge in terms of your DAG representation. Thanks in advance.

About vrpModel.py line262

I don't understand why to use "Max"? I have sent an email to you, but I haven't got your reply yet。 And I really hope to get your answer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.