[
    {
      "question": "[捂脸]几年前用大恒的工业相机，还得用他们的SDK，还没arm的版本，最后让他们编了一个arm的用",
      "part": " 快速上手 部署 internlm #### 获取 internlm 模型  \n#### 使用 turbomind 推理  \n> **note**<br />\n> turbomind 在使用 fp16 精度推理 internlm-7b 模型时，显存开销至少需要 15.7g。建议使用 3090, v100，a100等型号的显卡。<br />\n> 关闭显卡的 ecc 可以腾出 10% 显存，执行 `sudo nvidia-smi --ecc-config=0` 重启系统生效。  \n> **note**<br />\n> 使用 tensor 并发可以利用多张 gpu 进行推理。在 `chat` 时添加参数 `--tp=<num_gpu>` 可以启动运行时 tp。  \n#### 启动 gradio server  \n!  \n#### 通过 restful api 部署服务  \n使用下面的命令启动推理服务：  \n你可以通过命令行方式与推理服务进行对话：  \n也可以通过 webui 方式来对话：  \n更多详情可以查阅 restful_api.md。  \n#### 通过容器部署推理服务  \n使用下面的命令启动推理服务：  \n你可以通过命令行方式与推理服务进行对话：  \n也可以通过 webui 方式来对话：  \n其他模型的部署方式，比如 llama，llama-2，vicuna等等，请参考这里",
      "full": "<div align=\"center\">\n  <img src=\"resources/lmdeploy-logo.png\" width=\"450\"/>\n\n[![docs](https://img.shields.io/badge/docs-latest-blue)](https://lmdeploy-zh-cn.readthedocs.io/zh_CN/latest/)\n[![badge](https://github.com/InternLM/lmdeploy/workflows/lint/badge.svg)](https://github.com/InternLM/lmdeploy/actions)\n[![PyPI](https://img.shields.io/pypi/v/lmdeploy)](https://pypi.org/project/lmdeploy)\n[![license](https://img.shields.io/github/license/InternLM/lmdeploy.svg)](https://github.com/InternLM/lmdeploy/tree/main/LICENSE)\n[![issue resolution](https://img.shields.io/github/issues-closed-raw/InternLM/lmdeploy)](https://github.com/InternLM/lmdeploy/issues)\n[![open issues](https://img.shields.io/github/issues-raw/InternLM/lmdeploy)](https://github.com/InternLM/lmdeploy/issues)\n\n[English](README.md) | 简体中文\n\n</div>\n\n<p align=\"center\">\n    👋 join us on <a href=\"https://twitter.com/intern_lm\" target=\"_blank\">Twitter</a>, <a href=\"https://discord.gg/xa29JuW87d\" target=\"_blank\">Discord</a> and <a href=\"https://r.vansin.top/?r=internwx\" target=\"_blank\">WeChat</a>\n</p>\n\n______________________________________________________________________\n\n## 更新 🎉\n\n- \\[2023/08\\] TurboMind 支持 Qwen-7B，动态NTK-RoPE缩放，动态logN缩放\n- \\[2023/08\\] TurboMind 支持 Windows (tp=1)\n- \\[2023/08\\] TurboMind 支持 4-bit 推理，速度是 FP16 的 2.4 倍，是目前最快的开源实现🚀。部署方式请看[这里](./docs/zh_cn/w4a16.md)\n- \\[2023/08\\] LMDeploy 开通了 [HuggingFace Hub](https://huggingface.co/lmdeploy) ，提供开箱即用的 4-bit 模型\n- \\[2023/08\\] LMDeploy 支持使用 [AWQ](https://arxiv.org/abs/2306.00978) 算法进行 4-bit 量化\n- \\[2023/07\\] TurboMind 支持使用 GQA 的 Llama-2 70B 模型\n- \\[2023/07\\] TurboMind 支持 Llama-2 7B/13B 模型\n- \\[2023/07\\] TurboMind 支持 InternLM 的 Tensor Parallel 推理\n\n______________________________________________________________________\n\n## 简介\n\nLMDeploy 由 [MMDeploy](https://github.com/open-mmlab/mmdeploy) 和 [MMRazor](https://github.com/open-mmlab/mmrazor) 团队联合开发，是涵盖了 LLM 任务的全套轻量化、部署和服务解决方案。\n这个强大的工具箱提供以下核心功能：\n\n- **高效推理引擎 TurboMind**：基于 [FasterTransformer](https://github.com/NVIDIA/FasterTransformer)，我们实现了高效推理引擎 TurboMind，支持 InternLM、LLaMA、vicuna等模型在 NVIDIA GPU 上的推理。\n\n- **交互推理方式**：通过缓存多轮对话过程中 attention 的 k/v，记住对话历史，从而避免重复处理历史会话。\n\n- **多 GPU 部署和量化**：我们提供了全面的模型部署和量化支持，已在不同规模上完成验证。\n\n- **persistent batch 推理**：进一步优化模型执行效率。\n\n  ![PersistentBatchInference](https://github.com/InternLM/lmdeploy/assets/67539920/e3876167-0671-44fc-ac52-5a0f9382493e)\n\n## 支持的模型\n\n`LMDeploy` 支持 `TurboMind` 和 `Pytorch` 两种推理后端\n\n### TurboMind\n\n> **Note**<br />\n> W4A16 推理需要 Ampere 及以上架构的 Nvidia GPU\n\n|   模型   | 模型并行 | FP16 | KV INT8 | W4A16 | W8A8 |\n| :------: | :------: | :--: | :-----: | :---: | :--: |\n|  Llama   |   Yes    | Yes  |   Yes   |  Yes  |  No  |\n|  Llama2  |   Yes    | Yes  |   Yes   |  Yes  |  No  |\n| InternLM |   Yes    | Yes  |   Yes   |  Yes  |  No  |\n\n### Pytorch\n\n|   模型   | 模型并行 | FP16 | KV INT8 | W4A16 | W8A8 |\n| :------: | :------: | :--: | :-----: | :---: | :--: |\n|  Llama   |   Yes    | Yes  |   No    |  No   |  No  |\n|  Llama2  |   Yes    | Yes  |   No    |  No   |  No  |\n| InternLM |   Yes    | Yes  |   No    |  No   |  No  |\n\n## 性能\n\n**场景一**: 固定的输入、输出token数（1,2048），测试 output token throughput\n\n**场景二**: 使用真实数据，测试 request throughput\n\n测试配置：LLaMA-7B, NVIDIA A100(80G)\n\nTurboMind 的 output token throughput 超过 2000 token/s, 整体比 DeepSpeed 提升约 5% - 15%，比 huggingface transformers 提升 2.3 倍\n在 request throughput 指标上，TurboMind 的效率比 vLLM 高 30%\n\n![benchmark](https://github.com/InternLM/lmdeploy/assets/4560679/7775c518-608e-4e5b-be73-7645a444e774)\n\n## 快速上手\n\n### 安装\n\n使用 pip ( python 3.8+) 安装 LMDeploy，或者[源码安装](./docs/zh_cn/build.md)\n\n```shell\npip install lmdeploy\n```\n\n### 部署 InternLM\n\n#### 获取 InternLM 模型\n\n```shell\n# 1. 下载 InternLM 模型\n\n# Make sure you have git-lfs installed (https://git-lfs.com)\ngit lfs install\ngit clone https://huggingface.co/internlm/internlm-chat-7b /path/to/internlm-chat-7b\n\n# if you want to clone without large files – just their pointers\n# prepend your git clone with the following env var:\nGIT_LFS_SKIP_SMUDGE=1\n\n# 2. 转换为 trubomind 要求的格式。默认存放路径为 ./workspace\npython3 -m lmdeploy.serve.turbomind.deploy internlm-chat-7b /path/to/internlm-chat-7b\n\n```\n\n#### 使用 turbomind 推理\n\n```shell\npython3 -m lmdeploy.turbomind.chat ./workspace\n```\n\n> **Note**<br />\n> turbomind 在使用 FP16 精度推理 InternLM-7B 模型时，显存开销至少需要 15.7G。建议使用 3090, V100，A100等型号的显卡。<br />\n> 关闭显卡的 ECC 可以腾出 10% 显存，执行 `sudo nvidia-smi --ecc-config=0` 重启系统生效。\n\n> **Note**<br />\n> 使用 Tensor 并发可以利用多张 GPU 进行推理。在 `chat` 时添加参数 `--tp=<num_gpu>` 可以启动运行时 TP。\n\n#### 启动 gradio server\n\n```shell\npython3 -m lmdeploy.serve.gradio.app ./workspace\n```\n\n![](https://github.com/InternLM/lmdeploy/assets/67539920/08d1e6f2-3767-44d5-8654-c85767cec2ab)\n\n#### 通过 Restful API 部署服务\n\n使用下面的命令启动推理服务：\n\n```shell\npython3 -m lmdeploy.serve.openai.api_server ./workspace server_ip server_port --instance_num 32 --tp 1\n```\n\n你可以通过命令行方式与推理服务进行对话：\n\n```shell\n# restful_api_url is what printed in api_server.py, e.g. http://localhost:23333\npython -m lmdeploy.serve.openai.api_client restful_api_url\n```\n\n也可以通过 WebUI 方式来对话：\n\n```shell\n# restful_api_url is what printed in api_server.py, e.g. http://localhost:23333\n# server_ip and server_port here are for gradio ui\n# example: python -m lmdeploy.serve.gradio.app http://localhost:23333 localhost 6006 --restful_api True\npython -m lmdeploy.serve.gradio.app restful_api_url server_ip --restful_api True\n```\n\n更多详情可以查阅 [restful_api.md](docs/zh_cn/restful_api.md)。\n\n#### 通过容器部署推理服务\n\n使用下面的命令启动推理服务：\n\n```shell\nbash workspace/service_docker_up.sh\n```\n\n你可以通过命令行方式与推理服务进行对话：\n\n```shell\npython3 -m lmdeploy.serve.client {server_ip_addresss}:33337\n```\n\n也可以通过 WebUI 方式来对话：\n\n```shell\npython3 -m lmdeploy.serve.gradio.app {server_ip_addresss}:33337\n```\n\n其他模型的部署方式，比如 LLaMA，LLaMA-2，vicuna等等，请参考[这里](docs/zh_cn/serving.md)\n\n### 基于 PyTorch 的推理\n\n你必须确保环境中有安装 deepspeed：\n\n```\npip install deepspeed\n```\n\n#### 单个 GPU\n\n```shell\npython3 -m lmdeploy.pytorch.chat $NAME_OR_PATH_TO_HF_MODEL\\\n    --max_new_tokens 64 \\\n    --temperture 0.8 \\\n    --top_p 0.95 \\\n    --seed 0\n```\n\n#### 使用 DeepSpeed 实现张量并行\n\n```shell\ndeepspeed --module --num_gpus 2 lmdeploy.pytorch.chat \\\n    $NAME_OR_PATH_TO_HF_MODEL \\\n    --max_new_tokens 64 \\\n    --temperture 0.8 \\\n    --top_p 0.95 \\\n    --seed 0\n```\n\n## 量化部署\n\n### Step 1. 获取量化参数\n\n首先，执行量化脚本，获取量化参数\n\n> 执行后，量化需要的各种参数会存放在 $WORK_DIR 中; 接下来的步骤中会用到\n\n```\n\npython3 -m lmdeploy.lite.apis.calibrate \\\n  --model $HF_MODEL \\\n  --calib_dataset 'c4' \\             # 校准数据集，支持 c4, ptb, wikitext2, pileval\n  --calib_samples 128 \\              # 校准集的样本数，如果显存不够，可以适当调小\n  --calib_seqlen 2048 \\              # 单条的文本长度，如果显存不够，可以适当调小\n  --work_dir $WORK_DIR \\             # 保存 Pytorch 格式量化统计参数和量化后权重的文件夹\n```\n\n### Step 2. 实际量化模型\n\n目前支持对权重的 INT4 量化和 KV Cache 的 INT8 量化，根据需求执行对应脚本即可\n\n#### 权重 INT4 量化\n\nLMDeploy 使用 [AWQ](https://arxiv.org/abs/2306.00978) 算法对模型权重进行量化\n\n> 需要输入第一步的 \\`$WORK_DIR\\`\\` ，量化后的权重也会存在这个文件夹中\n\n```\npython3 -m lmdeploy.lite.apis.auto_awq \\\n  --model $HF_MODEL \\\n  --w_bits 4 \\                       # 权重量化的 bit 数\n  --w_group_size 128 \\               # 权重量化分组统计尺寸\n  --work_dir $WORK_DIR \\             # Step 1 保存量化参数的目录\n```\n\n[点击这里](./docs/zh_cn/w4a16.md) 查看 weight int4 用法测试结果。\n\n#### KV Cache INT8 量化\n\n[点击这里](./docs/zh_cn/kv_int8.md) 查看 kv int8 使用方法、实现公式和测试结果。\n\n> **Warning**<br />\n> 量化部署不支持运行时 Tensor 并发。如果希望使用 Tensor 并发，需要在 deploy 时配置 tp 参数。\n\n## 贡献指南\n\n我们感谢所有的贡献者为改进和提升 LMDeploy 所作出的努力。请参考[贡献指南](.github/CONTRIBUTING.md)来了解参与项目贡献的相关指引。\n\n## 致谢\n\n- [FasterTransformer](https://github.com/NVIDIA/FasterTransformer)\n- [llm-awq](https://github.com/mit-han-lab/llm-awq)\n\n## License\n\n该项目采用 [Apache 2.0 开源许可证](LICENSE)。\n"
    }
]
