Instructions to use apple/OpenELM-3B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use apple/OpenELM-3B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="apple/OpenELM-3B-Instruct", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("apple/OpenELM-3B-Instruct", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use apple/OpenELM-3B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "apple/OpenELM-3B-Instruct" # 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-Instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/apple/OpenELM-3B-Instruct
- SGLang
How to use apple/OpenELM-3B-Instruct 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-Instruct" \ --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-Instruct", "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-Instruct" \ --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-Instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use apple/OpenELM-3B-Instruct with Docker Model Runner:
docker model run hf.co/apple/OpenELM-3B-Instruct
Mahyar Najibi commited on
Commit ·
25f115c
1
Parent(s): 1a81796
Update README
Browse files- README.md +3 -3
- generate_openelm.py +5 -0
README.md
CHANGED
|
@@ -20,17 +20,17 @@ We have provided an example function to generate output from OpenELM models load
|
|
| 20 |
|
| 21 |
You can try the model by running the following command:
|
| 22 |
```
|
| 23 |
-
python generate_openelm.py --model apple/OpenELM-3B --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-3B --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-3B --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 --assistant_model apple/OpenELM-270M
|
| 34 |
```
|
| 35 |
|
| 36 |
|
|
|
|
| 20 |
|
| 21 |
You can try the model by running the following command:
|
| 22 |
```
|
| 23 |
+
python generate_openelm.py --model apple/OpenELM-3B-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-3B-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-3B-Instruct --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 --assistant_model apple/OpenELM-270M-Instruct
|
| 34 |
```
|
| 35 |
|
| 36 |
|
generate_openelm.py
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""Module to generate OpenELM output given a model and an input prompt."""
|
| 2 |
import os
|
| 3 |
import logging
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# For licensing see accompanying LICENSE file.
|
| 3 |
+
# Copyright (C) 2024 Apple Inc. All Rights Reserved.
|
| 4 |
+
#
|
| 5 |
+
|
| 6 |
"""Module to generate OpenELM output given a model and an input prompt."""
|
| 7 |
import os
|
| 8 |
import logging
|