Instructions to use apple/OpenELM-270M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use apple/OpenELM-270M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="apple/OpenELM-270M", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("apple/OpenELM-270M", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use apple/OpenELM-270M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "apple/OpenELM-270M" # 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-270M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/apple/OpenELM-270M
- SGLang
How to use apple/OpenELM-270M 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-270M" \ --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-270M", "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-270M" \ --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-270M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use apple/OpenELM-270M with Docker Model Runner:
docker model run hf.co/apple/OpenELM-270M
Is it possible to port from .mlpackage to .mlmodelc
Hi, maybe I am not using the right tools to try porting this model to run locally on iOS/iPadOS, trying to port from ml package to ml modelc.
I'd tried to run xcrun coremlcompiler compile OpenELM-270M-128-float32.mlpackage . which returns an error -> "coremlcompiler: error: compiler error: Encountered an error while compiling a neural network model: Failed to set owner and group on copied weights during compilation. Error description: The file “weight.bin” doesn’t exist.",
I see the weights of the model in a different folder and not as a single .bin file as the compiler requires, any help with this regard would be much appreciated.
Thanks in advance.
Pedro, thank you so much for your fast reply, I did download the models using the hugging face CLI tool but I'll try your suggestion, I was trying to mimic the structure in the SwiftChat app that looks for compiled models (also I did the same a few years ago with Stable Diffusion only got it working with the compiled versions).
Best regards.
Jorge.
Open the .mlpackage you downloaded, locate the weight.bin shortcut, right-click on it and select “Show Original.” Find the original file, copy it to the same directory as the weight.bin shortcut, and then delete the weight.bin shortcut. Rename the original file to weight.bin. Finally, import the .mlpackage into Xcode, and it should compile successfully.