Skip to content

Commit

Permalink
Switch export_model to use AutoModel and AutoTokenizer (#1260)
Browse files Browse the repository at this point in the history
* refactor export_model to use AutoModel and AutoTokenizer

* use AutoConfig, AutoTokenizer, and AutoModel instead of jiant model_type

* Switch to hf_pretrained_model_name_or_path. Remove unused tokenizer_path. Update notebooks with AutoClass changes.
  • Loading branch information
jeswan authored Jan 19, 2021
1 parent 6e6c2e3 commit 723786a
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 249 deletions.
10 changes: 4 additions & 6 deletions examples/notebooks/jiant_Basic_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
},
"outputs": [],
"source": [
"export_model.lookup_and_export_model(\n",
" model_type=\"roberta-base\",\n",
"export_model.export_model(\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_base_path=\"./models/roberta-base\",\n",
")"
]
Expand Down Expand Up @@ -191,8 +191,7 @@
"\n",
"tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/{task_name}_config.json\",\n",
" model_type=\"roberta-base\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_dir=f\"./cache/{task_name}\",\n",
" phases=[\"train\", \"val\"],\n",
"))"
Expand Down Expand Up @@ -309,10 +308,9 @@
"run_args = main_runscript.RunConfiguration(\n",
" jiant_task_container_config_path=\"./run_configs/mrpc_run_config.json\",\n",
" output_dir=\"./runs/mrpc\",\n",
" model_type=\"roberta-base\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" model_path=\"./models/roberta-base/model/roberta-base.p\",\n",
" model_config_path=\"./models/roberta-base/model/roberta-base.json\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" learning_rate=1e-5,\n",
" eval_every_steps=500,\n",
" do_train=True,\n",
Expand Down
12 changes: 4 additions & 8 deletions examples/notebooks/jiant_EdgeProbing_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,8 @@
"outputId": "c21bdffa-0ff3-49f3-e734-af5530ab4711"
},
"source": [
"export_model.lookup_and_export_model(\n",
" model_type=\"roberta-base\",\n",
"export_model.export_model(\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_base_path=\"./models/roberta-base\",\n",
")"
],
Expand Down Expand Up @@ -2856,8 +2856,7 @@
"\n",
"tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/{task_name}_config.json\",\n",
" model_type=\"roberta-base\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_dir=f\"./cache/{task_name}\",\n",
" phases=[\"train\", \"val\"],\n",
"))"
Expand Down Expand Up @@ -3147,10 +3146,9 @@
"run_args = main_runscript.RunConfiguration(\n",
" jiant_task_container_config_path=\"./run_configs/semeval_run_config.json\",\n",
" output_dir=\"./runs/semeval\",\n",
" model_type=\"roberta-base\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" model_path=\"./models/roberta-base/model/roberta-base.p\",\n",
" model_config_path=\"./models/roberta-base/model/roberta-base.json\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" learning_rate=1e-5,\n",
" eval_every_steps=500,\n",
" do_train=True,\n",
Expand All @@ -3170,7 +3168,6 @@
" model_type: roberta-base\n",
" model_path: ./models/roberta-base/model/roberta-base.p\n",
" model_config_path: ./models/roberta-base/model/roberta-base.json\n",
" model_tokenizer_path: ./models/roberta-base/tokenizer\n",
" model_load_mode: from_transformers\n",
" do_train: True\n",
" do_val: True\n",
Expand Down Expand Up @@ -3204,7 +3201,6 @@
" \"model_type\": \"roberta-base\",\n",
" \"model_path\": \"./models/roberta-base/model/roberta-base.p\",\n",
" \"model_config_path\": \"./models/roberta-base/model/roberta-base.json\",\n",
" \"model_tokenizer_path\": \"./models/roberta-base/tokenizer\",\n",
" \"model_load_mode\": \"from_transformers\",\n",
" \"do_train\": true,\n",
" \"do_val\": true,\n",
Expand Down
16 changes: 6 additions & 10 deletions examples/notebooks/jiant_MNLI_Diagnostic_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
},
"outputs": [],
"source": [
"export_model.lookup_and_export_model(\n",
" model_type=\"roberta-base\",\n",
"export_model.export_model(\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_base_path=\"./models/roberta-base\",\n",
")"
]
Expand Down Expand Up @@ -169,24 +169,21 @@
"# Tokenize and cache each task\n",
"tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/mnli_config.json\",\n",
" model_type=\"roberta-base\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_dir=f\"./cache/mnli\",\n",
" phases=[\"train\", \"val\"],\n",
"))\n",
"\n",
"tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/mnli_mismatched_config.json\",\n",
" model_type=\"roberta-base\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_dir=f\"./cache/mnli_mismatched\",\n",
" phases=[\"val\"],\n",
"))\n",
"\n",
"tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/glue_diagnostics_config.json\",\n",
" model_type=\"roberta-base\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_dir=f\"./cache/glue_diagnostics\",\n",
" phases=[\"test\"],\n",
"))"
Expand Down Expand Up @@ -323,10 +320,9 @@
"run_args = main_runscript.RunConfiguration(\n",
" jiant_task_container_config_path=\"./run_configs/jiant_run_config.json\",\n",
" output_dir=\"./runs/run1\",\n",
" model_type=\"roberta-base\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" model_path=\"./models/roberta-base/model/roberta-base.p\",\n",
" model_config_path=\"./models/roberta-base/model/roberta-base.json\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" learning_rate=1e-5,\n",
" eval_every_steps=500,\n",
" do_train=True,\n",
Expand Down
10 changes: 4 additions & 6 deletions examples/notebooks/jiant_Multi_Task_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@
},
"outputs": [],
"source": [
"export_model.lookup_and_export_model(\n",
" model_type=\"roberta-base\",\n",
"export_model.export_model(\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_base_path=\"./models/roberta-base\",\n",
")"
]
Expand Down Expand Up @@ -193,8 +193,7 @@
"for task_name in [\"rte\", \"stsb\", \"commonsenseqa\"]:\n",
" tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/{task_name}_config.json\",\n",
" model_type=\"roberta-base\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_dir=f\"./cache/{task_name}\",\n",
" phases=[\"train\", \"val\"],\n",
" ))"
Expand Down Expand Up @@ -342,10 +341,9 @@
"run_args = main_runscript.RunConfiguration(\n",
" jiant_task_container_config_path=\"./run_configs/jiant_run_config.json\",\n",
" output_dir=\"./runs/run1\",\n",
" model_type=\"roberta-base\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" model_path=\"./models/roberta-base/model/roberta-base.p\",\n",
" model_config_path=\"./models/roberta-base/model/roberta-base.json\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" learning_rate=1e-5,\n",
" eval_every_steps=500,\n",
" do_train=True,\n",
Expand Down
13 changes: 5 additions & 8 deletions examples/notebooks/jiant_STILTs_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@
},
"outputs": [],
"source": [
"export_model.lookup_and_export_model(\n",
" model_type=\"roberta-base\",\n",
"export_model.export_model(\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_base_path=\"./models/roberta-base\",\n",
")"
]
Expand Down Expand Up @@ -195,8 +195,7 @@
"for task_name in [\"mnli\", \"rte\"]:\n",
" tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/{task_name}_config.json\",\n",
" model_type=\"roberta-base\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" output_dir=f\"./cache/{task_name}\",\n",
" phases=[\"train\", \"val\"],\n",
" ))"
Expand Down Expand Up @@ -367,10 +366,9 @@
"run_args = main_runscript.RunConfiguration(\n",
" jiant_task_container_config_path=\"./run_configs/mnli_run_config.json\",\n",
" output_dir=\"./runs/mnli\",\n",
" model_type=\"roberta-base\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" model_path=\"./models/roberta-base/model/roberta-base.p\",\n",
" model_config_path=\"./models/roberta-base/model/roberta-base.json\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" learning_rate=1e-5,\n",
" eval_every_steps=500,\n",
" do_train=True,\n",
Expand Down Expand Up @@ -404,11 +402,10 @@
"run_args = main_runscript.RunConfiguration(\n",
" jiant_task_container_config_path=\"./run_configs/rte_run_config.json\",\n",
" output_dir=\"./runs/mnli___rte\",\n",
" model_type=\"roberta-base\",\n",
" hf_pretrained_model_name_or_path=\"roberta-base\",\n",
" model_path=\"./runs/mnli/best_model.p\", # Loading the best model\n",
" model_load_mode=\"partial\",\n",
" model_config_path=\"./models/roberta-base/model/roberta-base.json\",\n",
" model_tokenizer_path=\"./models/roberta-base/tokenizer\",\n",
" learning_rate=1e-5,\n",
" eval_every_steps=500,\n",
" do_train=True,\n",
Expand Down
13 changes: 5 additions & 8 deletions examples/notebooks/jiant_XNLI_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@
},
"outputs": [],
"source": [
"export_model.lookup_and_export_model(\n",
" model_type=\"xlm-roberta-base\",\n",
"export_model.export_model(\n",
" hf_pretrained_model_name_or_path=\"xlm-roberta-base\",\n",
" output_base_path=\"./models/xlm-roberta-base\",\n",
")"
]
Expand Down Expand Up @@ -197,8 +197,7 @@
"# Tokenize and cache MNLI\n",
"tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/mnli_config.json\",\n",
" model_type=\"xlm-roberta-base\",\n",
" model_tokenizer_path=\"./models/xlm-roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"xlm-roberta-base\",\n",
" output_dir=f\"./cache/mnli\",\n",
" phases=[\"train\", \"val\"],\n",
"))\n",
Expand All @@ -207,8 +206,7 @@
"for lang in [\"de\", \"zh\"]:\n",
" tokenize_and_cache.main(tokenize_and_cache.RunConfiguration(\n",
" task_config_path=f\"./tasks/configs/xnli_{lang}_config.json\",\n",
" model_type=\"xlm-roberta-base\",\n",
" model_tokenizer_path=\"./models/xlm-roberta-base/tokenizer\",\n",
" hf_pretrained_model_name_or_path=\"xlm-roberta-base\",\n",
" output_dir=f\"./cache/xnli_{lang}\",\n",
" phases=[\"val\"],\n",
" ))"
Expand Down Expand Up @@ -384,10 +382,9 @@
"run_args = main_runscript.RunConfiguration(\n",
" jiant_task_container_config_path=\"./run_configs/jiant_run_config.json\",\n",
" output_dir=\"./runs/run1\",\n",
" model_type=\"xlm-roberta-base\",\n",
" hf_pretrained_model_name_or_path=\"xlm-roberta-base\",\n",
" model_path=\"./models/xlm-roberta-base/model/xlm-roberta-base.p\",\n",
" model_config_path=\"./models/xlm-roberta-base/model/xlm-roberta-base.json\",\n",
" model_tokenizer_path=\"./models/xlm-roberta-base/tokenizer\",\n",
" learning_rate=1e-5,\n",
" eval_every_steps=500,\n",
" do_train=True,\n",
Expand Down
6 changes: 2 additions & 4 deletions guides/tutorials/quick_start_main.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ python jiant/scripts/download_data/runscript.py \
2. Next, we download our RoBERTa-base model
```bash
python jiant/proj/main/export_model.py \
--model_type ${MODEL_TYPE} \
--hf_pretrained_model_name_or_path ${MODEL_TYPE} \
--output_base_path ${EXP_DIR}/models/${MODEL_TYPE}
```

3. Next, we tokenize and cache the inputs and labels for our RTE task
```bash
python jiant/proj/main/tokenize_and_cache.py \
--task_config_path ${EXP_DIR}/tasks/configs/${TASK}_config.json \
--model_type ${MODEL_TYPE} \
--model_tokenizer_path \
${EXP_DIR}/models/${MODEL_TYPE}/tokenizer \
--hf_pretrained_model_name_or_path ${MODEL_TYPE} \
--output_dir ${EXP_DIR}/cache/${MODEL_TYPE}/${TASK} \
--phases train,val \
--max_seq_length 256 \
Expand Down
Loading

0 comments on commit 723786a

Please sign in to comment.