Home
Softono
i

internlm

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
5

Software by internlm

lmdeploy
Open Source

lmdeploy

<div align="center"> <img src="docs/en/_static/image/lmdeploy-logo.svg" width="450"/> [![PyPI](https://img.shields.io/pypi/v/lmdeploy)](https://pypi.org/project/lmdeploy) ![PyPI - Downloads](https://img.shields.io/pypi/dm/lmdeploy) [![license](https://img.shields.io/github/license/InternLM/lmdeploy.svg)](https://github.com/InternLM/lmdeploy/tree/main/LICENSE) [![issue resolution](https://img.shields.io/github/issues-closed-raw/InternLM/lmdeploy)](https://github.com/InternLM/lmdeploy/issues) [![open issues](https://img.shields.io/github/issues-raw/InternLM/lmdeploy)](https://github.com/InternLM/lmdeploy/issues) [📘Documentation](https://lmdeploy.readthedocs.io/en/latest/) | [🛠️Quick Start](https://lmdeploy.readthedocs.io/en/latest/get_started/get_started.html) | [🤔Reporting Issues](https://github.com/InternLM/lmdeploy/issues/new/choose) English | [简体中文](README_zh-CN.md) | [日本語](README_ja.md) 👋 join us on [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=wechat&label=WeChat)](https://cdn.vansin.top/internlm/lmdeploy.jpg) [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=twitter&label=Twitter)](https://twitter.com/intern_lm) [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=discord&label=Discord)](https://discord.gg/xa29JuW87d) </div> ______________________________________________________________________ ## Latest News 🎉 <details open> <summary><b>2026</b></summary> - \[2026/04\] PyPI has expanded the storage quota for LMDeploy and wheel uploads have resumed. `v0.12.3` is now available on PyPI, so you can install it directly via `pip install lmdeploy`. - \[2026/02\] Support [Qwen3.5](https://huggingface.co/collections/Qwen/qwen35) - \[2026/02\] Support [vllm-project/llm-compressor](https://github.com/vllm-project/llm-compressor) 4bit symmetric/asymmetric quantization. Refer [here](./docs/en/quantization/llm_compressor.md) for detailed guide </details> <details close> <summary><b>2025</b></summary> - \[2025/09\] TurboMind supports MXFP4 on NVIDIA GPUs starting from V100, achieving 1.5x the performmance of vLLM on H800 for openai gpt-oss models! - \[2025/06\] Comprehensive inference optimization for FP8 MoE Models - \[2025/06\] DeepSeek PD Disaggregation deployment is now supported through integration with [DLSlime](https://github.com/DeepLink-org/DLSlime) and [Mooncake](https://github.com/kvcache-ai/Mooncake). Huge thanks to both teams! - \[2025/04\] Enhance DeepSeek inference performance by integration deepseek-ai techniques: FlashMLA, DeepGemm, DeepEP, MicroBatch and eplb - \[2025/01\] Support DeepSeek V3 and R1 </details> <details close> <summary><b>2024</b></summary> - \[2024/11\] Support Mono-InternVL with PyTorch engine - \[2024/10\] PyTorchEngine supports graph mode on ascend platform, doubling the inference speed - \[2024/09\] LMDeploy PyTorchEngine adds support for [Huawei Ascend](./docs/en/get_started/ascend/get_started.md). See supported models [here](docs/en/supported_models/supported_models.md) - \[2024/09\] LMDeploy PyTorchEngine achieves 1.3x faster on Llama3-8B inference by introducing CUDA graph - \[2024/08\] LMDeploy is integrated into [modelscope/swift](https://github.com/modelscope/swift) as the default accelerator for VLMs inference - \[2024/07\] Support Llama3.1 8B, 70B and its TOOLS CALLING - \[2024/07\] Support [InternVL2](docs/en/multi_modal/internvl.md) full-series models, [InternLM-XComposer2.5](docs/en/multi_modal/xcomposer2d5.md) and [function call](docs/en/llm/api_server_tools.md) of InternLM2.5 - \[2024/06\] PyTorch engine support DeepSeek-V2 and several VLMs, such as CogVLM2, Mini-InternVL, LlaVA-Next - \[2024/05\] Balance vision model when deploying VLMs with multiple GPUs - \[2024/05\] Support 4-bits weight-only quantization and inference on VLMs, such as InternVL v1.5, LLaVa, InternLMXComposer2 - \[2024/04\] Support Llama3 and more VLMs, such as InternVL v1.1, v1.2, MiniGemini, InternLMXComposer2. - \[2024/04\] TurboMind adds online int8/int4 KV cache quantization and inference for all supported devices. Refer [here](docs/en/quantization/kv_quant.md) for detailed guide - \[2024/04\] TurboMind latest upgrade boosts GQA, rocketing the [internlm2-20b](https://huggingface.co/internlm/internlm2-20b) model inference to 16+ RPS, about 1.8x faster than vLLM. - \[2024/04\] Support Qwen1.5-MOE and dbrx. - \[2024/03\] Support DeepSeek-VL offline inference pipeline and serving. - \[2024/03\] Support VLM offline inference pipeline and serving. - \[2024/02\] Support Qwen 1.5, Gemma, Mistral, Mixtral, Deepseek-MOE and so on. - \[2024/01\] [OpenAOE](https://github.com/InternLM/OpenAOE) seamless integration with [LMDeploy Serving Service](docs/en/llm/api_server.md). - \[2024/01\] Support for multi-model, multi-machine, multi-card inference services. For usage instructions, please refer to [here](docs/en/llm/proxy_server.md) - \[2024/01\] Support [PyTorch inference engine](./docs/en/inference/pytorch.md), developed entirely in Python, helping to lower the barriers for developers and enable rapid experimentation with new features and technologies. </details> <details close> <summary><b>2023</b></summary> - \[2023/12\] Turbomind supports multimodal input. - \[2023/11\] Turbomind supports loading hf model directly. Click [here](docs/en/inference/load_hf.md) for details. - \[2023/11\] TurboMind major upgrades, including: Paged Attention, faster attention kernels without sequence length limitation, 2x faster KV8 kernels, Split-K decoding (Flash Decoding), and W4A16 inference for sm_75 - \[2023/09\] TurboMind supports Qwen-14B - \[2023/09\] TurboMind supports InternLM-20B - \[2023/09\] TurboMind supports all features of Code Llama: code completion, infilling, chat / instruct, and python specialist. Click [here](./docs/en/llm/codellama.md) for deployment guide - \[2023/09\] TurboMind supports Baichuan2-7B - \[2023/08\] TurboMind supports flash-attention2. - \[2023/08\] TurboMind supports Qwen-7B, dynamic NTK-RoPE scaling and dynamic logN scaling - \[2023/08\] TurboMind supports Windows (tp=1) - \[2023/08\] TurboMind supports 4-bit inference, 2.4x faster than FP16, the fastest open-source implementation. Check [this](docs/en/quantization/w4a16.md) guide for detailed info - \[2023/08\] LMDeploy has launched on the [HuggingFace Hub](https://huggingface.co/lmdeploy), providing ready-to-use 4-bit models. - \[2023/08\] LMDeploy supports 4-bit quantization using the [AWQ](https://arxiv.org/abs/2306.00978) algorithm. - \[2023/07\] TurboMind supports Llama-2 70B with GQA. - \[2023/07\] TurboMind supports Llama-2 7B/13B. - \[2023/07\] TurboMind supports tensor-parallel inference of InternLM. </details> ______________________________________________________________________ # Introduction LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the [MMRazor](https://github.com/open-mmlab/mmrazor) and [MMDeploy](https://github.com/open-mmlab/mmdeploy) teams. It has the following core features: - **Efficient Inference**: LMDeploy delivers up to 1.8x higher request throughput than vLLM, by introducing key features like persistent batch(a.k.a. continuous batching), blocked KV cache, dynamic split&fuse, tensor parallelism, high-performance CUDA kernels and so on. - **Effective Quantization**: LMDeploy supports weight-only and k/v quantization, and the 4-bit inference performance is 2.4x higher than FP16. The quantization quality has been confirmed via OpenCompass evaluation. - **Effortless Distribution Server**: Leveraging the request distribution service, LMDeploy facilitates an easy and efficient deployment of multi-model services across multiple machines and cards. - **Excellent Compatibility**: LMDeploy supports [KV Cache Quant](docs/en/quantization/kv_quant.md), [AWQ](docs/en/quantization/w4a16.md) and [Automatic Prefix Caching](docs/en/inference/turbomind_config.md) to be used simultaneously. # Performance ![v0 1 0-benchmark](https://github.com/InternLM/lmdeploy/assets/4560679/8e455cf1-a792-4fa8-91a2-75df96a2a5ba) # Supported Models <table> <tbody> <tr align="center" valign="middle"> <td> <b>LLMs</b> </td> <td> <b>VLMs</b> </td> <tr valign="top"> <td align="left" valign="top"> <ul> <li>Llama (7B - 65B)</li> <li>Llama2 (7B - 70B)</li> <li>Llama3 (8B, 70B)</li> <li>Llama3.1 (8B, 70B)</li> <li>Llama3.2 (1B, 3B)</li> <li>InternLM (7B - 20B)</li> <li>InternLM2 (7B - 20B)</li> <li>InternLM3 (8B)</li> <li>InternLM2.5 (7B)</li> <li>Qwen (1.8B - 72B)</li> <li>Qwen1.5 (0.5B - 110B)</li> <li>Qwen1.5 - MoE (0.5B - 72B)</li> <li>Qwen2 (0.5B - 72B)</li> <li>Qwen2-MoE (57BA14B)</li> <li>Qwen2.5 (0.5B - 32B)</li> <li>Qwen3, Qwen3-MoE</li> <li>Qwen3-Next(80B)</li> <li>Baichuan (7B)</li> <li>Baichuan2 (7B-13B)</li> <li>Code Llama (7B - 34B)</li> <li>ChatGLM2 (6B)</li> <li>GLM-4 (9B)</li> <li>GLM-4-0414 (9B, 32B)</li> <li>CodeGeeX4 (9B)</li> <li>YI (6B-34B)</li> <li>Mistral (7B)</li> <li>DeepSeek-MoE (16B)</li> <li>DeepSeek-V2 (16B, 236B)</li> <li>DeepSeek-V2.5 (236B)</li> <li>DeepSeek-V3 (685B)</li> <li>DeepSeek-V3.2 (685B)</li> <li>Mixtral (8x7B, 8x22B)</li> <li>Gemma (2B - 7B)</li> <li>StarCoder2 (3B - 15B)</li> <li>Phi-3-mini (3.8B)</li> <li>Phi-3.5-mini (3.8B)</li> <li>Phi-3.5-MoE (16x3.8B)</li> <li>Phi-4-mini (3.8B)</li> <li>MiniCPM3 (4B)</li> <li>SDAR (1.7B-30B)</li> <li>gpt-oss (20B, 120B)</li> <li>GLM-4.7-Flash (30B)</li> <li>GLM-5 (754B)</li> </ul> </td> <td> <ul> <li>LLaVA(1.5,1.6) (7B-34B)</li> <li>InternLM-XComposer2 (7B, 4khd-7B)</li> <li>InternLM-XComposer2.5 (7B)</li> <li>Qwen-VL (7B)</li> <li>Qwen2-VL (2B, 7B, 72B)</li> <li>Qwen2.5-VL (3B, 7B, 72B)</li> <li>Qwen3-VL (2B - 235B)</li> <li>Qwen3.5 (0.8B - 397B)</li> <li>Qwen3-Omni (30B-A3B)</li> <li>DeepSeek-VL (7B)</li> <li>DeepSeek-VL2 (3B, 16B, 27B)</li> <li>InternVL-Chat (v1.1-v1.5)</li> <li>InternVL2 (1B-76B)</li> <li>InternVL2.5(MPO) (1B-78B)</li> <li>InternVL3 (1B-78B)</li> <li>InternVL3.5 (1B-241BA28B)</li> <li>Intern-S1 (241B)</li> <li>Intern-S1-mini (8.3B)</li> <li>Intern-S1-Pro (1TB)</li> <li>Intern-S2-Preview (35B-A3B)</li> <li>Mono-InternVL (2B)</li> <li>ChemVLM (8B-26B)</li> <li>CogVLM-Chat (17B)</li> <li>CogVLM2-Chat (19B)</li> <li>MiniCPM-Llama3-V-2_5</li> <li>MiniCPM-V-2_6</li> <li>Phi-3-vision (4.2B)</li> <li>Phi-3.5-vision (4.2B)</li> <li>GLM-4V (9B)</li> <li>GLM-4.1V-Thinking (9B)</li> <li>Llama3.2-vision (11B, 90B)</li> <li>Molmo (7B-D,72B)</li> <li>Gemma3 (1B - 27B)</li> <li>Llama4 (Scout, Maverick)</li> </ul> </td> </tr> </tbody> </table> LMDeploy has developed two inference engines - [TurboMind](./docs/en/inference/turbomind.md) and [PyTorch](./docs/en/inference/pytorch.md), each with a different focus. The former strives for ultimate optimization of inference performance, while the latter, developed purely in Python, aims to decrease the barriers for developers. They differ in the types of supported models and the inference data type. Please refer to [this table](./docs/en/supported_models/supported_models.md) for each engine's capability and choose the proper one that best fits your actual needs. # Quick Start [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1Dh-YlSwg78ZO3AlleO441NF_QP2shs95#scrollTo=YALmXnwCG1pQ) ## Installation It is recommended installing lmdeploy using pip in a conda environment (python 3.10 - 3.13): ```shell conda create -n lmdeploy python=3.12 -y conda activate lmdeploy pip install lmdeploy ``` Starting from **v0.13.0**, the default prebuilt wheels published on **PyPI** are built against **CUDA 12.8**, so `pip install lmdeploy` is sufficient for typical setups including GeForce RTX 50 series. ## Offline Batch Inference ```python import lmdeploy with lmdeploy.pipeline("internlm/internlm3-8b-instruct") as pipe: response = pipe(["Hi, pls intro yourself", "Shanghai is"]) print(response) ``` > \[!NOTE\] > By default, LMDeploy downloads model from HuggingFace. If you would like to use models from ModelScope, please install ModelScope by `pip install modelscope` and set the environment variable: > > `export LMDEPLOY_USE_MODELSCOPE=True` > > If you would like to use models from openMind Hub, please install openMind Hub by `pip install openmind_hub` and set the environment variable: > > `export LMDEPLOY_USE_OPENMIND_HUB=True` For more information about inference pipeline, please refer to [here](docs/en/llm/pipeline.md). # Tutorials Please review [getting_started](docs/en/get_started/get_started.md) section for the basic usage of LMDeploy. For detailed user guides and advanced guides, please refer to our [tutorials](https://lmdeploy.readthedocs.io/en/latest/): - User Guide - [LLM Inference pipeline](docs/en/llm/pipeline.md) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1Dh-YlSwg78ZO3AlleO441NF_QP2shs95#scrollTo=YALmXnwCG1pQ) - [VLM Inference pipeline](docs/en/multi_modal/vl_pipeline.md) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1nKLfnPeDA3p-FMNw2NhI-KOpk7-nlNjF?usp=sharing) - [LLM Serving](docs/en/llm/api_server.md) - [VLM Serving](docs/en/multi_modal/api_server_vl.md) - [Quantization](docs/en/quantization) - Advance Guide - [Inference Engine - TurboMind](docs/en/inference/turbomind.md) - [Inference Engine - PyTorch](docs/en/inference/pytorch.md) - [Customize chat templates](docs/en/advance/chat_template.md) - [Add a new model](docs/en/advance/pytorch_new_model.md) - gemm tuning - [Long context inference](docs/en/advance/long_context.md) - [Multi-model inference service](docs/en/llm/proxy_server.md) # Third-party projects - Deploying LLMs offline on the NVIDIA Jetson platform by LMDeploy: [LMDeploy-Jetson](https://github.com/BestAnHongjun/LMDeploy-Jetson) - Example project for deploying LLMs using LMDeploy and BentoML: [BentoLMDeploy](https://github.com/bentoml/BentoLMDeploy) # Contributing We appreciate all contributions to LMDeploy. Please refer to [CONTRIBUTING.md](.github/CONTRIBUTING.md) for the contributing guideline. # Acknowledgement - [FasterTransformer](https://github.com/NVIDIA/FasterTransformer) - [llm-awq](https://github.com/mit-han-lab/llm-awq) - [vLLM](https://github.com/vllm-project/vllm) - [DeepSpeed-MII](https://github.com/microsoft/DeepSpeed-MII) # Citation ```bibtex @misc{2023lmdeploy, title={LMDeploy: A Toolkit for Compressing, Deploying, and Serving LLM}, author={LMDeploy Contributors}, howpublished = {\url{https://github.com/InternLM/lmdeploy}}, year={2023} } ``` ```bibtex @article{zhang2025efficient, title={Efficient Mixed-Precision Large Language Model Inference with TurboMind}, author={Zhang, Li and Jiang, Youhe and He, Guoliang and Chen, Xin and Lv, Han and Yao, Qian and Fu, Fangcheng and Chen, Kai}, journal={arXiv preprint arXiv:2508.15601}, year={2025} } ``` # License This project is released under the [Apache 2.0 license](LICENSE).

LLM Tools & Chat UIs ML Frameworks
7.9K Github Stars
InternLM
Open Source

InternLM

# InternLM <div align="center"> <img src="./assets/logo.svg" width="200"/> <div> </div> <div align="center"> <b><font size="5">InternLM</font></b> <sup> <a href="https://internlm.intern-ai.org.cn/"> <i><font size="4">HOT</font></i> </a> </sup> <div> </div> </div> [![license](./assets/license.svg)](./LICENSE) [![evaluation](./assets/compass_support.svg)](https://github.com/internLM/OpenCompass/) <!-- [![Documentation Status](https://readthedocs.org/projects/internlm/badge/?version=latest)](https://internlm.readthedocs.io/zh_CN/latest/?badge=latest) --> [📘Commercial Application](#license) | [🤗HuggingFace](https://huggingface.co/internlm) | [🆕Update News](#news) | [🤔Reporting Issues](https://github.com/InternLM/InternLM/issues/new) | [📜Technical Report](https://arxiv.org/abs/2403.17297)<br> [💬Chat Web](https://internlm-chat.intern-ai.org.cn/) | [🔗API](https://internlm.intern-ai.org.cn/api/document) | [🧩Modelers](https://modelers.cn/spaces/MindSpore-Lab/INTERNLM2-20B-PLAN) [English](./README.md) | [简体中文](./README_zh-CN.md) </div> <p align="center"> 👋 join us on <a href="https://discord.gg/xa29JuW87d" target="_blank">Discord</a> and <a href="https://github.com/InternLM/InternLM/assets/25839884/a6aad896-7232-4220-ac84-9e070c2633ce" target="_blank">WeChat</a> </p> ## Introduction InternLM3 has open-sourced an 8-billion parameter instruction model, InternLM3-8B-Instruct, designed for general-purpose usage and advanced reasoning. This model has the following characteristics: - **Enhanced performance at reduced cost**: State-of-the-art performance on reasoning and knowledge-intensive tasks surpass models like Llama3.1-8B and Qwen2.5-7B. Remarkably, InternLM3 is trained on only 4 trillion high-quality tokens, saving more than 75% of the training cost compared to other LLMs of similar scale. - **Deep thinking capability**: InternLM3 supports both the deep thinking mode for solving complicated reasoning tasks via the long chain-of-thought and the normal response mode for fluent user interactions. ## News \[2025.01.15\] We release InternLM3-8B-Instruct, See [model zoo below](#model-zoo) for download or [model cards](./model_cards/) for more details. \[2024.08.01\] We release InternLM2.5-1.8B, InternLM2.5-1.8B-Chat, InternLM2.5-20B and InternLM2.5-20B-Chat. See [model zoo below](#model-zoo) for download or [model cards](./model_cards/) for more details. \[2024.07.19\] We release the InternLM2-Reward series of reward models in 1.8B, 7B and 20B sizes. See [model zoo below](#model-zoo) for download or [model cards](./model_cards/internlm2_reward.md) for more details. \[2024.07.03\] We release InternLM2.5-7B, InternLM2.5-7B-Chat and InternLM2.5-7B-Chat-1M. See [model zoo below](#model-zoo) for download or [model cards](./model_cards/) for more details. \[2024.03.26\] We release InternLM2 technical report. See [arXiv](https://arxiv.org/abs/2403.17297) for details. \[2024.01.31\] We release InternLM2-1.8B, along with the associated chat model. They provide a cheaper deployment option while maintaining leading performance. \[2024.01.23\] We release InternLM2-Math-7B and InternLM2-Math-20B with pretraining and SFT checkpoints. They surpass ChatGPT with small sizes. See [InternLM-Math](https://github.com/InternLM/internlm-math) for details and download. \[2024.01.17\] We release InternLM2-7B and InternLM2-20B and their corresponding chat models with stronger capabilities in all dimensions. See [model zoo below](#model-zoo) for download or [model cards](./model_cards/) for more details. \[2023.12.13\] InternLM-7B-Chat and InternLM-20B-Chat checkpoints are updated. With an improved finetuning strategy, the new chat models can generate higher quality responses with greater stylistic diversity. \[2023.09.20\] InternLM-20B is released with base and chat versions. ## Model Zoo ### InternLM3 | Model | Transformers | ModelScope | Modelers | Release Date | | ------------------------- | -------------------------------------------------------- | ------------------------------------------------------ | ----------------------------------------------------- | ------------ | | **InternLM3-8B-Instruct** | [🤗internlm3_8B_instruct](https://huggingface.co/internlm/internlm3-8b-instruct) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm3_8b_instruct](https://www.modelscope.cn/models/Shanghai_AI_Laboratory/internlm3-8b-instruct/summary) | [![Open in Modelers](https://modelers.cn/assets/logo1-1bf58310.svg)](https://modelers.cn/models/Intern/internlm3-8b-instruct) | 2025-01-15 | ### InternLM2.5 <details> <summary>(click to expand)</summary> | Model | Transformers(HF) | ModelScope(HF) | OpenXLab(HF) | OpenXLab(Origin) | Release Date | | -------------------------- | ------------------------------------------ | ---------------------------------------- | -------------------------------------- | ------------------------------------------ | ------------ | | **InternLM2.5-1.8B** | [🤗internlm2_5-1_8b](https://huggingface.co/internlm/internlm2_5-1_8b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2_5-1_8b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2_5-1_8b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-1_8b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-1_8b-original) | 2024-08-05 | | **InternLM2.5-1.8B-Chat** | [🤗internlm2_5-1_8b-chat](https://huggingface.co/internlm/internlm2_5-1_8b-chat) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2_5-1_8b-chat](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2_5-1_8b-chat/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-1_8b-chat) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-1_8b-chat-original) | 2024-08-05 | | **InternLM2.5-7B** | [🤗internlm2_5-7b](https://huggingface.co/internlm/internlm2_5-7b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2_5-7b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2_5-7b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-7b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-7b-original) | 2024-07-03 | | **InternLM2.5-7B-Chat** | [🤗internlm2_5-7b-chat](https://huggingface.co/internlm/internlm2_5-7b-chat) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2_5-7b-chat](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2_5-7b-chat/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-7b-chat) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-7b-chat-original) | 2024-07-03 | | **InternLM2.5-7B-Chat-1M** | [🤗internlm2_5-7b-chat-1m](https://huggingface.co/internlm/internlm2_5-7b-chat-1m) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2_5-7b-chat-1m](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2_5-7b-chat-1m/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-7b-chat-1m) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-7b-chat-1m-original) | 2024-07-03 | | **InternLM2.5-20B** | [🤗internlm2_5-20b](https://huggingface.co/internlm/internlm2_5-20b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2_5-20b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2_5-20b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-20b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-20b-original) | 2024-08-05 | | **InternLM2.5-20B-Chat** | [🤗internlm2_5-20b-chat](https://huggingface.co/internlm/internlm2_5-20b-chat) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2_5-20b-chat](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2_5-20b-chat/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-20b-chat) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2_5-20b-chat-original) | 2024-08-05 | **Notes:** The release of InternLM2.5 series contains 1.8B, 7B, and 20B versions. 7B models are efficient for research and application and 20B models are more powerful and can support more complex scenarios. The relation of these models are shown as follows. 1. **InternLM2.5**: Foundation models pre-trained on large-scale corpus. InternLM2.5 models are recommended for consideration in most applications. 2. **InternLM2.5-Chat**: The Chat model that undergoes supervised fine-tuning (SFT) and reinforcement learning from human feedback (RLHF), based on the InternLM2.5 model. InternLM2.5-Chat is optimized for instruction following, chat experience, and function call, which is recommended for downstream applications. 3. **InternLM2.5-Chat-1M**: InternLM2.5-Chat-1M supports 1M long-context with compatible performance as InternLM2.5-Chat. **Limitations:** Although we have made efforts to ensure the safety of the model during the training process and to encourage the model to generate text that complies with ethical and legal requirements, the model may still produce unexpected outputs due to its size and probabilistic generation paradigm. For example, the generated responses may contain biases, discrimination, or other harmful content. Please do not propagate such content. We are not responsible for any consequences resulting from the dissemination of harmful information. **Supplements:** `HF` refers to the format used by HuggingFace in [transformers](https://github.com/huggingface/transformers), whereas `Origin` denotes the format adopted by the InternLM team in [InternEvo](https://github.com/InternLM/InternEvo). </details> ### InternLM2-Reward <details> <summary>(click to expand)</summary> InternLM2-Reward is a series of reward models, trained on 2.4 million preference samples, available in 1.8B, 7B, and 20B sizes. These model were applied to the PPO training process of our chat models. See [model cards](./model_cards/internlm2_reward.md) for more details. | Model | RewardBench Score | Transformers(HF) | ModelScope(HF) | OpenXLab(HF) | Release Date | | ------------------------- | ----------------- | -------------------------------------------------- | ------------------------------------------------- | ----------------------------------------------- | ------------ | | **InternLM2-1.8B-Reward** | 80.6 | [🤗internlm2-1_8b-reward](https://huggingface.co/internlm/internlm2-1_8b-reward) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-1_8b-reward](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-1_8b-reward/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-1_8b-reward) | 2024-07-19 | | **InternLM2-7B-Reward** | 86.6 | [🤗internlm2-7b-reward](https://huggingface.co/internlm/internlm2-7b-reward) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-7b-reward](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-7b-reward/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-7b-reward) | 2024-07-19 | | **InternLM2-20B-Reward** | 89.5 | [🤗internlm2-20b-reward](https://huggingface.co/internlm/internlm2-20b-reward) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-20b-reward](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-20b-reward/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-20b-reward) | 2024-07-19 | </details> ### InternLM2 <details> <summary>(click to expand)</summary> Our previous generation models with advanced capabilities in long-context processing, reasoning, and coding. See [model cards](./model_cards/) for more details. | Model | Transformers(HF) | ModelScope(HF) | OpenXLab(HF) | OpenXLab(Origin) | Release Date | | --------------------------- | ----------------------------------------- | ---------------------------------------- | -------------------------------------- | ------------------------------------------ | ------------ | | **InternLM2-1.8B** | [🤗internlm2-1.8b](https://huggingface.co/internlm/internlm2-1_8b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-1.8b](https://www.modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-1_8b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-base-1.8b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-base-1.8b-original) | 2024-01-31 | | **InternLM2-Chat-1.8B-SFT** | [🤗internlm2-chat-1.8b-sft](https://huggingface.co/internlm/internlm2-chat-1_8b-sft) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-chat-1.8b-sft](https://www.modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-chat-1_8b-sft/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-1.8b-sft) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-1.8b-sft-original) | 2024-01-31 | | **InternLM2-Chat-1.8B** | [🤗internlm2-chat-1.8b](https://huggingface.co/internlm/internlm2-chat-1_8b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-chat-1.8b](https://www.modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-chat-1_8b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-1.8b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-1.8b-original) | 2024-02-19 | | **InternLM2-Base-7B** | [🤗internlm2-base-7b](https://huggingface.co/internlm/internlm2-base-7b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-base-7b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-base-7b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-base-7b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-base-7b-original) | 2024-01-17 | | **InternLM2-7B** | [🤗internlm2-7b](https://huggingface.co/internlm/internlm2-7b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-7b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-7b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-7b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-7b-original) | 2024-01-17 | | **InternLM2-Chat-7B-SFT** | [🤗internlm2-chat-7b-sft](https://huggingface.co/internlm/internlm2-chat-7b-sft) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-chat-7b-sft](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-chat-7b-sft/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-7b-sft) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-7b-sft-original) | 2024-01-17 | | **InternLM2-Chat-7B** | [🤗internlm2-chat-7b](https://huggingface.co/internlm/internlm2-chat-7b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-chat-7b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-chat-7b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-7b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-7b-original) | 2024-01-17 | | **InternLM2-Base-20B** | [🤗internlm2-base-20b](https://huggingface.co/internlm/internlm2-base-20b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-base-20b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-base-20b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-base-20b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-base-20b-original) | 2024-01-17 | | **InternLM2-20B** | [🤗internlm2-20b](https://huggingface.co/internlm/internlm2-20b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-20b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-20b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-20b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-20b-original) | 2024-01-17 | | **InternLM2-Chat-20B-SFT** | [🤗internlm2-chat-20b-sft](https://huggingface.co/internlm/internlm2-chat-20b-sft) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-chat-20b-sft](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-chat-20b-sft/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-20b-sft) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-20b-sft-original) | 2024-01-17 | | **InternLM2-Chat-20B** | [🤗internlm2-chat-20b](https://huggingface.co/internlm/internlm2-chat-20b) | [<img src="./assets/modelscope_logo.png" width="20px" /> internlm2-chat-20b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm2-chat-20b/summary) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-20b) | [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/internlm2-chat-20b-original) | 2024-01-17 | </details> ## Performance We conducted a comprehensive evaluation of InternLM using the open-source evaluation tool [OpenCompass](https://github.com/internLM/OpenCompass/). The evaluation covered five dimensions of capabilities: disciplinary competence, language competence, knowledge competence, inference competence, and comprehension competence. Here are some of the evaluation results, and you can visit the [OpenCompass leaderboard](https://rank.opencompass.org.cn) for more evaluation results. | Benchmark | | InternLM3-8B-Instruct | Qwen2.5-7B-Instruct | Llama3.1-8B-Instruct | GPT-4o-mini(close source) | | ------------ | ------------------------------- | --------------------- | ------------------- | -------------------- | ------------------------- | | General | CMMLU(0-shot) | **83.1** | 75.8 | 53.9 | 66.0 | | | MMLU(0-shot) | 76.6 | **76.8** | 71.8 | 82.7 | | | MMLU-Pro(0-shot) | **57.6** | 56.2 | 48.1 | 64.1 | | Reasoning | GPQA-Diamond(0-shot) | **37.4** | 33.3 | 24.2 | 42.9 | | | DROP(0-shot) | **83.1** | 80.4 | 81.6 | 85.2 | | | HellaSwag(10-shot) | **91.2** | 85.3 | 76.7 | 89.5 | | | KOR-Bench(0-shot) | **56.4** | 44.6 | 47.7 | 58.2 | | MATH | MATH-500(0-shot) | **83.0**\* | 72.4 | 48.4 | 74.0 | | | AIME2024(0-shot) | **20.0**\* | 16.7 | 6.7 | 13.3 | | Coding | LiveCodeBench(2407-2409 Pass@1) | **17.8** | 16.8 | 12.9 | 21.8 | | | HumanEval(Pass@1) | 82.3 | **85.4** | 72.0 | 86.6 | | Instrunction | IFEval(Prompt-Strict) | **79.3** | 71.7 | 75.2 | 79.7 | | Long Context | RULER(4-128K Average) | 87.9 | 81.4 | **88.5** | 90.7 | | Chat | AlpacaEval 2.0(LC WinRate) | **51.1** | 30.3 | 25.0 | 50.7 | | | WildBench(Raw Score) | **33.1** | 23.3 | 1.5 | 40.3 | | | MT-Bench-101(Score 1-10) | **8.59** | 8.49 | 8.37 | 8.87 | - The evaluation results were obtained from [OpenCompass](https://github.com/internLM/OpenCompass/) (some data marked with \*, which means evaluating with Thinking Mode), and evaluation configuration can be found in the configuration files provided by [OpenCompass](https://github.com/internLM/OpenCompass/). - The evaluation data may have numerical differences due to the version iteration of [OpenCompass](https://github.com/internLM/OpenCompass/), so please refer to the latest evaluation results of [OpenCompass](https://github.com/internLM/OpenCompass/). **Limitations:** Although we have made efforts to ensure the safety of the model during the training process and to encourage the model to generate text that complies with ethical and legal requirements, the model may still produce unexpected outputs due to its size and probabilistic generation paradigm. For example, the generated responses may contain biases, discrimination, or other harmful content. Please do not propagate such content. We are not responsible for any consequences resulting from the dissemination of harmful information. ### Requirements - Python >= 3.8 - PyTorch >= 1.12.0 (2.0.0 and above are recommended) - Transformers >= 4.38 ## Usages ### Conversation Mode #### Transformers inference To load the InternLM3 8B Instruct model using Transformers, use the following code: ```python import torch from transformers import AutoTokenizer, AutoModelForCausalLM model_dir = "internlm/internlm3-8b-instruct" tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True) # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error. model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.float16) # (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes. # InternLM3 8B in 4bit will cost nearly 8GB GPU memory. # pip install -U bitsandbytes # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True) # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True) model = model.eval() 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"}, ] tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt") generated_ids = model.generate(tokenized_chat, max_new_tokens=1024, temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8) generated_ids = [ output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids) ] prompt = tokenizer.batch_decode(tokenized_chat)[0] print(prompt) response = tokenizer.batch_decode(generated_ids)[0] print(response) ``` #### LMDeploy inference LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the MMRazor and MMDeploy teams. ```bash pip install lmdeploy ``` You can run batch inference locally with the following python code: ```python 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) ``` Or you can launch an OpenAI compatible server with the following command: ```bash lmdeploy serve api_server internlm/internlm3-8b-instruct --model-name internlm3-8b-instruct --server-port 23333 ``` Then you can send a chat request to the server: ```bash 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"} ] }' ``` Find more details in the [LMDeploy documentation](https://lmdeploy.readthedocs.io/en/latest/) #### SGLang inference ##### Installation ```bash pip3 install "sglang[srt]>=0.4.1.post6" --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/ ``` ##### OpenAI Compatible Server ```bash python3 -m sglang.launch_server --model internlm/internlm3-8b-instruct --trust-remote-code --chat-template internlm2-chat ``` ##### OpenAI client ```python3 import openai client = openai.Client( base_url="http://127.0.0.1:30000/v1", api_key="EMPTY") # Chat completion response = client.chat.completions.create( model="default", messages=[ {"role": "system", "content": "You are a helpful AI assistant"}, {"role": "user", "content": "List 3 countries and their capitals."}, ], temperature=0, max_tokens=64, ) print(response) ``` #### Ollama inference install ollama and pull the model ```bash # install ollama curl -fsSL https://ollama.com/install.sh | sh # pull the model ollama pull internlm/internlm3-8b-instruct # install ollama-python pip install ollama ``` inference code: ```python 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) ``` #### vLLM inference refer to [installation](https://docs.vllm.ai/en/latest/getting_started/installation/index.html) to install the latest code of vllm ```python pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly ``` inference code: ```python from vllm import LLM, SamplingParams llm = LLM(model="internlm/internlm3-8b-instruct") sampling_params = SamplingParams(temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8) 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 中文.""" prompts = [ { "role": "system", "content": system_prompt, }, { "role": "user", "content": "Please tell me five scenic spots in Shanghai" }, ] outputs = llm.chat(prompts, sampling_params=sampling_params, use_tqdm=False) print(outputs) ``` ### Thinking Mode #### Thinking Demo <img src="https://github.com/InternLM/InternLM/blob/017ba7446d20ecc3b9ab8e7b66cc034500868ab4/assets/solve_puzzle.png?raw=true" width="400"/> #### Thinking system prompt ```python thinking_system_prompt = """You are an expert mathematician with extensive experience in mathematical competitions. You approach problems through systematic thinking and rigorous reasoning. When solving problems, follow these thought processes: ## Deep Understanding Take time to fully comprehend the problem before attempting a solution. Consider: - What is the real question being asked? - What are the given conditions and what do they tell us? - Are there any special restrictions or assumptions? - Which information is crucial and which is supplementary? ## Multi-angle Analysis Before solving, conduct thorough analysis: - What mathematical concepts and properties are involved? - Can you recall similar classic problems or solution methods? - Would diagrams or tables help visualize the problem? - Are there special cases that need separate consideration? ## Systematic Thinking Plan your solution path: - Propose multiple possible approaches - Analyze the feasibility and merits of each method - Choose the most appropriate method and explain why - Break complex problems into smaller, manageable steps ## Rigorous Proof During the solution process: - Provide solid justification for each step - Include detailed proofs for key conclusions - Pay attention to logical connections - Be vigilant about potential oversights ## Repeated Verification After completing your solution: - Verify your results satisfy all conditions - Check for overlooked special cases - Consider if the solution can be optimized or simplified - Review your reasoning process Remember: 1. Take time to think thoroughly rather than rushing to an answer 2. Rigorously prove each key conclusion 3. Keep an open mind and try different approaches 4. Summarize valuable problem-solving methods 5. Maintain healthy skepticism and verify multiple times Your response should reflect deep mathematical understanding and precise logical thinking, making your solution path and reasoning clear to others. When you're ready, present your complete solution with: - Clear problem understanding - Detailed solution process - Key insights - Thorough verification Focus on clear, logical progression of ideas and thorough explanation of your mathematical reasoning. Provide answers in the same language as the user asking the question, repeat the final answer using a '\\boxed{}' without any units, you have [[8192]] tokens to complete the answer. """ ``` #### Transformers inference ```python import torch from transformers import AutoTokenizer, AutoModelForCausalLM model_dir = "internlm/internlm3-8b-instruct" tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True) # Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error. model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, torch_dtype=torch.float16) # (Optional) If on low resource devices, you can load model in 4-bit or 8-bit to further save GPU memory via bitsandbytes. # InternLM3 8B in 4bit will cost nearly 8GB GPU memory. # pip install -U bitsandbytes # 8-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_8bit=True) # 4-bit: model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", trust_remote_code=True, load_in_4bit=True) model = model.eval() messages = [ {"role": "system", "content": thinking_system_prompt}, {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."}, ] tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt") generated_ids = model.generate(tokenized_chat, max_new_tokens=8192) generated_ids = [ output_ids[len(input_ids):] for input_ids, output_ids in zip(tokenized_chat, generated_ids) ] prompt = tokenizer.batch_decode(tokenized_chat)[0] print(prompt) response = tokenizer.batch_decode(generated_ids)[0] print(response) ``` #### LMDeploy inference LMDeploy is a toolkit for compressing, deploying, and serving LLM. ```bash pip install lmdeploy ``` You can run batch inference locally with the following python code: ```python from lmdeploy import pipeline, GenerationConfig, ChatTemplateConfig model_dir = "internlm/internlm3-8b-instruct" chat_template_config = ChatTemplateConfig(model_name='internlm3') pipe = pipeline(model_dir, chat_template_config=chat_template_config) messages = [ {"role": "system", "content": thinking_system_prompt}, {"role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)."}, ] response = pipe(messages, gen_config=GenerationConfig(max_new_tokens=2048)) print(response) ``` #### SGLang inference Installation ```bash pip3 install "sglang[srt]>=0.4.1.post6" --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/ ``` For offline engine api usage, please refer to [Offline Engine API](https://docs.sglang.ai/backend/offline_engine_api.html) #### Ollama inference install ollama and pull the model ```bash # install ollama curl -fsSL https://ollama.com/install.sh | sh # pull the model ollama pull internlm/internlm3-8b-instruct # install ollama-python pip install ollama ``` inference code: ```python import ollama messages = [ { "role": "system", "content": thinking_system_prompt, }, { "role": "user", "content": "已知函数\(f(x)=\mathrm{e}^{x}-ax - a^{3}\)。\n(1)当\(a = 1\)时,求曲线\(y = f(x)\)在点\((1,f(1))\)处的切线方程;\n(2)若\(f(x)\)有极小值,且极小值小于\(0\),求\(a\)的取值范围。" }, ] stream = ollama.chat( model='internlm/internlm3-8b-instruct', messages=messages, stream=True, options=dict(num_ctx=8192, num_predict=2048) ) for chunk in stream: print(chunk['message']['content'], end='', flush=True) ``` #### vLLM inference refer to [installation](https://docs.vllm.ai/en/latest/getting_started/installation/index.html) to install the latest code of vllm ```python pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly ``` inference code ```python from vllm import LLM, SamplingParams llm = LLM(model="internlm/internlm3-8b-instruct") sampling_params = SamplingParams(temperature=1, repetition_penalty=1.005, top_k=40, top_p=0.8, max_tokens=8192) prompts = [ { "role": "system", "content": thinking_system_prompt, }, { "role": "user", "content": "Given the function\(f(x)=\mathrm{e}^{x}-ax - a^{3}\),\n(1) When \(a = 1\), find the equation of the tangent line to the curve \(y = f(x)\) at the point \((1,f(1))\).\n(2) If \(f(x)\) has a local minimum and the minimum value is less than \(0\), determine the range of values for \(a\)." }, ] outputs = llm.chat(prompts, sampling_params=sampling_params, use_tqdm=False) print(outputs) ``` ## License Code and model weights are licensed under Apache-2.0. ## Citation ``` @misc{cai2024internlm2, title={InternLM2 Technical Report}, author={Zheng Cai and Maosong Cao and Haojiong Chen and Kai Chen and Keyu Chen and Xin Chen and Xun Chen and Zehui Chen and Zhi Chen and Pei Chu and Xiaoyi Dong and Haodong Duan and Qi Fan and Zhaoye Fei and Yang Gao and Jiaye Ge and Chenya Gu and Yuzhe Gu and Tao Gui and Aijia Guo and Qipeng Guo and Conghui He and Yingfan Hu and Ting Huang and Tao Jiang and Penglong Jiao and Zhenjiang Jin and Zhikai Lei and Jiaxing Li and Jingwen Li and Linyang Li and Shuaibin Li and Wei Li and Yining Li and Hongwei Liu and Jiangning Liu and Jiawei Hong and Kaiwen Liu and Kuikun Liu and Xiaoran Liu and Chengqi Lv and Haijun Lv and Kai Lv and Li Ma and Runyuan Ma and Zerun Ma and Wenchang Ning and Linke Ouyang and Jiantao Qiu and Yuan Qu and Fukai Shang and Yunfan Shao and Demin Song and Zifan Song and Zhihao Sui and Peng Sun and Yu Sun and Huanze Tang and Bin Wang and Guoteng Wang and Jiaqi Wang and Jiayu Wang and Rui Wang and Yudong Wang and Ziyi Wang and Xingjian Wei and Qizhen Weng and Fan Wu and Yingtong Xiong and Chao Xu and Ruiliang Xu and Hang Yan and Yirong Yan and Xiaogui Yang and Haochen Ye and Huaiyuan Ying and Jia Yu and Jing Yu and Yuhang Zang and Chuyu Zhang and Li Zhang and Pan Zhang and Peng Zhang and Ruijie Zhang and Shuo Zhang and Songyang Zhang and Wenjian Zhang and Wenwei Zhang and Xingcheng Zhang and Xinyue Zhang and Hui Zhao and Qian Zhao and Xiaomeng Zhao and Fengzhe Zhou and Zaida Zhou and Jingming Zhuo and Yicheng Zou and Xipeng Qiu and Yu Qiao and Dahua Lin}, year={2024}, eprint={2403.17297}, archivePrefix={arXiv}, primaryClass={cs.CL} } ```

LLM Tools & Chat UIs ML Frameworks
7.2K Github Stars
xtuner
Open Source

xtuner

<div align="center"> <img src="https://github.com/InternLM/lmdeploy/assets/36994684/0cf8d00f-e86b-40ba-9b54-dc8f1bc6c8d8" width="600"/> <br /><br /> [![GitHub Repo stars](https://img.shields.io/github/stars/InternLM/xtuner?style=social)](https://github.com/InternLM/xtuner/stargazers) [![license](https://img.shields.io/github/license/InternLM/xtuner.svg)](https://github.com/InternLM/xtuner/blob/main/LICENSE) [![PyPI](https://img.shields.io/pypi/v/xtuner)](https://pypi.org/project/xtuner/) [![Downloads](https://static.pepy.tech/badge/xtuner)](https://pypi.org/project/xtuner/) [![issue resolution](https://img.shields.io/github/issues-closed-raw/InternLM/xtuner)](https://github.com/InternLM/xtuner/issues) [![open issues](https://img.shields.io/github/issues-raw/InternLM/xtuner)](https://github.com/InternLM/xtuner/issues) 👋 join us on [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=wechat&label=WeChat)](https://cdn.vansin.top/internlm/xtuner.jpg) [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=twitter&label=Twitter)](https://twitter.com/intern_lm) [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=discord&label=Discord)](https://discord.gg/xa29JuW87d) 🔍 Explore our models on [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🤗%20Huggingface)](https://huggingface.co/xtuner) [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🤖%20ModelScope)](https://www.modelscope.cn/organization/xtuner) [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🧰%20OpenXLab)](https://openxlab.org.cn/usercenter/xtuner) [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🧠%20WiseModel)](https://www.wisemodel.cn/organization/xtuner) English | [简体中文](README_zh-CN.md) </div> ## 🚀 Speed Benchmark <div align=center> <img src="https://github.com/user-attachments/assets/fa42d587-068d-427b-b88c-25a164b3511c" style="width:80%"> </div> ## 🎉 News - **\[2025/09\]** XTuner V1 Released! A Next-Generation Training Engine Built for Ultra-Large MoE Models ## 📖 XTuner V1 XTuner V1 is a next-generation LLM training engine specifically designed for ultra-large-scale MoE models. Unlike traditional 3D parallel training architectures, XTuner V1 is optimized for the mainstream MoE training scenarios prevalent in today's academic research. ### Key Features **📊 Dropless Training** - **Scalable without complexity:** Train 200B-scale MoE models without expert parallelism; 600B models require only intra-node expert parallelism - **Optimized parallelism strategy:** Smaller expert parallelism dimension compared to traditional 3D approaches, enabling more efficient Dropless training **📝 Long Sequence Support** - **Memory-efficient design:** Train 200B MoE models on 64k sequence lengths without sequence parallelism through advanced memory optimization techniques - **Flexible scaling:** Full support for DeepSpeed Ulysses sequence parallelism with linearly scalable maximum sequence length - **Robust performance:** Maintains stability despite expert load imbalance during long sequence training **⚡ Superior Efficiency** - **Massive scale:** Supports MoE training up to 1T parameters - **Breakthrough performance:** First to achieve FSDP training throughput that surpasses traditional 3D parallel schemes for MoE models above 200B scale - **Hardware optimization:** Achieves training efficiency on Ascend A3 Supernode that exceeds NVIDIA H800 <div align=center> <img src="https://github.com/user-attachments/assets/c4fb2bb4-56bd-4f1c-8188-7f5370314cf8" style="width:90%"> </div> ## 🔥 Roadmap XTuner V1 is committed to continuously improving training efficiency for pre-training, instruction fine-tuning, and reinforcement learning of ultra-large MoE models, with special focus on Ascend NPU optimization. ### 🚀 Training Engine Our vision is to establish XTuner V1 as a versatile training backend that seamlessly integrates with the broader open-source ecosystem. | Model | GPU(FP8) | GPU(BF16)| NPU(BF16) | |------------|-----------|----------|-----------| | Intern S1 | ✅ | ✅ | ✅ | | Intern VL | ✅ | ✅ | ✅ | | Qwen3 Dense| ✅ | ✅ | ✅ | | Qwen3 MoE | ✅ | ✅ | ✅ | | GPT OSS | ✅ | ✅ | 🚧 | | Deepseek V3| ✅ | ✅ | 🚧 | | KIMI K2 | ✅ | ✅ | 🚧 | ### 🧠 Algorithm The algorithm component is actively evolving. We welcome community contributions - with XTuner V1, scale your algorithms to unprecedented sizes! **Implemented** - ✅ **Multimodal Pre-training** - Full support for vision-language model training - ✅ **Multimodal Supervised Fine-tuning** - Optimized for instruction following - ✅ [GRPO](https://arxiv.org/pdf/2402.03300) - Group Relative Policy Optimization **Coming Soon** - 🔄 [MPO](https://arxiv.org/pdf/2411.10442) - Mixed Preference Optimization - 🔄 [DAPO](https://arxiv.org/pdf/2503.14476) - Dynamic Sampling Policy Optimization - 🔄 **Multi-turn Agentic RL** - Advanced agent training capabilities ### ⚡ Inference Engine Integration Seamless deployment with leading inference frameworks: - [x] LMDeploy - [ ] vLLM - [ ] SGLang ### Data Preparation - You can use [GraphGen](https://github.com/open-sciencelab/GraphGen) to create synthetic data for fine-tuning. ## 🤝 Contributing We appreciate all contributions to XTuner. Please refer to [CONTRIBUTING.md](.github/CONTRIBUTING.md) for the contributing guideline. ## 🙏 Acknowledgement The development of XTuner V1's training engine has been greatly inspired by and built upon the excellent work of the open-source community. We extend our sincere gratitude to the following pioneering projects: **Training Engine:** - [Torchtitan](https://github.com/pytorch/torchtitan) - A PyTorch native platform for training generative AI models - [Deepspeed](https://github.com/deepspeedai/DeepSpeed) - Microsoft's deep learning optimization library - [MindSpeed](https://gitee.com/ascend/MindSpeed) - Ascend's high-performance training acceleration library - [Megatron](https://github.com/NVIDIA/Megatron-LM) - NVIDIA's large-scale transformer training framework **Reinforcement Learning:** XTuner V1's reinforcement learning capabilities have been enhanced through insights and best practices from: - [veRL](https://github.com/volcengine/verl) - Volcano Engine Reinforcement Learning for LLMs - [SLIME](https://github.com/THUDM/slime) - THU's scalable RLHF implementation - [AReal](https://github.com/inclusionAI/AReaL) - Ant Reasoning Reinforcement Learning for LLMs - [OpenRLHF](https://github.com/OpenRLHF/OpenRLHF) - An Easy-to-use, Scalable and High-performance RLHF Framework based on Ray We are deeply grateful to all contributors and maintainers of these projects for advancing the field of large-scale model training. ## 🖊️ Citation ```bibtex @misc{2023xtuner, title={XTuner: A Toolkit for Efficiently Fine-tuning LLM}, author={XTuner Contributors}, howpublished = {\url{https://github.com/InternLM/xtuner}}, year={2023} } ``` ## License This project is released under the [Apache License 2.0](LICENSE). Please also adhere to the Licenses of models and datasets being used.

ML Frameworks
5.2K Github Stars
HuixiangDou
Open Source

HuixiangDou

# 🎚️ Upgrade [HuixiangDou2](https://github.com/tpoisonooo/HuixiangDou2)(ACL25) is a GraphRAG solution whose effectiveness has been demonstrated in the plant-science domain and that contributed to the [**cover paper in Cell**](https://www.cell.com/molecular-plant/issue?pii=S1674-2052(24)X0008-8) Molecular Plant. If you work outside computer science, give the new release a try. --- English | [简体中文](README_zh.md) <div align="center"> <img src="resource/logo_black.svg" width="555px"/> <div align="center"> <a href="https://cdn.vansin.top/internlm/dou.jpg" target="_blank"> <img alt="Wechat" src="https://img.shields.io/badge/wechat-robot%20inside-brightgreen?logo=wechat&logoColor=white" /> </a> <a href="https://huixiangdou.readthedocs.io/en/latest/" target="_blank"> <img alt="Readthedocs" src="https://img.shields.io/badge/readthedocs-chat%20with%20AI-brightgreen?logo=readthedocs&logoColor=white" /> </a> <a href="https://youtu.be/ylXrT-Tei-Y" target="_blank"> <img alt="YouTube" src="https://img.shields.io/badge/YouTube-black?logo=youtube&logoColor=red" /> </a> <a href="https://www.bilibili.com/video/BV1S2421N7mn" target="_blank"> <img alt="BiliBili" src="https://img.shields.io/badge/BiliBili-pink?logo=bilibili&logoColor=white" /> </a> <a href="https://discord.gg/TW4ZBpZZ" target="_blank"> <img alt="discord" src="https://img.shields.io/badge/discord-red?logo=discord&logoColor=white" /> </a> <a href="https://arxiv.org/abs/2401.08772" target="_blank"> <img alt="Arxiv" src="https://img.shields.io/badge/arxiv-2401.08772%20-darkred?logo=arxiv&logoColor=white" /> </a> <a href="https://arxiv.org/abs/2405.02817" target="_blank"> <img alt="Arxiv" src="https://img.shields.io/badge/arxiv-2405.02817%20-darkred?logo=arxiv&logoColor=white" /> </a> </div> </div> HuixiangDou1 is a **professional knowledge assistant** based on LLM. Advantages: 1. Design three-stage pipelines of preprocess, rejection and response * `chat_in_group` copes with **group chat** scenario, answer user questions without message flooding, see [2401.08772](https://arxiv.org/abs/2401.08772), [2405.02817](https://arxiv.org/abs/2405.02817), [Hybrid Retrieval](./docs/en/doc_knowledge_graph.md) and [Precision Report](./evaluation/) * `chat_with_repo` for **real-time streaming** chat 2. No training required, with CPU-only, 2G, 10G configuration 3. Offers a complete suite of Web, Android, and pipeline source code, industrial-grade and commercially viable Check out the [scenes in which HuixiangDou are running](./huixiangdou-inside.md) and current public service status: - [readthedocs ChatWithAI](https://huixiangdou.readthedocs.io/zh-cn/latest/) (cpu-only) is available - [OpenXLab](https://openxlab.org.cn/apps/detail/tpoisonooo/huixiangdou-web) is using GPU and under continuous maintenance - [WeChat bot](https://cdn.vansin.top/internlm/dou.jpg) has a cost associated with WeChat integration. All code has been verified to be functional for one year. Please deploy it on your own for either the [free](https://github.com/InternLM/HuixiangDou/blob/main/docs/zh/doc_add_wechat_accessibility.md) or [commercial](https://github.com/InternLM/HuixiangDou/blob/main/docs/zh/doc_add_wechat_commercial.md) version. If this helps you, please give it a star ⭐ # 🔆 New Features Our Web version has been released to [OpenXLab](https://openxlab.org.cn/apps/detail/tpoisonooo/huixiangdou-web), where you can create knowledge base, update positive and negative examples, turn on web search, test chat, and integrate into Feishu/WeChat groups. See [BiliBili](https://www.bilibili.com/video/BV1S2421N7mn) and [YouTube](https://www.youtube.com/watch?v=ylXrT-Tei-Y) ! The Web version's API for Android also supports other devices. See [Python sample code](./tests/test_openxlab_android_api.py). - \[2025/03\] Simplify deployment and removing `--standalone` - \[2025/03\] [Forwarding multiple wechat group message](./docs/zh/doc_merge_wechat_group.md) - \[2024/09\] [Inverted indexer](https://github.com/InternLM/HuixiangDou/pull/387) makes LLM prefer knowledge base🎯 - \[2024/09\] [Code retrieval](./huixiangdou/services/parallel_pipeline.py) - \[2024/08\] [chat_with_readthedocs](https://huixiangdou.readthedocs.io/en/latest/), see [how to integrate](./docs/zh/doc_add_readthedocs.md) 👍 - \[2024/07\] Image and text retrieval & Removal of `langchain` 👍 - \[2024/07\] [Hybrid Knowledge Graph and Dense Retrieval](./docs/en/doc_knowledge_graph.md) improve 1.7% F1 score 🎯 - \[2024/06\] [Evaluation of chunksize, splitter, and text2vec model](./evaluation) 🎯 - \[2024/05\] [wkteam WeChat access](./docs/zh/doc_add_wechat_commercial.md), parsing image & URL, support coreference resolution - \[2024/05\] [SFT LLM on NLP task, F1 increased by 29%](./sft/) 🎯 <table> <tr> <td>🤗</td> <td><a href="https://huggingface.co/tpoisonooo/HuixiangDou-CR-LoRA-Qwen-14B">LoRA-Qwen1.5-14B</a></td> <td><a href="https://huggingface.co/tpoisonooo/HuixiangDou-CR-LoRA-Qwen-32B">LoRA-Qwen1.5-32B</a></td> <td><a href="https://huggingface.co/datasets/tpoisonooo/HuixiangDou-CR/tree/main">alpaca data</a></td> <td><a href="https://arxiv.org/abs/2405.02817">arXiv</a></td> </tr> </table> - \[2024/04\] [RAG Annotation SFT Q&A Data and Examples](./docs/zh/doc_rag_annotate_sft_data.md) - \[2024/04\] Release [Web Front and Back End Service Source Code](./web) 👍 - \[2024/03\] New [Personal WeChat Integration](./docs/zh/doc_add_wechat_accessibility.md) and [**Prebuilt APK**](https://github.com/InternLM/HuixiangDou/releases/download/v0.1.0rc1/huixiangdou-20240508.apk) ! - \[2024/02\] \[Experimental Feature\] [WeChat Group](https://cdn.vansin.top/internlm/dou.jpg) Integration of multimodal to achieve OCR # 📖 Support Status <table align="center"> <tbody> <tr align="center" valign="bottom"> <td> <b>LLM</b> </td> <td> <b>File Format</b> </td> <td> <b>Retrieval Method</b> </td> <td> <b>Integration</b> </td> <td> <b>Preprocessing</b> </td> </tr> <tr valign="top"> <td> - [DeepSeek](https://www.deepseek.com) - [InternLM](https://internlm.intern-ai.org.cn) - [GLM](https://www.zhipuai.cn) - [KIMI](https://kimi.moonshot.cn) - [StepFun](https://platform.stepfun.com) - [vLLM](https://github.com/vllm-project/vllm) - [Silicon🏷️](https://cloud.siliconflow.cn/s/tpoisonooo) - [PPIO🏷️](https://ppinfra.com/user/register?invited_by=7GF8QS) - [Xi-Api](https://api.xi-ai.cn) </td> <td> - excel - html - markdown - pdf - ppt - txt - word </td> <td> - Dense for Document - Sparse for Code - [Knowledge Graph](./docs/en/doc_knowledge_graph.md) - [Internet Search](./huixiangdou/services/web_search.py) - [SourceGraph](https://sourcegraph.com) - Image and Text </td> <td> - WeChat([android](./docs/zh/doc_add_wechat_accessibility.md)/[wkteam](./docs/zh/doc_add_wechat_commercial.md)) - Lark - [OpenXLab Web](https://openxlab.org.cn/apps/detail/tpoisonooo/huixiangdou-web) - [Gradio Demo](./huixiangdou/gradio_ui.py) - [HTTP Server](./huixiangdou/api_server.py) - [Read the Docs](./docs/zh/doc_add_readthedocs.md) </td> <td> - [Coreference Resolution](https://arxiv.org/abs/2405.02817) </td> </tr> </tbody> </table> # 📦 Hardware Requirements The following are the GPU memory requirements for different features, the difference lies only in whether the **options are turned on**. | Configuration Example | GPU mem Requirements | Description | Verified on Linux | | :----------------------------------------------: | :------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------: | | [config-cpu.ini](./config-cpu.ini) | - | Use [siliconcloud](https://siliconflow.cn/) API <br/> for text only | ![](https://img.shields.io/badge/x86-passed-blue?style=for-the-badge) | | \[Standard Edition\][config.ini](./config.ini) | 2GB | Use openai API (such as [kimi](https://kimi.moonshot.cn), [deepseek](https://platform.deepseek.com/usage) and [stepfun](https://platform.stepfun.com/) to search for text only | ![](https://img.shields.io/badge/1660ti%206G-passed-blue?style=for-the-badge) | | [config-multimodal.ini](./config-multimodal.ini) | 10GB | Use openai API for LLM, image and text retrieval | ![](https://img.shields.io/badge/3090%2024G-passed-blue?style=for-the-badge) | # 🔥 Running the Standard Edition We take the standard edition (local running LLM, text retrieval) as an introduction example. Other versions are just different in configuration options. ## I. Download and install dependencies [Click to agree to the BCE model agreement](https://huggingface.co/maidalun1020/bce-embedding-base_v1), log in huggingface ```shell huggingface-cli login ``` Install dependencies ```bash # parsing `word` format requirements apt update apt install python-dev libxml2-dev libxslt1-dev antiword unrtf poppler-utils pstotext tesseract-ocr flac ffmpeg lame libmad0 libsox-fmt-mp3 sox libjpeg-dev swig libpulse-dev # python requirements pip install -r requirements.txt # For python3.8, install faiss-gpu instead of faiss ``` ## II. Create knowledge base We use some novels to build knowledge base and filtering questions. If you have your own documents, just put them under `repodir`. Copy and execute all the following commands (including the '#' symbol). ```shell # Download the knowledge base, we only take the some documents as example. You can put any of your own documents under `repodir` cd HuixiangDou mkdir repodir cp -rf resource/data* repodir/ # Build knowledge base, this will save the features of repodir to workdir, and update the positive and negative example thresholds into `config.ini` mkdir workdir python3 -m huixiangdou.services.store # You can also build knowledge base from QA pairs (CSV or JSON format) # CSV: First column is key (question), second column is value (answer) # JSON: {"question1": "answer1", "question2": "answer2", ...} # python3 -m huixiangdou.services.store --qa-pair resource/data/qa_pair.csv ``` ## III. Setup LLM API and test Set the model and `api-key` in `config.ini`. If running LLM locally, we recommend using `vllm`. ```text vllm serve /path/to/Qwen-2.5-7B-Instruct --served-model-name vllm --enable-prefix-caching --served-model-name Qwen-2.5-7B-Instruct ``` Here is an example of the configured `config.ini`: ```ini [llm.server] remote_type = "kimi" remote_api_key = "sk-dp3GriuhhLXnYo0KUuWbFUWWKOXXXXXXXXXX" remote_llm_model = "auto" # remote_type = "step" # remote_api_key = "5CpPyYNPhQMkIzs5SYfcdbTHXq3a72H5XXXXXXXXXXXXX" # remote_llm_model = "auto" # remote_type = "deepseek" # remote_api_key = "sk-86db9a205aa9422XXXXXXXXXXXXXX" # remote_llm_model = "deepseek-chat" # remote_type = "vllm" # remote_api_key = "EMPTY" # remote_llm_model = "Qwen2.5-7B-Instruct" # remote_type = "siliconcloud" # remote_api_key = "sk-xxxxxxxxxxxxx" # remote_llm_model = "alibaba/Qwen1.5-110B-Chat" # remote_type = "ppio" # remote_api_key = "sk-xxxxxxxxxxxxx" # remote_llm_model = "thudm/glm-4-9b-chat" ``` Then run the test: ```text # Respond to questions related to the Hundred-Plant Garden (related to the knowledge base), but do not respond to weather questions. python3 -m huixiangdou.main +-----------------------+---------+--------------------------------+-----------------+ | Query | State | Reply | References | +=======================+=========+================================+=================+ | What is in the Hundred-Plant Garden? | success | The Hundred-Plant Garden has a rich variety of natural landscapes and life... | installation.md | -------------------------------------------------------------------------------------- | How is the weather today? | Init state| .. | | +-----------------------+---------+--------------------------------+-----------------+ 🔆 Input your question here, type `bye` for exit: .. ``` 💡 Also run a simple Web UI with `gradio`: ```bash python3 -m huixiangdou.gradio_ui ``` <video src="https://github.com/user-attachments/assets/9e5dbb30-1dc1-42ad-a7d4-dc7380676554" ></video> Or run a server to listen 23333, default pipeline is `chat_with_repo`: ```bash python3 -m huixiangdou.api_server # test async API curl -X POST http://127.0.0.1:23333/huixiangdou_stream -H "Content-Type: application/json" -d '{"text": "how to install mmpose","image": ""}' # cURL sync API curl -X POST http://127.0.0.1:23333/huixiangdou_inference -H "Content-Type: application/json" -d '{"text": "how to install mmpose","image": ""}' ``` Please update the `repodir` documents, [good_questions](./resource/good_questions.json) and [bad_questions](./resource/bad_questions.json), and try your own domain knowledge (medical, financial, power, etc.). ## IV. Integration ### To Feishu, WeChat group - [**One-way** sending to Feishu group](./docs/zh/doc_send_only_lark_group.md) - [**Two-way** Feishu group receiving and sending, recalling](./docs/zh/doc_add_lark_group.md) - [Personal WeChat Android access](./docs/zh/doc_add_wechat_accessibility.md) and [Android tool](./android) - [Personal WeChat wkteam access](./docs/zh/doc_add_wechat_commercial.md) ### To web front and backend We provide `typescript` front-end and `python` back-end source code: - Multi-tenant management supported - Zero programming access to Feishu and WeChat - k8s friendly Same as [OpenXlab APP](https://openxlab.org.cn/apps/detail/tpoisonooo/huixiangdou-web), please read the [web deployment document](./web/README.md). ### To readthedocs.io [Try right-bottom button on the page](https://huixiangdou.readthedocs.io/zh-cn/latest/) and [document](./docs/zh/doc_add_readthedocs.md). # 🍴 Other Configurations ## **CPU-only Edition** If there is no GPU available, model inference can be completed using the [siliconcloud](https://siliconflow.cn/) API. Taking docker miniconda+Python3.11 as an example, install CPU dependencies and run: ```bash # Start container docker run -v /path/to/huixiangdou:/huixiangdou -p 7860:7860 -p 23333:23333 -it continuumio/miniconda3 /bin/bash # Install dependencies apt update apt install python-dev libxml2-dev libxslt1-dev antiword unrtf poppler-utils pstotext tesseract-ocr flac ffmpeg lame libmad0 libsox-fmt-mp3 sox libjpeg-dev swig libpulse-dev python3 -m pip install -r requirements-cpu.txt # Establish knowledge base python3 -m huixiangdou.services.store --config_path config-cpu.ini # Q&A test python3 -m huixiangdou.main --config_path config-cpu.ini # gradio UI python3 -m huixiangdou.gradio_ui --config_path config-cpu.ini ``` If you find the installation too slow, a pre-installed image is provided in [Docker Hub](https://hub.docker.com/repository/docker/tpoisonooo/huixiangdou/tags). Simply replace it when starting the docker. ## **10G Multimodal Edition** If you have 10G GPU mem, you can further support image and text retrieval. Just modify the model used in config.ini. ```toml # config-multimodal.ini # !!! Download `https://huggingface.co/BAAI/bge-visualized/blob/main/Visualized_m3.pth` to `bge-m3` folder !!! embedding_model_path = "BAAI/bge-m3" reranker_model_path = "BAAI/bge-reranker-v2-minicpm-layerwise" ``` Note: - You need to manually download [Visualized_m3.pth](https://huggingface.co/BAAI/bge-visualized/blob/main/Visualized_m3.pth) to the [bge-m3](https://huggingface.co/BAAI/bge-m3) directory - Install FlagEmbedding on main branch, we have made [bugfix](https://github.com/FlagOpen/FlagEmbedding/commit/3f84da0796d5badc3ad519870612f1f18ff0d1d3). [Here](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/visual/eva_clip/bpe_simple_vocab_16e6.txt.gz) you can download `bpe_simple_vocab_16e6.txt.gz` - Install [requirements/multimodal.txt](./requirements/multimodal.txt) Run gradio to test, see the image and text retrieval result [here](https://github.com/InternLM/HuixiangDou/pull/326). ```bash python3 tests/test_query_gradio.py ``` ## **Furthermore** Please read the following topics: - [Hybrid knowledge graph and dense retrieval](./docs/en/doc_knowledge_graph.md) - [Refer to config-advanced.ini configuration to improve effects](./docs/en/doc_full_dev.md) - [Group chat scenario anaphora resolution training](./sft) - [Use wkteam WeChat access, integrate images, public account parsing, and anaphora resolution](./docs/zh/doc_add_wechat_commercial.md) - [Use rag.py to annotate SFT training data](./docs/zh/doc_rag_annotate_sft_data.md) # 🛠️ FAQ 1. What if the robot is too cold/too chatty? - Fill in the questions that should be answered in the real scenario into `resource/good_questions.json`, and fill the ones that should be rejected into `resource/bad_questions.json`. - Adjust the theme content in `repodir` to ensure that the markdown documents in the main library do not contain irrelevant content. Re-run `feature_store` to update thresholds and feature libraries. ⚠️ You can directly modify `reject_throttle` in config.ini. Generally speaking, 0.5 is a high value; 0.2 is too low. 2. Launch is normal, but out of memory during runtime? LLM long text based on transformers structure requires more memory. At this time, kv cache quantization needs to be done on the model, such as [lmdeploy quantization description](https://github.com/InternLM/lmdeploy/blob/main/docs/en/quantization). Then use docker to independently deploy Hybrid LLM Service. 7. `No module named 'faiss.swigfaiss_avx2'` locate installed `faiss` package ```python import faiss print(faiss.__file__) # /root/.conda/envs/InternLM2_Huixiangdou/lib/python3.10/site-packages/faiss/__init__.py ``` add soft link ```Bash # cd your_python_path/site-packages/faiss cd /root/.conda/envs/InternLM2_Huixiangdou/lib/python3.10/site-packages/faiss/ ln -s swigfaiss.py swigfaiss_avx2.py ``` # 🍀 Acknowledgements - [KIMI](https://kimi.moonshot.cn/): Long text LLM, supports direct file upload - [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding): BAAI RAG group - [BCEmbedding](https://github.com/netease-youdao/BCEmbedding): Chinese-English bilingual feature model - [Langchain-ChatChat](https://github.com/chatchat-space/Langchain-Chatchat): Application of Langchain and ChatGLM - [GrabRedEnvelope](https://github.com/xbdcc/GrabRedEnvelope): WeChat red packet grab # 📝 Citation ```shell @misc{kong2024huixiangdou, title={HuiXiangDou: Overcoming Group Chat Scenarios with LLM-based Technical Assistance}, author={Huanjun Kong and Songyang Zhang and Jiaying Li and Min Xiao and Jun Xu and Kai Chen}, year={2024}, eprint={2401.08772}, archivePrefix={arXiv}, primaryClass={cs.CL} } @misc{kong2024labelingsupervisedfinetuningdata, title={Labeling supervised fine-tuning data with the scaling law}, author={Huanjun Kong}, year={2024}, eprint={2405.02817}, archivePrefix={arXiv}, primaryClass={cs.CL}, url={https://arxiv.org/abs/2405.02817}, } @misc{kong2025huixiangdou2robustlyoptimizedgraphrag, title={HuixiangDou2: A Robustly Optimized GraphRAG Approach}, author={Huanjun Kong and Zhefan Wang and Chenyang Wang and Zhe Ma and Nanqing Dong}, year={2025}, eprint={2503.06474}, archivePrefix={arXiv}, primaryClass={cs.IR}, url={https://arxiv.org/abs/2503.06474}, } ```

AI Agents Knowledge Bases & RAG
2.5K Github Stars
Agent-FLAN
Open Source

Agent-FLAN

# Agent-FLAN: Designing Data and Methods of Effective Agent Tuning for Large Language Models [![arXiv](https://img.shields.io/badge/arXiv-2403.12881-b31b1b.svg)](https://arxiv.org/abs/2403.12881) [![license](https://img.shields.io/github/license/InternLM/opencompass.svg)](./LICENSE) [![Open in OpenXLab](https://cdn-static.openxlab.org.cn/header/openxlab_models.svg)](https://openxlab.org.cn/models/detail/OpenLMLab/Agent-FLAN-7b) ## ✨ Introduction [[🤗 HuggingFace](https://huggingface.co/internlm/Agent-FLAN-7b)] [[🧰 OpenXLab](https://openxlab.org.cn/models/detail/OpenLMLab/Agent-FLAN-7b)] [[📃 Paper](https://arxiv.org/abs/2403.12881)] [[🌐 Project Page](https://internlm.github.io/Agent-FLAN/)] > Open-sourced Large Language Models (LLMs) have achieved great success in various NLP tasks, however, they are still far inferior to API-based models when acting as agents. How to integrate agent ability into general LLMs becomes a crucial and urgent problem. This paper first delivers three key observations: (1) the current agent training corpus is entangled with both formats following and agent reasoning, which significantly shifts from the distribution of its pre-training data; (2) LLMs exhibit different learning speeds on the capabilities required by agent tasks; and (3) current approaches have side-effects when improving agent abilities by introducing hallucinations. Based on the above findings, we propose Agent-FLAN to effectively Fine-tune LANguage models for Agents. Through careful decomposition and redesign of the training corpus, Agent-FLAN enables Llama2-7B to outperform prior best works by 3.5% across various agent evaluation datasets. With comprehensively constructed negative samples, Agent-FLAN greatly alleviates the hallucination issues based on our established evaluation benchmark. Besides, it consistently improves the agent capability of LLMs when scaling model sizes while slightly enhancing the general capability of LLMs. ## 🚀 What's New - **[2024.3.21]** Paper available on [ArXiv](https://arxiv.org/abs/2403.12881). 🔥🔥🔥 - **[2024.3.20]** Release the dataset and model checkpoint for Agent-FLAN. 🎉🎉🎉 ## ♟️ Agent-FLAN Agent-FLAN series are finetuned on AgentInstruct and Toolbench by applying the data generation pipeline proposed in Agent-FLAN paper, which holds strong abilities on various agent tasks and tool utilization~ <div> <center> <img src="docs/figure/teaser.png"> Comparison of recent agent tuning approaches on Held-In, Held-Out tasks. Performances are normalized with GPT-4 results for better visualization. * denotes our re-implementation for a fair comparison. </div> ### 🤗 HuggingFace Model & Dataset Agent-FLAN is produced by mixed training on AgentInstruct, ToolBench, and ShareGPT datasets from the Llama2-chat series. The models follow the conversation format of Llama-2-chat, with the template protocol as: ```python dict(role='user', begin='<|Human|>െ', end='\n '), dict(role='system', begin='<|Human|>െ', end='\n '), dict(role='assistant', begin='<|Assistant|>െ', end='ി\n '), ``` The 7B model is available on Huggingface & OpenXLab model hub. | Model | Huggingface Repo | OpenXLab Repo | | :---------: | :------------------------------------------------------------: | :----------------------------------------: | | Agent-FLAN-7B | [Model Link](https://huggingface.co/internlm/Agent-FLAN-7b) | [Model Link](https://openxlab.org.cn/models/detail/OpenLMLab/Agent-FLAN-7b) | The Agent-FLAN dataset is also available on Huggingface dataset hub. | Dataset | Huggingface Repo | | :---------: | :------------------------------------------------------------: | | Agent-FLAN | [Dataset Link](https://huggingface.co/datasets/internlm/Agent-FLAN) | ## 💫 Detailed Results <div> <center> <img src="docs/figure/performance.png" width="100%"> </div> Main results of Agent-FLAN. Agent-FLAN significantly outperforms previous agent-tuning approaches by a large margin on both held-in and held-out tasks. * denotes our re-implementation with the same amount of training data for a fair comparison. Since FireAct does not train on AgentInstruct dataset, we omit its performance on the HELD-IN set. Bold: the best in API-based and open-sourced models. ## ❤️ Acknowledgements Agent-FLAN is built with [Lagent](https://github.com/InternLM/lagent) and [T-Eval](https://github.com/open-compass/t-eval). Thanks for their awesome work! ## 🖊️ Citation If you find this project useful in your research, please consider cite: ``` @article{chen2024agent, title={Agent-FLAN: Designing Data and Methods of Effective Agent Tuning for Large Language Models}, author={Chen, Zehui and Liu, Kuikun and Wang, Qiuchen and Zhang, Wenwei and Liu, Jiangning and Lin, Dahua and Chen, Kai and Zhao, Feng}, journal={arXiv preprint arXiv:2403.12881}, year={2024} } ``` ## 💳 License This project is released under the Apache 2.0 [license](./LICENSE).

AI Agents ML Frameworks
361 Github Stars