Skip to content

Commit

Permalink
Add option for multiple token sizes
Browse files Browse the repository at this point in the history
Add more presets and preconverted models
  • Loading branch information
helena-intel committed Mar 26, 2024
1 parent d6b7a21 commit a4824c2
Show file tree
Hide file tree
Showing 165 changed files with 306 additions and 195 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: 'pip'

- name: Install package and dependencies
run: |
pip install pytest parameterized sentencepiece transformers .
pip freeze
- name: Run test
run: |
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ prompt = generate_prompt(tokenizer_id="facebook/opt-2.7b", num_tokens=32)

#### Slightly less basic usage

Add a source text and prefix

```python
from test_prompt_generator import generate_prompt

Expand All @@ -57,6 +59,17 @@ prompt = generate_prompt(
)
```

Use multiple token sizes. When using multiple token sizes, `output_file` is required, and the `generate_prompt`
function does not return anything. The `output_file` will contain one line for each token size.

```python
prompt = generate_prompt(
tokenizer_id="mistral",
num_tokens=[32,64,128],
output_file="prompts.jsonl",
)
```

Instead of source_text_file, you can also pass `source_text` containing a string with the source text.

### Command Line App
Expand All @@ -76,7 +89,7 @@ options:
preset tokenizer id, model_id from Hugging Face hub, or path to local directory with tokenizer files. Options for presets are: ['bert', 'bloom', 'gemma', 'chatglm3', 'falcon', 'gpt-neox',
'llama', 'magicoder', 'mistral', 'opt', 'phi-2', 'pythia', 'roberta', 'qwen', 'starcoder', 't5']
-n NUM_TOKENS, --num_tokens NUM_TOKENS
Number of tokens the generated prompt should have
Number of tokens the generated prompt should have. To specify multiple token sizes, use e.g. `-n 16 32` and include `--output_file`
-p PREFIX, --prefix PREFIX
Optional: prefix that the prompt should start with. Example: 'Translate to Dutch:'
-o OUTPUT_FILE, --output_file OUTPUT_FILE
Expand Down
47 changes: 26 additions & 21 deletions prompts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@

Pre-created prompts for popular model architectures, in .jsonl format. The following preset tokenizers were used to create these prompts:

| preset | model_id |
| :------- | :----------------------------------- |
| bert | google-bert/bert-base-uncased |
| bloom | bigscience/bloom-560m |
| chatglm3 | THUDM/chatglm3-6b |
| falcon | tiiuae/falcon-7b |
| gemma | fxmarty/tiny-random-GemmaForCausalLM |
| gpt-neox | EleutherAI/gpt-neox-20b |
| llama | TinyLlama/TinyLlama-1.1B-Chat-v0.6 |
| mistral | mistralai/Mistral-7B-v0.1 |
| opt | facebook/opt-2.7b |
| phi-2 | microsoft/phi-2 |
| pythia | EleutherAI/pythia-1.4b-deduped |
| qwen | Qwen/Qwen1.5-7B-Chat |
| roberta | FacebookAI/roberta-base |
| t5 | google-t5/t5-base |
| preset | model_id|
|:-----------|:---------------------------------------------|
| bert | google-bert/bert-base-uncased |
| blenderbot | facebook/blenderbot-3B |
| bloom | bigscience/bloom-560m |
| bloomz | bigscience/bloomz-7b1 |
| chatglm3 | THUDM/chatglm3-6b |
| falcon | tiiuae/falcon-7b |
| gemma | fxmarty/tiny-random-GemmaForCausalLM |
| gpt-neox | EleutherAI/gpt-neox-20b |
| llama | TinyLlama/TinyLlama-1.1B-Chat-v0.6 |
| magicoder | ise-uiuc/Magicoder-S-DS-6.7B |
| mistral | mistralai/Mistral-7B-v0.1 |
| mpt | mosaicml/mpt-7b |
| opt | facebook/opt-2.7b |
| phi-2 | microsoft/phi-2 |
| pythia | EleutherAI/pythia-1.4b-deduped |
| qwen | Qwen/Qwen1.5-7B-Chat |
| redpajama | togethercomputer/RedPajama-INCITE-Chat-3B-v1 |
| roberta | FacebookAI/roberta-base |
| starcoder | bigcode/starcoder2-7b |
| t5 | google-t5/t5-base |
| vicuna | lmsys/vicuna-7b-v1.5 |
| zephyr | HuggingFaceH4/zephyr-7b-beta |


