建议使用 Python 3.10 或 3.11
验证:
python --version如果你有 NVIDIA 显卡:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121仅 CPU:
pip install torch torchvision torchaudiopip install transformers sentencepiece numpyOpenELM 已支持 Hugging Face:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "apple/OpenELM-270M"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype="auto"
)
prompt = "The capital of France is"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))git clone https://github.com/apple/corenet.git
cd corenet
pip install -e .从 Hugging Face 下载:
https://huggingface.co/apple/OpenELM-270M官方示例(简化):
python -m corenet.modeling.openelm.generate \
--model apple/OpenELM-270M \
--prompt "Hello, my name is"⚠️ Windows 下可能遇到路径 / shell 问题,建议用 PowerShell 或 WSL
Windows + WSL2 + Ubuntu
libomp 报错 → 安装 Visual C++ Redistributable| 模型 | 显存需求 |
|---|---|
| OpenELM-270M | ~1GB |
| OpenELM-450M | ~2GB |
| OpenELM-1.1B | ~4GB |
| OpenELM-3B | ~8GB+ |
我可以直接给你 一键可跑的 Windows 脚本。