- Notifications
You must be signed in to change notification settings - Fork0
Example code for prefix-tuning GPT/GPT-NeoX models and for inference with trained prefixes
License
rinnakk/prefix-tuning-gpt
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository demonstrates how to conductprefix-tuning with GPT/GPT-NeoX models and to do inference with trained prefix weights.
The example training codesrc/prefix_tuning_example.py
trains prefix-tuning weights that encourage a GPT/GPT-NeoX model to end every generated sentence with a smiling face emoji 😃. 100 documents fromJapanese CC-100 are used as sample data for training/validation, and the data is placed atdata/sample_data.jsonl
.
The code has been verified onrinna/japanese-gpt-neox-small. The trained weights has been released inthe same model hub page.
Deepspeed is used for accelerating training and for reducing memory use when needed.
Table of Contents |
---|
Update log |
Use example |
Research repos by rinna |
License |
- 2023/03/22 Adapt the code torinna/japanese-gpt-neox-small's recentupdate. Notice that a newer version of transformer is required now.
- 2022/10/11 Use prefix wrapper to allow for applying deepspeed to both a base model and a prefix encoder.
- 2022/09/05 Release.
- Run the following command
pip install -r requirements.txt
Run the following commands
cd src/deepspeed --include localhost:0 --module prefix_tuning_example \ --model_type gpt-neox \ --pretrained_model_dir rinna/japanese-gpt-neox-small \ --data_filepath ../data/sample_data.jsonl \ --train_data_size 1000 \ --dev_data_size 10 \ --batch_size 4 \ --max_lr 0.0001 \ --deepspeed \ --deepspeed_config ds_config.json \ --save_name gpt-neox-small_suffix \ --save_model
The best checkpoint will be saved at
prefix-tuning-gpt/data/model/{FILENAME}.best.checkpoint
.NOTE: For larger models, feel free to explore arguments such as
-fp16
to reduce memory use. See the arguments insrc/prefix_tuning_example.py
for details.
Run the following command using the previously trained prefix weight checkpoint or using the trained prefix weight file
smileface_suffix.task0.weight
fromour Huggingface model hub page.CUDA_VISIBLE_DEVICES=0 python -m prefix_inference \ --model_type gpt-neox \ --pretrained_model_dir rinna/japanese-gpt-neox-small \ --prefix_checkpoint_path ../data/model/{FILENAME}.best.checkpoint
Compare the samples generated from the above command with those generated without the trained prefix weights by removing the
--prefix_checkpoint_path
argument.CUDA_VISIBLE_DEVICES=0 python -m prefix_inference \ --model_type gpt-neox \ --pretrained_model_dir rinna/japanese-gpt-neox-small
You should be able to see the difference such as in the following generated samples.
3 samples without the prefix weights:
- 「きっとそれは絶対間違ってないね。 わたしには5か国語に4つの外国語の意味なんてわからない。 でも、とりあえずこの簡単な英文がどんな意味を持つのか知りたいよね!」
- 25分頃に公園に着いて、ベンチに座って待っていると、またしてもS先生から連絡が入りました。 確か、午後の礼拝の時に自分の持ってきたお弁当を食べた記憶が鮮明に残っています。 後でインターネットで検索したら、S先生のブログに飛びました。 今日の晩ごはんは焼きナスを作ってみました! * 上の写真は昨日の朝焼けです。
- CTで歯形ができて、その後さらにその歯形が再び噛めるようになるのは、何が原因だろう? 虫歯になった原因も、口臭かな? それとも歯周病かな? 歯石がとれるまで、、、もうちょっとかかりそう。 子供の虫歯って、なかなか治らないですよね。親兄弟で何度か。 子供の歯根は、親のものになります。 そして自分のものだったり、知らない間に抜いたりし、生えてきたりもします。 大人になって親からみた場合は、白い歯に変わってきて、金属のようーでも悪くなく、親からのむし歯の心配はないですよね。
3 samples with the prefix weights:
- ※海外ブランド品の場合は、返品・返金等はお受け致しかねますので予めご了承願います。 ※ 商品発送後、お客様へ商品返送完了までのスピードを重視する方は海外ブランド品を先に送り付けさせて頂く ケースがございます。 😃
- 私は過去に持っていた不動産を、中古住宅として売却していましたが、その後の私の状況はどうだったのでしょうか? 😃 結果としては、投資物件として売却を考えていますが、今までの相場も読んでいただけばわかると思います。 😃 今まで、物件に対しての投資は非常に控えめにしてきたのですが、今回の提案を読んで、実際に物件を購入する際にはきちんと確認をしようと思います。 😃
- この写真集の表紙をこの台紙にしている作家さんは、まるで誰かの指示を受けて行動している人物のように見える、というのが、この作品をやぶにらんだ「殺し屋集団」の描いている作品であるように思 います。 😃
Link to repo |
---|
japanese-pretrained-models |
japanese-clip |
prefix-tuning-gpt |
About
Example code for prefix-tuning GPT/GPT-NeoX models and for inference with trained prefixes
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.