curl -fsSL https://ollama.com/install.sh | shollama run llama3✅ 默认是 llama3:8b
✅ 自动下载、自动运行
✅ 直接进对话界面
ollama run llama3:8b
ollama run llama3:70b适合:
sudo apt update
sudo apt install -y python3 python3-pip git建议用 conda:
conda create -n llama3 python=3.10
conda activate llama3pip install torch transformers accelerateGPU 用户(CUDA 12):
pip install torch --index-url https://download.pytorch.org/whl/cu121需要 Hugging Face 账号 + 申请访问权限
huggingface-cli login模型示例:
meta-llama/Meta-Llama-3-8B-Instructmeta-llama/Meta-Llama-3-70B-Instruct下载:
git lfs install
git clone https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instructfrom transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "./Meta-Llama-3-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
prompt = "介绍一下 Linux"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=200)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))nvidia-smi能看到 GPU 就行
✅ 可以
| 需求 | 推荐方式 |
|---|---|
| 只想本地聊天 | ✅ Ollama |
| 学习 / 开发 | ✅ transformers |
| 高性能推理 | ✅ vLLM |
| 中文优化 | ✅ Ollama + 中文 prompt |
如果你愿意,我可以:
你现在是 服务器 / 笔记本 / 台式机?有没有 GPU?