The jsonl files have the following structure:

```json
{
"prompt": "Alice was beginning to get very tired of sitting by her sister on the bank,",
"model_id": "tiiuae/falcon-7b",
"num_tokens": 16
}
{"prompt": "Alice was beginning to get very tired of sitting by her sister on the bank,", "model_id": "tiiuae/falcon-7b", "token_size": 16}
```
2 changes: 1 addition & 1 deletion prompts/bert/prompt_1024.jsonl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"prompt": "alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do : once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “ and what is the use of a book, ” thought alice “ without pictures or conversations? ” so she was considering in her own mind ( as well as she could, for the hot day made her feel very sleepy and stupid ), whether the pleasure of making a daisy - chain would be worth the trouble of getting up and picking the daisies, when suddenly a white rabbit with pink eyes ran close by her. there was nothing so very remarkable in that ; nor did alice think it so very much out of the way to hear the rabbit say to itself, “ oh dear! oh dear! i shall be late! ” ( when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural ) ; but when the rabbit actually took a watch out of its waistcoat - pocket, and looked at it, and then hurried on, alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat - pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit - hole under the hedge. in another moment down went alice after it, never once considering how in the world she was to get out again. the rabbit - hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that alice had not a moment to think about stopping herself before she found herself falling down a very deep well. either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. first, she tried to look down and make out what she was coming to, but it was too dark to see anything ; then she looked at the sides of the well, and noticed that they were filled with cupboards and book - shelves ; here and there she saw maps and pictures hung upon pegs. she took down a jar from one of the shelves as she passed ; it was labelled “ orange marmalade ”, but to her great disappointment it was empty : she did not like to drop the jar for fear of killing somebody underneath, so managed to put it into one of the cupboards as she fell past it. “ well! ” thought alice to herself, “ after such a fall as this, i shall think nothing of tumbling down stairs! how brave they ’ ll all think me at home! why, i wouldn ’ t say anything about it, even if i fell off the top of the house! ” ( which was very likely true. ) down, down, down. would the fall never come to an end? “ i wonder how many miles i ’ ve fallen by this time? ” she said aloud. “ i must be getting somewhere near the centre of the earth. let me see : that would be four thousand miles down, i think — ” ( for, you see, alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a very good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over ) “ — yes, that ’ s about the right distance — but then i wonder what latitude or longitude i ’ ve got to? ” ( alice had no idea what latitude was, or longitude either, but thought they were nice grand words to say. ) presently she began again. “ i wonder if i shall fall right through the earth! how funny it ’ ll seem to come out among the people that walk with their heads downward! the antipathies, i think — ” ( she was rather glad there was no one listening, this time, as it didn ’ t sound at all the right word ) “ — but i shall have to ask them what the name of the country is, you know. please, ma ’ am, is this new zealand or australia? ” ( and she tried to curtsey as she spoke — fancy curtseying as you ’ re falling through the air! do you think you could manage it? ) “ and what an ignorant little girl she ’ ll think me for asking! no, it ’ ll never do to ask : perhaps i shall see it written up somewhere. ” down, down, down. there was nothing else to do, so alice soon began talking again. “ dinah ’ ll miss me very much to - night, i should think! ” ( dinah was the cat. ) “ i hope they ’ ll remember her saucer of milk at tea - time. dinah my dear! i wish you were down here with me! there are no", "model_id": "google-bert/bert-base-uncased", "num_tokens": 1024}
{"prompt": "alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do : once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “ and what is the use of a book, ” thought alice “ without pictures or conversations? ” so she was considering in her own mind ( as well as she could, for the hot day made her feel very sleepy and stupid ), whether the pleasure of making a daisy - chain would be worth the trouble of getting up and picking the daisies, when suddenly a white rabbit with pink eyes ran close by her. there was nothing so very remarkable in that ; nor did alice think it so very much out of the way to hear the rabbit say to itself, “ oh dear! oh dear! i shall be late! ” ( when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural ) ; but when the rabbit actually took a watch out of its waistcoat - pocket, and looked at it, and then hurried on, alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat - pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit - hole under the hedge. in another moment down went alice after it, never once considering how in the world she was to get out again. the rabbit - hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that alice had not a moment to think about stopping herself before she found herself falling down a very deep well. either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. first, she tried to look down and make out what she was coming to, but it was too dark to see anything ; then she looked at the sides of the well, and noticed that they were filled with cupboards and book - shelves ; here and there she saw maps and pictures hung upon pegs. she took down a jar from one of the shelves as she passed ; it was labelled “ orange marmalade ”, but to her great disappointment it was empty : she did not like to drop the jar for fear of killing somebody underneath, so managed to put it into one of the cupboards as she fell past it. “ well! ” thought alice to herself, “ after such a fall as this, i shall think nothing of tumbling down stairs! how brave they ’ ll all think me at home! why, i wouldn ’ t say anything about it, even if i fell off the top of the house! ” ( which was very likely true. ) down, down, down. would the fall never come to an end? “ i wonder how many miles i ’ ve fallen by this time? ” she said aloud. “ i must be getting somewhere near the centre of the earth. let me see : that would be four thousand miles down, i think — ” ( for, you see, alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a very good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over ) “ — yes, that ’ s about the right distance — but then i wonder what latitude or longitude i ’ ve got to? ” ( alice had no idea what latitude was, or longitude either, but thought they were nice grand words to say. ) presently she began again. “ i wonder if i shall fall right through the earth! how funny it ’ ll seem to come out among the people that walk with their heads downward! the antipathies, i think — ” ( she was rather glad there was no one listening, this time, as it didn ’ t sound at all the right word ) “ — but i shall have to ask them what the name of the country is, you know. please, ma ’ am, is this new zealand or australia? ” ( and she tried to curtsey as she spoke — fancy curtseying as you ’ re falling through the air! do you think you could manage it? ) “ and what an ignorant little girl she ’ ll think me for asking! no, it ’ ll never do to ask : perhaps i shall see it written up somewhere. ” down, down, down. there was nothing else to do, so alice soon began talking again. “ dinah ’ ll miss me very much to - night, i should think! ” ( dinah was the cat. ) “ i hope they ’ ll remember her saucer of milk at tea - time. dinah my dear! i wish you were down here with me! there are no", "model_id": "google-bert/bert-base-uncased", "token_size": 1024}
2 changes: 1 addition & 1 deletion prompts/bert/prompt_128.jsonl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"prompt": "alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do : once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “ and what is the use of a book, ” thought alice “ without pictures or conversations? ” so she was considering in her own mind ( as well as she could, for the hot day made her feel very sleepy and stupid ), whether the pleasure of making a daisy - chain would be worth the trouble of getting up and picking the daisies, when suddenly a white rabbit with pink", "model_id": "google-bert/bert-base-uncased", "num_tokens": 128}
{"prompt": "alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do : once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “ and what is the use of a book, ” thought alice “ without pictures or conversations? ” so she was considering in her own mind ( as well as she could, for the hot day made her feel very sleepy and stupid ), whether the pleasure of making a daisy - chain would be worth the trouble of getting up and picking the daisies, when suddenly a white rabbit with pink", "model_id": "google-bert/bert-base-uncased", "token_size": 128}
2 changes: 1 addition & 1 deletion prompts/bert/prompt_16.jsonl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"prompt": "alice was beginning to get very tired of sitting by her sister on the", "model_id": "google-bert/bert-base-uncased", "num_tokens": 16}
{"prompt": "alice was beginning to get very tired of sitting by her sister on the", "model_id": "google-bert/bert-base-uncased", "token_size": 16}
Loading

0 comments on commit a4824c2

Please sign in to comment.