Instructions to use apple/OpenELM-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use apple/OpenELM-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="apple/OpenELM-3B", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("apple/OpenELM-3B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use apple/OpenELM-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "apple/OpenELM-3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "apple/OpenELM-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/apple/OpenELM-3B
- SGLang
How to use apple/OpenELM-3B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "apple/OpenELM-3B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "apple/OpenELM-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "apple/OpenELM-3B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "apple/OpenELM-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use apple/OpenELM-3B with Docker Model Runner:
docker model run hf.co/apple/OpenELM-3B
Mahyar Najibi commited on
Commit ·
1186dc1
1
Parent(s): 200856b
Updating README.md to include example usage.
Browse files
README.md
CHANGED
|
@@ -16,35 +16,23 @@ Our pre-training dataset contains RefinedWeb, deduplicated PILE, a subset of Red
|
|
| 16 |
|
| 17 |
## Usage
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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 |
|
| 50 |
## Main Results
|
|
|
|
| 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 --checkpoint apple/OpenELM-3B --hf_security_token [HF_SECURITY_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs no_repeat_ngram_size=10
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
Additional arguments to the huggingface 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:
|
| 27 |
+
```
|
| 28 |
+
python generate_openelm.py --checkpoint apple/OpenELM-3B --hf_security_token [HF_SECURITY_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs no_repeat_ngram_size=10 prompt_lookup_num_tokens=10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
```
|
| 30 |
+
Alternatively, model-wise speculative generation can be also tried by passing a smaller model checkpoint through the `speculative_model_ckpt` argument, for example:
|
| 31 |
+
```
|
| 32 |
+
python generate_openelm.py --checkpoint apple/OpenELM-3B --hf_security_token [HF_SECURITY_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs no_repeat_ngram_size=10 --speculative_model_ckpt apple/OpenELM-270M
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
|
| 36 |
|
| 37 |
|
| 38 |
## Main Results
|