
InternLM
开箱即用的中文大模型,从预训练到部署全流程搞定
项目预览
项目数据
项目介绍
Star 增长趋势
本站每日记录该项目 GitHub 星标变化,观测越久曲线越完整
数据来源:GitHub API 逐日快照 · 收录于 2026-08-09 · 当前星标 ★ 7277
使用教程
环境要求
- Python 环境(用于运行 LMDeploy / Ollama 的 Python 调用代码)
- 已安装 pip,可执行 pip install
- 能够访问 HuggingFace 下载 internlm/internlm3-8b-instruct 模型权重
- 若使用 Ollama 方案,需先安装 Ollama 运行时
安装与启动步骤
-
1安装 LMDeploy
LMDeploy 是官方推荐的压缩、部署与服务化工具包,用一条 pip 命令安装即可,建议在独立虚拟环境中执行。
pip install lmdeploy -
2本地批量推理
用 LMDeploy 的 pipeline 直接加载模型并提问,脚本会自动从 HuggingFace 拉取权重,首次运行需等待下载完成。
import lmdeploy model_dir = "internlm/internlm3-8b-instruct" pipe = lmdeploy.pipeline(model_dir) response = pipe("Please tell me five scenic spots in Shanghai") print(response) -
3启动兼容 API 服务
启动 OpenAI 兼容的推理服务,--model-name 用于指定请求时使用的模型名,--server-port 指定监听端口。
lmdeploy serve api_server internlm/internlm3-8b-instruct --model-name internlm3-8b-instruct --server-port 23333 -
4发起对话请求
服务启动后,用 curl 向本地 23333 端口发送 chat/completions 请求,注意 model 字段要与启动时的 --model-name 保持一致。
curl http://localhost:23333/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "internlm3-8b-instruct", "messages": [ {"role": "user", "content": "Please tell me five scenic spots in Shanghai"} ] }' -
5安装 Ollama 方案
另一种更轻量的本地运行方式:先用官方脚本安装 Ollama,再安装 ollama 的 Python 客户端库。
curl -fsSL https://ollama.com/install.sh | sh pip install ollama -
6Ollama 流式推理
通过 ollama.chat 指定 model 为 internlm/internlm3-8b-instruct,开启 stream 逐块打印模型回复内容。
import ollama system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语). - InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless. - InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文.""" messages = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": "Please tell me five scenic spots in Shanghai"} ] stream = ollama.chat( model='internlm/internlm3-8b-instruct', messages=messages, stream=True, ) for chunk in stream: print(chunk['message']['content'], end='', flush=True)
关键配置
| 配置项 | 必填 | 说明 | 示例 |
|---|---|---|---|
model_dir | 是 | 模型权重目录或 HuggingFace 仓库名,LMDeploy 据此加载模型 | internlm/internlm3-8b-instruct |
--model-name | 否 | API 服务对外暴露的模型名称,需与请求体 model 字段一致 | internlm3-8b-instruct |
--server-port | 否 | OpenAI 兼容服务的监听端口 | 23333 |
num_ctx | 否 | Ollama 调用的上下文窗口长度 | 8192 |
num_predict | 否 | Ollama 调用的最大生成 token 数 | 2048 |
如何确认成功
API 服务启动后,curl 请求返回包含模型回复的 JSON;或在 Python 中运行 pipeline,终端打印出上海五个景点即成功。
常见问题
Q:curl 请求报模型名不存在怎么办?
A:检查请求体中的 model 字段是否与启动服务时 --model-name 的值完全一致,示例中为 internlm3-8b-instruct。
Q:如何让模型支持更长上下文?
A:使用 Ollama 调用时可通过 options 传入 num_ctx 参数,README 示例中设置为 8192。
Q:LMDeploy 和 Ollama 两种方式该选哪个?
A:LMDeploy 适合批量推理和自建 OpenAI 兼容服务;Ollama 安装更轻量,适合本地快速对话体验。可任选其一。
Q:首次运行很慢是正常的吗?
A:正常。首次运行会自动下载模型权重,体积较大,需要等待下载完成后再进行推理。
注意事项
- README 中所有示例模型均为 internlm/internlm3-8b-instruct,替换模型时需同步修改服务名与请求体。
- Ollama 方案需先执行安装脚本安装 Ollama 运行时,再安装 Python 客户端 ollama。
- Python 示例中的 thinking_system_prompt 变量 README 未给出定义,实际使用时需自行补充系统提示词。
- 官方还提供在线 Chat Web 与 API 文档链接,可先体验再决定是否本地部署。
核心亮点
- 多版本迭代成熟,从基础版到长上下文版覆盖不同需求
- 中文能力突出,在中文理解和生成任务上表现优于同量级模型
- 提供完整的训练和推理工具链,支持微调和 RLHF,便于定制
不足之处
- 文档和社区生态相对国际主流项目(如 LLaMA)仍有差距
- 部分高级功能依赖特定硬件或库,部署门槛略高
适用场景
- 中文对话助手和客服系统开发
- 企业私有化大模型部署与微调
- 学术研究中的模型对比和实验
替代项目
LLaMA、ChatGLM、Qwen
同类项目推荐
Awesome_Multimodel_LLM
开源
一站式收藏多模态大模型资源,快速跟上最新进展
Awesome_Multimodel is a curated GitHub repository that provides a comprehensive coll···
Mobile-O
开源
让手机原生跑通多模态AI,离线也能理解与生成图像。
[CVPR'26 Demo] Mobile-O: Unified Multimodal Understanding and Generation on Mobile D···
laya
开源
一次前向传播,把任意文本变成选择、评分和是/否判断
Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decision···
awesome-ltx2
开源
找齐 LTX-2 模型、工作流和 LoRA,一键上手视频生成。
All available LTX-2 models, encoders, workflows, LoRAs for ComfyUI
awesome-AI-toolkit
开源
一站式找齐AI工具、框架、数据集和论文
A curated, comprehensive collection of open-source AI tools, frameworks, datasets, c···
awesome-controlnet
开源
一站式收集 ControlNet 资源,快速上手精准可控的图像生成
Awesome repo for ControlNet
sealion
开源
让大模型真正听懂东南亚多国语言
South-East Asia Large Language Models
Bootstrap3D
开源
用合成数据训练多视图扩散模型,让 3D 生成更稳更准
[ICCV-2025] Official implementation of Bootstrap3D: Improving Multi-view Diffusion M···
Yi
开源
中文大模型新选择,从零训练性能强,拿来即用可微调
A series of large language models trained from scratch by developers @01-ai