验证:
python --versionvenvpython -m venv openelm_env
source openelm_env/bin/activatecondaconda create -n openelm python=3.10
conda activate openelmgit clone https://github.com/apple/corenet.git
cd corenetOpenELM 模型代码位于 corenet/models/language_modeling/openelm/pip install --upgrade pip
pip install torch torchvision torchaudiopip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121pip install -e .或手动安装常见依赖:
pip install transformers tokenizers sentencepiece numpy tqdmpip install huggingface_hub下载模型(示例:270M 参数):
huggingface-cli download apple/OpenELM-270M-Instruct --local-dir openelm-270m常用模型:
| 模型 | HuggingFace |
|---|---|
| 270M | apple/OpenELM-270M |
| 450M | apple/OpenELM-450M |
| 1B | apple/OpenELM-1B |
| 3B | apple/OpenELM-3B |
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "apple/OpenELM-270M-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path)
prompt = "What is OpenELM?"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=100)
print(tokenizer.decode(outputs[0]))python scripts/eval/eval_lm.py \
--model openelm \
--model.weights openelm-270m/pytorch_model.bin \
--dataset.text.test data/sample.txtpip install accelerate deepspeed bitsandbytespip install peft示例:
from peft import LoraConfig, get_peft_model✅ 非常适合
pip install torch(MPS 支持)| 模型 | 最低显存 |
|---|---|
| 270M | 4GB |
| 450M | 6GB |
| 1B | 10GB |
| 3B | 16GB+ |
✅ 最推荐组合
如果你愿意,我可以:
直接告诉我你的 系统 + 是否有 GPU 即可。