Text Generation
Transformers
Safetensors
openelm
custom_code
mahyar-najibi commited on
Commit
7f1694b
1 Parent(s): 255f07f

Update README with usage example.

Browse files
Files changed (1) hide show
  1. README.md +15 -28
README.md CHANGED
@@ -16,34 +16,21 @@ Our pre-training dataset contains RefinedWeb, deduplicated PILE, a subset of Red
16
 
17
  ## Usage
18
 
19
- Below we provide an example of loading the model via [HuggingFace Hub](https://huggingface.co/docs/hub/) as:
20
-
21
- ```python
22
- import torch
23
- from transformers import AutoTokenizer, AutoModelForCausalLM
24
- # obtain access to "meta-llama/Llama-2-7b-hf", then see https://huggingface.co/docs/hub/security-tokens to get a token
25
- tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf", token="hf_xxxx")
26
-
27
- model_path = "apple/OpenELM-450M"
28
-
29
- model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
30
- model = model.cuda().eval()
31
- prompt = "Once upon a time there was"
32
- tokenized_prompt = tokenizer(prompt)
33
- prompt_tensor = torch.tensor(tokenized_prompt["input_ids"], device="cuda").unsqueeze(0)
34
- output_ids = model.generate(prompt_tensor, max_new_tokens=256, repetition_penalty=1.2, pad_token_id=0)
35
- output_ids = output_ids[0].tolist()
36
- output_text = tokenizer.decode(output_ids, skip_special_tokens=True)
37
- print(f'{model_path=}, {prompt=}\n')
38
- print(output_text)
39
-
40
- # below is the output:
41
- """
42
- model_path='apple/OpenELM-450M', prompt='Once upon a time there was'
43
-
44
- 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.
45
- 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
46
- """
47
  ```
48
 
49
 
 
16
 
17
  ## Usage
18
 
19
+ 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`.
20
+
21
+ You can try the model by running the following command:
22
+ ```
23
+ python generate_openelm.py --model apple/OpenELM-270M-Instruct --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2
24
+ ```
25
+ Please refer to [this link](https://huggingface.co/docs/hub/security-tokens) to obtain your hugging face access token.
26
+
27
+ 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:
28
+ ```
29
+ python generate_openelm.py --model apple/OpenELM-270M-Instruct --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 prompt_lookup_num_tokens=10
30
+ ```
31
+ 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:
32
+ ```
33
+ python generate_openelm.py --model apple/OpenELM-270M-Instruct --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 --assistant_model [SMALLER_MODEL]
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  ```
35
 
36