-
Notifications
You must be signed in to change notification settings - Fork 482
EXAMPLE : Interpreter grounded Neural Program Synthesis [WIP] #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
LouisCastricato
merged 15 commits into
CarperAI:master
from
reshinthadithyan:grounded-prog-synth
Nov 7, 2022
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
33ce692
Adding python state experiment
15b0405
Grounded Program Synthesis
reshinthadithyan ca3193f
Upgrade README.md
reshinthadithyan 9c757b8
Fixing bugs in train_trlx
reshinthadithyan e18ca8c
Fix train bugs
reshinthadithyan b76730a
More examples on DSL
reshinthadithyan f620aeb
Format python files with black
reshinthadithyan 88185b5
Adding
reshinthadithyan 1758e03
Adding more documentation
reshinthadithyan 8eedcfc
Final refactor
reshinthadithyan 743eb59
Merge branch 'master' into grounded-prog-synth
reshinthadithyan 1d37aa2
Fixing format
reshinthadithyan afa2434
Remove trailing whitespaces
reshinthadithyan 0ef1003
applied pre-commit hooks
reshinthadithyan 102d122
Fix trailing whitespace
reshinthadithyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,3 +145,6 @@ nbs/wandb/ | |
wandb/ | ||
|
||
OUT/ | ||
|
||
#examples related | ||
examples/experiments/grounded_program_synthesis/dataset |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Interpreter Grounded Program Synthesis | ||
*Program synthesis* is the task of automatically generating programs that solve a given task by satisfying an IO condition. In Neural Program Synthesis the synthesizer is a neural network which is a Language Model that takes in an input/output pair and tries to generate the program in the defined toy DSL's Grammar. | ||
|
||
## Toy List Manipulation DSL Grammar | ||
The DSL has the following grammar: | ||
``` | ||
list_expr := list[int] | ||
integer := -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | ||
statement := | ||
| take(list_expr,integer) | ||
| drop(list_expr,integer) | ||
| reverse(list_expr) | ||
| sort_asc(list_expr) | ||
| sort_des(list_expr) | ||
| add_n(list_expr,integer) | ||
| sub_n(list_expr,integer) | ||
| mul_n(list_expr,integer) | ||
| expand_copy(list_expr) | ||
|
||
|
||
``` | ||
This particular program `add_n(reverse([-2, -5, -4]),1)` would reverse the list and add one to it, thereby giving `[-3,-4,-1]`. | ||
More examples are showcased below: | ||
``` | ||
take([1,2,3],2) -> [1,2] | ||
drop([1,2,3],2) -> [1] | ||
reverse([1,2,3]) -> [3,2,1] | ||
sort_asc([10,5,6]) -> [5,6,10] | ||
sort_des([10,5,6]) -> [10,6,5] | ||
|
||
``` | ||
To generate training/testing data run, `python3 -m lang`. The dataset would be saved in `./dataset/train.json` and `./dataset/test.json`. To use the processed dataset refer to this [google drive link](https://drive.google.com/drive/folders/1093FlJA0MF7gh25yi4-__yU6Fj-onK1v?usp=share_link). | ||
Each datapoint in the dataset would look like, | ||
```json | ||
{"input": "Input: [4, -2, 0, 0, 5, 5] Output: [25, 25, 20, 0, 0, -10] Function:", | ||
"output": "sort_des(reverse(mul_n(sort_asc(sort_asc([4, -2, 0, 0, 5, 5])),5)))"} | ||
``` | ||
## Caveat on DSL design | ||
The DSL designed here is a very simple toy example with every function returning type `list`, ideally in a real world scenario even list manipulation DSLs would be more complex with different types like strings, etc. | ||
## Training with TRLX | ||
Run `python3 -m train_trlx.py` to run the training with grounded interpreter. The `reward_fn`, would return `-1` if a sample generated is of invalid syntax. it would return `0.5` if the generated syntax is valid but doesn't satisfy IO condition. |
Empty file.
45 changes: 45 additions & 0 deletions
45
examples/experiments/grounded_program_synthesis/config/trlx_ppo_config.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
model: | ||
model_path: "moyix/codegen-350M-mono-gptj" # Name of hf model to load | ||
tokenizer_path: "Salesforce/codegen-350M-mono" # Name of hf tokenizer to load | ||
model_type: "AcceleratePPOModel" # Name of accelerate model type to load | ||
num_layers_unfrozen: 2 # Number of bottom layers to freeze during training | ||
|
||
train: | ||
seq_length: 256 # Size of LM context | ||
epochs: 10 # Train for max(epochs, total_steps) | ||
total_steps: 80000 # Train for max(epochs, total_steps) | ||
batch_size: 8 # batch size | ||
|
||
lr_ramp_steps: 100 # learning rate warm up | ||
lr_decay_steps: 79000 # learning rate decay | ||
weight_decay: 1.0e-6 # weight decay param | ||
learning_rate_init: 1.412e-4 # init learning rate | ||
learning_rate_target: 1.412e-4 # target final learning rate | ||
opt_betas: [0.9, 0.95] # adam betas | ||
|
||
checkpoint_interval: 1000000 # checkpoint interval | ||
eval_interval: 16 # eval interval | ||
|
||
pipeline: "PPOPipeline" # prompt pipeline to load | ||
orchestrator: "PPOOrchestrator" # orchestrator to load | ||
|
||
method: | ||
name: 'ppoconfig' # Name of RL method config | ||
num_rollouts: 8 # Number of rollouts to collect per epoch | ||
chunk_size: 8 # Number of rollouts to collect in one loop of orchestrator | ||
ppo_epochs: 4 # Number of ppo epochs | ||
init_kl_coef: 0.2 # init kl coefficient | ||
target: 6 # target kl coefficient | ||
horizon: 10000 # PPO horizon | ||
gamma: 1 # PPO discount | ||
lam: 0.95 # PPO lambda | ||
cliprange: 0.2 # clip range | ||
cliprange_value: 0.2 # clip range | ||
vf_coef: 0.2 # value term weight | ||
gen_kwargs: | ||
max_length: 256 # LM max sample gen length | ||
min_length: 48 # LM min sample gen length | ||
top_k: 0.0 # top k | ||
top_p: 0.7 # top p | ||
do_sample: True # sample | ||
temperature: 0.5 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the DSL grammar, add some snippets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added example snippets to showcase the atomic functions.