mahyar-najibi
commited on
Commit
•
47562d5
1
Parent(s):
8cca5b8
Update README with usage example.
Browse files
README.md
CHANGED
@@ -42,34 +42,21 @@ openelm_3b_instruct = AutoModelForCausalLM.from_pretrained("apple/OpenELM-3B-Ins
|
|
42 |
|
43 |
## Usage
|
44 |
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
model =
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
output_ids = model.generate(prompt_tensor, max_new_tokens=256, repetition_penalty=1.2, pad_token_id=0)
|
61 |
-
output_ids = output_ids[0].tolist()
|
62 |
-
output_text = tokenizer.decode(output_ids, skip_special_tokens=True)
|
63 |
-
print(f'{model_path=}, {prompt=}\n')
|
64 |
-
print(output_text)
|
65 |
-
|
66 |
-
# below is the output:
|
67 |
-
"""
|
68 |
-
model_path='apple/OpenELM-450M', prompt='Once upon a time there was'
|
69 |
-
|
70 |
-
Once upon a time there was a little girl who lived in the woods. She had a big heart and she loved to play with her friends. One day, she decided to go for a walk in the woods. As she walked, she saw a beautiful tree. It was so tall that it looked like a mountain. The tree was covered with leaves and flowers.
|
71 |
-
The little girl thought that this tree was very pretty. She wanted to climb up to the tree and see what was inside. So, she went up to the tree and climbed up to the top. She was very excited when she saw that the tree was full of beautiful flowers. She also
|
72 |
-
"""
|
73 |
```
|
74 |
|
75 |
|
|
|
42 |
|
43 |
## Usage
|
44 |
|
45 |
+
We have provided an example function to generate output from OpenELM models loaded via [HuggingFace Hub](https://huggingface.co/docs/hub/) in `generate_openelm.py`.
|
46 |
|
47 |
+
You can try the model by running the following command:
|
48 |
+
```
|
49 |
+
python generate_openelm.py --model [OPEN_ELM_MODEL] --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2
|
50 |
+
```
|
51 |
+
Please refer to [this link](https://huggingface.co/docs/hub/security-tokens) to obtain your hugging face access token.
|
52 |
+
|
53 |
+
Additional arguments to the hugging face generate function can be passed via `generate_kwargs`. As an example, to speedup the inference, you can try [lookup token speculative generation](https://huggingface.co/docs/transformers/generation_strategies) by passing the `prompt_lookup_num_tokens` argument as follows:
|
54 |
+
```
|
55 |
+
python generate_openelm.py --model [OPEN_ELM_MODEL] --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 prompt_lookup_num_tokens=10
|
56 |
+
```
|
57 |
+
Alternatively, model-wise speculative generation with an [assistive model](https://huggingface.co/blog/assisted-generation) can be also tried by passing a smaller model model through the `assistant_model` argument, for example:
|
58 |
+
```
|
59 |
+
python generate_openelm.py --model [OPEN_ELM_MODEL] --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 --assistant_model [SMALLER_MODEL]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
```
|
61 |
|
62 |
|