OpenELM 是 Apple 开源的高效语言模型系列,特点:
projects/openelm)模型权重(本地)
+ 推理代码(本地)
+ Python 环境(本地)
= 完全离线推理pip install transformers torch sentencepiece
huggingface-cli download apple/OpenELM-270M --local-dir OpenELM-270M将以下文件拷贝到离线机器:
OpenELM-270M/
├── config.json
├── tokenizer.model
├── tokenizer_config.json
├── pytorch_model.binfrom transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "./OpenELM-270M"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path)
input_text = "The capital of France is"
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, max_length=50)
print(tokenizer.decode(outputs[0]))git clone https://github.com/apple/corenet
cd corenet
pip install -e .官方权重示例(需提前下载):
openelm-270M-instruct.ptpython projects/openelm/eval.py \
--model.weight path/to/openelm-270M.pt \
--text "Hello world"| 环境 | 支持情况 |
|---|---|
| CPU | ✅ |
| CUDA GPU | ✅ |
| Mac M1/M2 | ✅(MPS) |
| 树莓派 | ⚠️(仅 270M) |
Mac 示例:
model.to("mps")✅ 解决:确保 tokenizer.model 在本地
✅ 解决:
transformers.utils.logging.set_verbosity_error()openelm_offline/
├── model/
├── inference.py
├── requirements.txtrequirements.txt
torch
transformers
sentencepiece我可以进一步提供:
你打算用在什么设备 / 场景?