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
NotImplementedError: Cannot copy out of meta tensor; no data!
decoder_model = AutoModelForCausalLM.from_pretrained(
"apple/OpenELM-270M",
torch_dtype=torch.float32,
trust_remote_code=True,
)
leads to
File "/tmp/.xdg_cache_kalvinchang/huggingface/modules/transformers_modules/apple/OpenELM_hyphen_270M/e2b9003235d55a404567faf06e74883081c65e65/modeling_openelm.py", line 808, in init
self.transformer = OpenELMModel(config)
File "/tmp/.xdg_cache_kalvinchang/huggingface/modules/transformers_modules/apple/OpenELM_hyphen_270M/e2b9003235d55a404567faf06e74883081c65e65/modeling_openelm.py", line 548, in init
self.layers = nn.ModuleList(
File "/scratch/users/kalvinchang/conda/envs/flow-slm/lib/python3.10/site-packages/torch/nn/modules/container.py", line 364, in init
self += modules
File "/scratch/users/kalvinchang/conda/envs/flow-slm/lib/python3.10/site-packages/torch/nn/modules/container.py", line 413, in iadd
return self.extend(modules)
File "/scratch/users/kalvinchang/conda/envs/flow-slm/lib/python3.10/site-packages/torch/nn/modules/container.py", line 498, in extend
for i, module in enumerate(modules):
File "/tmp/.xdg_cache_kalvinchang/huggingface/modules/transformers_modules/apple/OpenELM_hyphen_270M/e2b9003235d55a404567faf06e74883081c65e65/modeling_openelm.py", line 549, in
OpenELMDecoderLayer(config=config, layer_idx=layer_idx)
File "/tmp/.xdg_cache_kalvinchang/huggingface/modules/transformers_modules/apple/OpenELM_hyphen_270M/e2b9003235d55a404567faf06e74883081c65e65/modeling_openelm.py", line 468, in init
self.attn = OpenELMMultiHeadCausalAttention(config=config, layer_idx=layer_idx)
File "/tmp/.xdg_cache_kalvinchang/huggingface/modules/transformers_modules/apple/OpenELM_hyphen_270M/e2b9003235d55a404567faf06e74883081c65e65/modeling_openelm.py", line 278, in init
self.pos_embedding = OpenELMRotaryEmbedding(
File "/tmp/.xdg_cache_kalvinchang/huggingface/modules/transformers_modules/apple/OpenELM_hyphen_270M/e2b9003235d55a404567faf06e74883081c65e65/modeling_openelm.py", line 146, in init
self._compute_sin_cos_embeddings(max_seq_length)
File "/tmp/.xdg_cache_kalvinchang/huggingface/modules/transformers_modules/apple/OpenELM_hyphen_270M/e2b9003235d55a404567faf06e74883081c65e65/modeling_openelm.py", line 197, in _compute_sin_cos_embeddings
cos_emb = emb.cos().to(dtype=key_dtype, device=key_device)
File "/scratch/users/kalvinchang/conda/envs/flow-slm/lib/python3.10/site-packages/torch/utils/_device.py", line 109, in torch_function
return func(*args, **kwargs)
NotImplementedError: Cannot copy out of meta tensor; no data!
The solution (as found by https://github.com/Cicicai379) is to comment out
self._compute_sin_cos_embeddings(max_seq_length) in the initialization