[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-mistralai--mistral-inference":3,"tool-mistralai--mistral-inference":61},[4,18,28,37,45,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":24,"last_commit_at":25,"category_tags":26,"status":17},9989,"n8n","n8n-io\u002Fn8n","n8n 是一款面向技术团队的公平代码（fair-code）工作流自动化平台，旨在让用户在享受低代码快速构建便利的同时，保留编写自定义代码的灵活性。它主要解决了传统自动化工具要么过于封闭难以扩展、要么完全依赖手写代码效率低下的痛点，帮助用户轻松连接 400 多种应用与服务，实现复杂业务流程的自动化。\n\nn8n 特别适合开发者、工程师以及具备一定技术背景的业务人员使用。其核心亮点在于“按需编码”：既可以通过直观的可视化界面拖拽节点搭建流程，也能随时插入 JavaScript 或 Python 代码、调用 npm 包来处理复杂逻辑。此外，n8n 原生集成了基于 LangChain 的 AI 能力，支持用户利用自有数据和模型构建智能体工作流。在部署方面，n8n 提供极高的自由度，支持完全自托管以保障数据隐私和控制权，也提供云端服务选项。凭借活跃的社区生态和数百个现成模板，n8n 让构建强大且可控的自动化系统变得简单高效。",184740,2,"2026-04-19T23:22:26",[16,14,13,15,27],"插件",{"id":29,"name":30,"github_repo":31,"description_zh":32,"stars":33,"difficulty_score":10,"last_commit_at":34,"category_tags":35,"status":17},10095,"AutoGPT","Significant-Gravitas\u002FAutoGPT","AutoGPT 是一个旨在让每个人都能轻松使用和构建 AI 的强大平台，核心功能是帮助用户创建、部署和管理能够自动执行复杂任务的连续型 AI 智能体。它解决了传统 AI 应用中需要频繁人工干预、难以自动化长流程工作的痛点，让用户只需设定目标，AI 即可自主规划步骤、调用工具并持续运行直至完成任务。\n\n无论是开发者、研究人员，还是希望提升工作效率的普通用户，都能从 AutoGPT 中受益。开发者可利用其低代码界面快速定制专属智能体；研究人员能基于开源架构探索多智能体协作机制；而非技术背景用户也可直接选用预置的智能体模板，立即投入实际工作场景。\n\nAutoGPT 的技术亮点在于其模块化“积木式”工作流设计——用户通过连接功能块即可构建复杂逻辑，每个块负责单一动作，灵活且易于调试。同时，平台支持本地自托管与云端部署两种模式，兼顾数据隐私与使用便捷性。配合完善的文档和一键安装脚本，即使是初次接触的用户也能在几分钟内启动自己的第一个 AI 智能体。AutoGPT 正致力于降低 AI 应用门槛，让人人都能成为 AI 的创造者与受益者。",183572,"2026-04-20T04:47:55",[13,36,27,14,15],"语言模型",{"id":38,"name":39,"github_repo":40,"description_zh":41,"stars":42,"difficulty_score":10,"last_commit_at":43,"category_tags":44,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":46,"name":47,"github_repo":48,"description_zh":49,"stars":50,"difficulty_score":24,"last_commit_at":51,"category_tags":52,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",161692,"2026-04-20T11:33:57",[14,13,36],{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":24,"last_commit_at":59,"category_tags":60,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",109154,"2026-04-18T11:18:24",[14,15,13],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":74,"owner_company":76,"owner_location":76,"owner_email":77,"owner_twitter":76,"owner_website":78,"owner_url":79,"languages":80,"stars":97,"forks":98,"last_commit_at":99,"license":100,"difficulty_score":10,"env_os":101,"env_gpu":102,"env_ram":101,"env_deps":103,"category_tags":114,"github_topics":115,"view_count":24,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":118,"updated_at":119,"faqs":120,"releases":149},10202,"mistralai\u002Fmistral-inference","mistral-inference","Official inference library for Mistral models","mistral-inference 是 Mistral AI 官方推出的轻量级推理库，旨在帮助开发者高效运行各类 Mistral 系列大语言模型。它解决了在本地环境中部署和调用高性能开源模型时常见的配置复杂、依赖繁琐等痛点，提供了一套极简的代码实现，让用户能快速上手体验从 7B 到 8x22B 等不同规模的模型，包括专为代码生成的 Codestral 和擅长数学推理的 Mathstral 等垂直领域模型。\n\n这款工具主要面向具备一定技术背景的开发者与研究人员，特别是那些希望在本地 GPU 环境中进行模型测试、原型开发或深度集成的用户。通过简单的 pip 安装或源码克隆，配合必要的 GPU 环境（需安装 xformers），即可轻松加载官方提供的多种模型权重。其核心亮点在于“最小化代码”设计理念，去除了冗余封装，直接暴露底层推理逻辑，既保证了运行效率，也方便用户根据需求进行定制化修改。此外，它还支持包括混合专家架构（MoE）在内的多种先进模型结构，为探索前沿大模型技术提供了灵活可靠的基础设施。无论是想快速验证算法思路的研究者，还是构建本地化 AI 应用的工程师，mistral-infer","mistral-inference 是 Mistral AI 官方推出的轻量级推理库，旨在帮助开发者高效运行各类 Mistral 系列大语言模型。它解决了在本地环境中部署和调用高性能开源模型时常见的配置复杂、依赖繁琐等痛点，提供了一套极简的代码实现，让用户能快速上手体验从 7B 到 8x22B 等不同规模的模型，包括专为代码生成的 Codestral 和擅长数学推理的 Mathstral 等垂直领域模型。\n\n这款工具主要面向具备一定技术背景的开发者与研究人员，特别是那些希望在本地 GPU 环境中进行模型测试、原型开发或深度集成的用户。通过简单的 pip 安装或源码克隆，配合必要的 GPU 环境（需安装 xformers），即可轻松加载官方提供的多种模型权重。其核心亮点在于“最小化代码”设计理念，去除了冗余封装，直接暴露底层推理逻辑，既保证了运行效率，也方便用户根据需求进行定制化修改。此外，它还支持包括混合专家架构（MoE）在内的多种先进模型结构，为探索前沿大模型技术提供了灵活可靠的基础设施。无论是想快速验证算法思路的研究者，还是构建本地化 AI 应用的工程师，mistral-inference 都是一个值得尝试的实用选择。","# Mistral Inference\n\u003Ca target=\"_blank\" href=\"https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fmistralai\u002Fmistral-inference\u002Fblob\u002Fmain\u002Ftutorials\u002Fgetting_started.ipynb\">\n  \u003Cimg src=\"https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg\" alt=\"Open In Colab\"\u002F>\n\u003C\u002Fa>\n\n\nThis repository contains minimal code to run Mistral models.\n\nBlog 7B: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fannouncing-mistral-7b\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fannouncing-mistral-7b\u002F)\\\nBlog 8x7B: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-of-experts\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-of-experts\u002F)\\\nBlog 8x22B: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-8x22b\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-8x22b\u002F)\\\nBlog Codestral 22B: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral\u002F) \\\nBlog Codestral Mamba 7B: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F) \\\nBlog Mathstral 7B: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F) \\\nBlog Nemo: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-nemo\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-nemo\u002F) \\\nBlog Mistral Large 2: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-large-2407\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-large-2407\u002F) \\\nBlog Pixtral 12B: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fpixtral-12b\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fpixtral-12b\u002F)\nBlog Mistral Small 3.1: [https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-small-3-1\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-small-3-1\u002F)\n\nDiscord: [https:\u002F\u002Fdiscord.com\u002Finvite\u002Fmistralai](https:\u002F\u002Fdiscord.com\u002Finvite\u002Fmistralai)\\\nDocumentation: [https:\u002F\u002Fdocs.mistral.ai\u002F](https:\u002F\u002Fdocs.mistral.ai\u002F)\\\nGuardrailing: [https:\u002F\u002Fdocs.mistral.ai\u002Fusage\u002Fguardrailing](https:\u002F\u002Fdocs.mistral.ai\u002Fusage\u002Fguardrailing)\n\n## Installation\n\nNote: You will use a GPU to install `mistral-inference`, as it currently requires `xformers` to be installed and `xformers` itself needs a GPU for installation.\n\n### PyPI\n\n```\npip install mistral-inference\n```\n\n### Local\n\n```\ncd $HOME && git clone https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\ncd $HOME\u002Fmistral-inference && poetry install .\n```\n\n## Model download\n\n### Direct links\n\n| Name        | Download | md5sum |\n|-------------|-------|-------|\n| 7B Instruct | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-7b-v0-3\u002Fmistral-7B-Instruct-v0.3.tar | `80b71fcb6416085bcb4efad86dfb4d52` |\n| 8x7B Instruct | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x7b-v0-1\u002FMixtral-8x7B-v0.1-Instruct.tar (**Updated model coming soon!**) | `8e2d3930145dc43d3084396f49d38a3f` |\n| 8x22 Instruct | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x22b-v0-3\u002Fmixtral-8x22B-Instruct-v0.3.tar | `471a02a6902706a2f1e44a693813855b` |\n| 7B Base | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-7b-v0-3\u002Fmistral-7B-v0.3.tar | `0663b293810d7571dad25dae2f2a5806` |\n| 8x7B |     **Updated model coming soon!**       | - |\n| 8x22B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x22b-v0-3\u002Fmixtral-8x22B-v0.3.tar | `a2fa75117174f87d1197e3a4eb50371a` |\n| Codestral 22B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fcodestral-22b-v0-1\u002Fcodestral-22B-v0.1.tar | `1ea95d474a1d374b1d1b20a8e0159de3` |\n| Mathstral 7B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmathstral-7b-v0-1\u002Fmathstral-7B-v0.1.tar | `5f05443e94489c261462794b1016f10b` |\n| Codestral-Mamba 7B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fcodestral-mamba-7b-v0-1\u002Fcodestral-mamba-7B-v0.1.tar | `d3993e4024d1395910c55db0d11db163` |\n| Nemo Base | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-base-2407.tar | `c5d079ac4b55fc1ae35f51f0a3c0eb83` |\n| Nemo Instruct | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-instruct-2407.tar | `296fbdf911cb88e6f0be74cd04827fe7` |\n| Mistral Large 2 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-large-2407\u002Fmistral-large-instruct-2407.tar | `fc602155f9e39151fba81fcaab2fa7c4` |\n\nNote:\n- **Important**:\n  - `mixtral-8x22B-Instruct-v0.3.tar` is exactly the same as [Mixtral-8x22B-Instruct-v0.1](https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMixtral-8x22B-Instruct-v0.1), only stored in `.safetensors` format\n  - `mixtral-8x22B-v0.3.tar` is the same as [Mixtral-8x22B-v0.1](https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMixtral-8x22B-v0.1), but has an extended vocabulary of 32768 tokens.\n  - `codestral-22B-v0.1.tar` has a custom non-commercial license, called [Mistral AI Non-Production (MNPL) License](https:\u002F\u002Fmistral.ai\u002Flicenses\u002FMNPL-0.1.md)\n  - `mistral-large-instruct-2407.tar` has a custom non-commercial license, called [Mistral AI Research (MRL) License](https:\u002F\u002Fmistral.ai\u002Flicenses\u002FMRL-0.1.md)\n- All of the listed models above support function calling. For example, Mistral 7B Base\u002FInstruct v3 is a minor update to Mistral 7B Base\u002FInstruct v2,  with the addition of function calling capabilities.\n- The \"coming soon\" models will include function calling as well.\n- You can download the previous versions of our models from our [docs](https:\u002F\u002Fdocs.mistral.ai\u002Fgetting-started\u002Fopen_weight_models\u002F#downloading).\n\n### From Hugging Face Hub\n\n| Name        | ID | URL |\n|-------------|-------|-------|\n| Pixtral Large Instruct | mistralai\u002FPixtral-Large-Instruct-2411 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FPixtral-Large-Instruct-2411 |\n| Pixtral 12B Base | mistralai\u002FPixtral-12B-Base-2409 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FPixtral-12B-Base-2409 |\n| Pixtral 12B | mistralai\u002FPixtral-12B-2409 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FPixtral-12B-2409 |\n| Mistral Small 3.1 24B Base | mistralai\u002FMistral-Small-3.1-24B-Base-2503 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMistral-Small-3.1-24B-Base-2503\n| Mistral Small 3.1 24B Instruct | mistralai\u002FMistral-Small-3.1-24B-Instruct-2503 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMistral-Small-3.1-24B-Instruct-2503 |\n\n\n### Usage\n\n**News!!!**: Mistral Large 2 is out. Read more about its capabilities [here](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-large-2407\u002F).\n\nCreate a local folder to store models\n```sh\nexport MISTRAL_MODEL=$HOME\u002Fmistral_models\nmkdir -p $MISTRAL_MODEL\n```\n\nDownload any of the above links and extract the content, *e.g.*:\n\n```sh\nexport 12B_DIR=$MISTRAL_MODEL\u002F12B_Nemo\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-instruct-2407.tar\nmkdir -p $12B_DIR\ntar -xf mistral-nemo-instruct-2407.tar -C $12B_DIR\n```\n\nor\n\n```sh\nexport M8x7B_DIR=$MISTRAL_MODEL\u002F8x7b_instruct\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x7b-v0-1\u002FMixtral-8x7B-v0.1-Instruct.tar\nmkdir -p $M8x7B_DIR\ntar -xf Mixtral-8x7B-v0.1-Instruct.tar -C $M8x7B_DIR\n```\n\nFor Hugging Face models' weights, here is an example to download [Mistral Small 3.1 24B Instruct](https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMistral-Small-3.1-24B-Instruct-2503):\n\n```python\nfrom pathlib import Path\nfrom huggingface_hub import snapshot_download\n\n\nmistral_models_path = Path.home().joinpath(\"mistral_models\")\n\nmodel_path = mistral_models_path \u002F \"mistral-small-3.1-instruct\"\nmodel_path.mkdir(parents=True, exist_ok=True)\n\nrepo_id = \"mistralai\u002FMistral-Small-3.1-24B-Instruct-2503\"\n\nsnapshot_download(\n    repo_id=repo_id,\n    allow_patterns=[\"params.json\", \"consolidated.safetensors\", \"tekken.json\"],\n    local_dir=model_path,\n)\n```\n\n## Usage\n\nThe following sections give an overview of how to run the model from the Command-line interface (CLI) or directly within Python.\n\n### CLI\n\n- **Demo**\n\nTo test that a model works in your setup, you can run the `mistral-demo` command.\n*E.g.* the 12B Mistral-Nemo model can be tested on a single GPU as follows:\n\n```sh\nmistral-demo $12B_DIR\n```\n\nLarge models, such **8x7B** and **8x22B** have to be run in a multi-GPU setup.\nFor these models, you can use the following command:\n\n```sh\ntorchrun --nproc-per-node 2 --no-python mistral-demo $M8x7B_DIR\n```\n\n*Note*: Change `--nproc-per-node` to more GPUs if available.\n\n- **Chat**\n\nTo interactively chat with the models, you can make use of the `mistral-chat` command.\n\n```sh\nmistral-chat $12B_DIR --instruct --max_tokens 1024 --temperature 0.35\n```\n\nFor large models, you can make use of `torchrun`.\n\n```sh\ntorchrun --nproc-per-node 2 --no-python mistral-chat $M8x7B_DIR --instruct\n```\n\n*Note*: Change `--nproc-per-node` to more GPUs if necessary (*e.g.* for 8x22B).\n\n- **Chat with Codestral**\n\nTo use [Codestral](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral\u002F) as a coding assistant you can run the following command using `mistral-chat`.\nMake sure `$M22B_CODESTRAL` is set to a valid path to the downloaded codestral folder, e.g. `$HOME\u002Fmistral_models\u002FCodestral-22B-v0.1`\n\n```sh\nmistral-chat $M22B_CODESTRAL --instruct --max_tokens 256\n```\n\nIf you prompt it with *\"Write me a function that computes fibonacci in Rust\"*, the model should generate something along the following lines:\n\n```sh\nSure, here's a simple implementation of a function that computes the Fibonacci sequence in Rust. This function takes an integer `n` as an argument and returns the `n`th Fibonacci number.\n\nfn fibonacci(n: u32) -> u32 {\n    match n {\n        0 => 0,\n        1 => 1,\n        _ => fibonacci(n - 1) + fibonacci(n - 2),\n    }\n}\n\nfn main() {\n    let n = 10;\n    println!(\"The {}th Fibonacci number is: {}\", n, fibonacci(n));\n}\n\nThis function uses recursion to calculate the Fibonacci number. However, it's not the most efficient solution because it performs a lot of redundant calculations. A more efficient solution would use a loop to iteratively calculate the Fibonacci numbers.\n```\n\nYou can continue chatting afterwards, *e.g.* with *\"Translate it to Python\"*.\n\n- **Chat with Codestral-Mamba**\n\nTo use [Codestral-Mamba](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F) as a coding assistant you can run the following command using `mistral-chat`.\nMake sure `$7B_CODESTRAL_MAMBA` is set to a valid path to the downloaded codestral-mamba folder, e.g. `$HOME\u002Fmistral_models\u002Fmamba-codestral-7B-v0.1`.\n\nYou then need to additionally install the following packages:\n\n```\npip install packaging mamba-ssm causal-conv1d transformers\n```\n\nbefore you can start chatting:\n\n```sh\nmistral-chat $7B_CODESTRAL_MAMBA --instruct --max_tokens 256\n```\n\n- **Chat with Mathstral**\n\nTo use [Mathstral](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F) as an assistant you can run the following command using `mistral-chat`.\nMake sure `$7B_MATHSTRAL` is set to a valid path to the downloaded codestral folder, e.g. `$HOME\u002Fmistral_models\u002Fmathstral-7B-v0.1`\n\n```sh\nmistral-chat $7B_MATHSTRAL --instruct --max_tokens 256\n```\n\nIf you prompt it with *\"Albert likes to surf every week. Each surfing session lasts for 4 hours and costs $20 per hour. How much would Albert spend in 5 weeks?\"*, the model should answer with the correct calculation.\n\nYou can then continue chatting afterwards, *e.g.* with *\"How much would he spend in a year?\"*.\n\n- **Chat with Mistral Small 3.1 24B Instruct**\n\nTo use [Mistral Small 3.1 24B Instruct](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-small-3-1\u002F) as an assistant you can run the following command using `mistral-chat`.\nMake sure `$MISTRAL_SMALL_3_1_INSTRUCT` is set to a valid path to the downloaded mistral small folder, e.g. `$HOME\u002Fmistral_models\u002Fmistral-small-3.1-instruct`\n\n```sh\n    mistral-chat $MISTRAL_SMALL_3_1_INSTRUCT --instruct --max_tokens 256\n```\n\nIf you prompt it with *\"The above image presents an image of which park ? Please give the hints to identify the park.\"* with the following image URL *https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fpatrickvonplaten\u002Frandom_img\u002Fresolve\u002Fmain\u002Fyosemite.png*, the model should answer with the Yosemite park and give hints to identify it.\n\nYou can then continue chatting afterwards, *e.g.* with *\"What is the name of the lake in the image?\"*. The model should respond that it is not a lake but a river.\n\n### Python\n\n- *Instruction Following*:\n\n```py\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\n\n\ntokenizer = MistralTokenizer.from_file(\".\u002Fmistral-nemo-instruct-v0.1\u002Ftekken.json\")  # change to extracted tokenizer file\nmodel = Transformer.from_folder(\".\u002Fmistral-nemo-instruct-v0.1\")  # change to extracted model dir\n\nprompt = \"How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar.\"\n\ncompletion_request = ChatCompletionRequest(messages=[UserMessage(content=prompt)])\n\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=1024, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])\n\nprint(result)\n```\n\n- *Multimodal Instruction Following*:\n\n\n```python\nfrom pathlib import Path\n\nfrom huggingface_hub import snapshot_download\nfrom mistral_common.protocol.instruct.messages import ImageURLChunk, TextChunk\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_inference.generate import generate\nfrom mistral_inference.transformer import Transformer\n\nmodel_path = Path.home().joinpath(\"mistral_models\") \u002F \"mistral-small-3.1-instruct\" # change to extracted model\n\ntokenizer = MistralTokenizer.from_file(model_path \u002F \"tekken.json\")\nmodel = Transformer.from_folder(model_path)\n\nurl = \"https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fpatrickvonplaten\u002Frandom_img\u002Fresolve\u002Fmain\u002Fyosemite.png\"\nprompt = \"The above image presents an image of which park ? Please give the hints to identify the park.\"\n\nuser_content = [ImageURLChunk(image_url=url), TextChunk(text=prompt)]\n\ntokens, images = tokenizer.instruct_tokenizer.encode_user_content(user_content, False)\n\nout_tokens, _ = generate(\n    [tokens],\n    model,\n    images=[images],\n    max_tokens=256,\n    temperature=0.15,\n    eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id,\n)\nresult = tokenizer.decode(out_tokens[0])\n\nprint(\"Prompt:\", prompt)\nprint(\"Completion:\", result)\n```\n\n- *Function Calling*:\n\n```py\nfrom mistral_common.protocol.instruct.tool_calls import Function, Tool\n\ncompletion_request = ChatCompletionRequest(\n    tools=[\n        Tool(\n            function=Function(\n                name=\"get_current_weather\",\n                description=\"Get the current weather\",\n                parameters={\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"location\": {\n                            \"type\": \"string\",\n                            \"description\": \"The city and state, e.g. San Francisco, CA\",\n                        },\n                        \"format\": {\n                            \"type\": \"string\",\n                            \"enum\": [\"celsius\", \"fahrenheit\"],\n                            \"description\": \"The temperature unit to use. Infer this from the users location.\",\n                        },\n                    },\n                    \"required\": [\"location\", \"format\"],\n                },\n            )\n        )\n    ],\n    messages=[\n        UserMessage(content=\"What's the weather like today in Paris?\"),\n        ],\n)\n\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])\n\nprint(result)\n```\n\n- *Fill-in-the-middle (FIM)*:\n\nMake sure to have `mistral-common >= 1.2.0` installed:\n```\npip install --upgrade mistral-common\n```\n\nYou can simulate a code completion in-filling as follows.\n\n```py\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.tokens.instruct.request import FIMRequest\n\ntokenizer = MistralTokenizer.from_model(\"codestral-22b\")\nmodel = Transformer.from_folder(\".\u002Fmistral_22b_codestral\")\n\nprefix = \"\"\"def add(\"\"\"\nsuffix = \"\"\"    return sum\"\"\"\n\nrequest = FIMRequest(prompt=prefix, suffix=suffix)\n\ntokens = tokenizer.encode_fim(request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=256, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.decode(out_tokens[0])\n\nmiddle = result.split(suffix)[0].strip()\nprint(middle)\n```\n\n### Test\n\nTo run logits equivalence:\n```\npython -m pytest tests\n```\n\n## Deployment\n\nThe `deploy` folder contains code to build a [vLLM](https:\u002F\u002FM7B_DIR.com\u002Fvllm-project\u002Fvllm) image with the required dependencies to serve the Mistral AI model. In the image, the [transformers](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002F) library is used instead of the reference implementation. To build it:\n\n```bash\ndocker build deploy --build-arg MAX_JOBS=8\n```\n\nInstructions to run the image can be found in the [official documentation](https:\u002F\u002Fdocs.mistral.ai\u002Fquickstart).\n\n\n## Model platforms\n\n- Use Mistral models on [Mistral AI official API](https:\u002F\u002Fconsole.mistral.ai\u002F) (La Plateforme)\n- Use Mistral models via [cloud providers](https:\u002F\u002Fdocs.mistral.ai\u002Fdeployment\u002Fcloud\u002Foverview\u002F)\n\n## References\n\n[1]: [LoRA](https:\u002F\u002Farxiv.org\u002Fabs\u002F2106.09685): Low-Rank Adaptation of Large Language Models, Hu et al. 2021\n\n## License\n\nThis library is licensed under the Apache 2.0 License. See the [LICENCE](.\u002FLICENCE) file for more information.\n\n*You must not use this library or our models in a manner that infringes, misappropriates, or otherwise violates any third party’s rights, including intellectual property rights.*\n","# Mistral 推理\n\u003Ca target=\"_blank\" href=\"https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fmistralai\u002Fmistral-inference\u002Fblob\u002Fmain\u002Ftutorials\u002Fgetting_started.ipynb\">\n  \u003Cimg src=\"https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg\" alt=\"在 Colab 中打开\"\u002F>\n\u003C\u002Fa>\n\n\n此仓库包含运行 Mistral 模型所需的最简代码。\n\n7B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fannouncing-mistral-7b\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fannouncing-mistral-7b\u002F)\\\n8x7B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-of-experts\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-of-experts\u002F)\\\n8x22B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-8x22b\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmixtral-8x22b\u002F)\\\nCodestral 22B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral\u002F) \\\nCodestral Mamba 7B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F) \\\nMathstral 7B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F) \\\nNemo 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-nemo\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-nemo\u002F) \\\nMistral Large 2 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-large-2407\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-large-2407\u002F) \\\nPixtral 12B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fpixtral-12b\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fpixtral-12b\u002F)\nMistral Small 3.1 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-small-3-1\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-small-3-1\u002F)\n\nDiscord：[https:\u002F\u002Fdiscord.com\u002Finvite\u002Fmistralai](https:\u002F\u002Fdiscord.com\u002Finvite\u002Fmistralai)\\\n文档：[https:\u002F\u002Fdocs.mistral.ai\u002F](https:\u002F\u002Fdocs.mistral.ai\u002F)\\\n护栏机制：[https:\u002F\u002Fdocs.mistral.ai\u002Fusage\u002Fguardrailing](https:\u002F\u002Fdocs.mistral.ai\u002Fusage\u002Fguardrailing)\n\n## 安装\n\n注意：您需要使用 GPU 来安装 `mistral-inference`，因为目前它要求安装 `xformers`，而 `xformers` 本身也需要 GPU 才能完成安装。\n\n### PyPI\n\n```\npip install mistral-inference\n```\n\n### 本地\n\n```\ncd $HOME && git clone https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\ncd $HOME\u002Fmistral-inference && poetry install .\n```\n\n## 模型下载\n\n### 直接链接\n\n| 名称        | 下载 | md5sum |\n|-------------|-------|-------|\n| 7B 指令版 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-7b-v0-3\u002Fmistral-7B-Instruct-v0.3.tar | `80b71fcb6416085bcb4efad86dfb4d52` |\n| 8x7B 指令版 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x7b-v0-1\u002FMixtral-8x7B-v0.1-Instruct.tar (**更新后的模型即将发布！**) | `8e2d3930145dc43d3084396f49d38a3f` |\n| 8x22 指令版 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x22b-v0-3\u002Fmixtral-8x22B-Instruct-v0.3.tar | `471a02a6902706a2f1e44a693813855b` |\n| 7B 基础版 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-7b-v0-3\u002Fmistral-7B-v0.3.tar | `0663b293810d7571dad25dae2f2a5806` |\n| 8x7B |     **更新后的模型即将发布！**       | - |\n| 8x22B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x22b-v0-3\u002Fmixtral-8x22B-v0.3.tar | `a2fa75117174f87d1197e3a4eb50371a` |\n| Codestral 22B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fcodestral-22b-v0-1\u002Fcodestral-22B-v0.1.tar | `1ea95d474a1d374b1d1b20a8e0159de3` |\n| Mathstral 7B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmathstral-7b-v0-1\u002Fmathstral-7B-v0.1.tar | `5f05443e94489c261462794b1016f10b` |\n| Codestral-Mamba 7B | https:\u002F\u002Fmodels.mistralcdn.com\u002Fcodestral-mamba-7b-v0-1\u002Fcodestral-mamba-7B-v0.1.tar | `d3993e4024d1395910c55db0d11db163` |\n| Nemo 基础版 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-base-2407.tar | `c5d079ac4b55fc1ae35f51f0a3c0eb83` |\n| Nemo 指令版 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-instruct-2407.tar | `296fbdf911cb88e6f0be74cd04827fe7` |\n| Mistral Large 2 | https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-large-2407\u002Fmistral-large-instruct-2407.tar | `fc602155f9e39151fba81fcaab2fa7c4` |\n\n注：\n- **重要提示**：\n  - `mixtral-8x22B-Instruct-v0.3.tar` 与 [Mixtral-8x22B-Instruct-v0.1](https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMixtral-8x22B-Instruct-v0.1) 完全相同，只是存储格式为 `.safetensors`。\n  - `mixtral-8x22B-v0.3.tar` 与 [Mixtral-8x22B-v0.1](https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMixtral-8x22B-v0.1) 相同，但词汇表扩展到了 32768 个词。\n  - `codestral-22B-v0.1.tar` 采用一种非商业用途的自定义许可协议，称为 [Mistral AI 非生产许可 (MNPL)](https:\u002F\u002Fmistral.ai\u002Flicenses\u002FMNPL-0.1.md)。\n  - `mistral-large-instruct-2407.tar` 采用一种非商业用途的自定义许可协议，称为 [Mistral AI 研究许可 (MRL)](https:\u002F\u002Fmistral.ai\u002Flicenses\u002FMRL-0.1.md)。\n- 上述所有模型均支持函数调用功能。例如，Mistral 7B 基础版\u002F指令版 v3 是对 7B 基础版\u002F指令版 v2 的小幅更新，新增了函数调用能力。\n- “即将发布”的模型也将包含函数调用功能。\n- 您可以从我们的文档中下载旧版本的模型：[https:\u002F\u002Fdocs.mistral.ai\u002Fgetting-started\u002Fopen_weight_models\u002F#downloading]。\n\n### 从 Hugging Face Hub 下载\n\n| 名称        | ID | URL |\n|-------------|-------|-------|\n| Pixtral Large 指令版 | mistralai\u002FPixtral-Large-Instruct-2411 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FPixtral-Large-Instruct-2411 |\n| Pixtral 12B 基础版 | mistralai\u002FPixtral-12B-Base-2409 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FPixtral-12B-Base-2409 |\n| Pixtral 12B | mistralai\u002FPixtral-12B-2409 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FPixtral-12B-2409 |\n| Mistral Small 3.1 24B 基础版 | mistralai\u002FMistral-Small-3.1-24B-Base-2503 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMistral-Small-3.1-24B-Base-2503\n| Mistral Small 3.1 24B 指令版 | mistralai\u002FMistral-Small-3.1-24B-Instruct-2503 | https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMistral-Small-3.1-24B-Instruct-2503 |\n\n\n### 使用方法\n\n**最新消息!!!**：Mistral Large 2 已发布。更多关于其功能的信息请参见 [此处](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-large-2407\u002F)。\n\n创建一个用于存储模型的本地文件夹\n```sh\nexport MISTRAL_MODEL=$HOME\u002Fmistral_models\nmkdir -p $MISTRAL_MODEL\n```\n\n下载上述任意链接并解压内容，例如：\n\n```sh\nexport 12B_DIR=$MISTRAL_MODEL\u002F12B_Nemo\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-instruct-2407.tar\nmkdir -p $12B_DIR\ntar -xf mistral-nemo-instruct-2407.tar -C $12B_DIR\n```\n\n或者\n\n```sh\nexport M8x7B_DIR=$MISTRAL_MODEL\u002F8x7b_instruct\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fmixtral-8x7b-v0-1\u002FMixtral-8x7B-v0.1-Instruct.tar\nmkdir -p $M8x7B_DIR\ntar -xf Mixtral-8x7B-v0.1-Instruct.tar -C $M8x7B_DIR\n```\n\n对于 Hugging Face 模型的权重，以下是一个下载 [Mistral Small 3.1 24B 指令版](https:\u002F\u002Fhuggingface.co\u002Fmistralai\u002FMistral-Small-3.1-24B-Instruct-2503) 的示例：\n\n```python\nfrom pathlib import Path\nfrom huggingface_hub import snapshot_download\n\n\nmistral_models_path = Path.home().joinpath(\"mistral_models\")\n\nmodel_path = mistral_models_path \u002F \"mistral-small-3.1-instruct\"\nmodel_path.mkdir(parents=True, exist_ok=True)\n\nrepo_id = \"mistralai\u002FMistral-Small-3.1-24B-Instruct-2503\"\n\nsnapshot_download(\n    repo_id=repo_id,\n    allow_patterns=[\"params.json\", \"consolidated.safetensors\", \"tekken.json\"],\n    local_dir=model_path,\n)\n```\n\n## 使用方法\n\n以下章节将概述如何通过命令行界面 (CLI) 或直接在 Python 中运行模型。\n\n### 命令行界面\n\n- **演示**\n\n要测试模型在您的环境中是否正常工作，可以运行 `mistral-demo` 命令。  \n*例如*，120亿参数的 Mistral-Nemo 模型可以在单个 GPU 上进行测试，命令如下：\n\n```sh\nmistral-demo $12B_DIR\n```\n\n对于大型模型，如 **8x7B** 和 **8x22B**，则需要在多 GPU 环境中运行。针对这些模型，可以使用以下命令：\n\n```sh\ntorchrun --nproc-per-node 2 --no-python mistral-demo $M8x7B_DIR\n```\n\n*注意*：如果有多余的 GPU，可将 `--nproc-per-node` 的值调整为更大的数字。\n\n- **聊天**\n\n要与模型进行交互式对话，可以使用 `mistral-chat` 命令。\n\n```sh\nmistral-chat $12B_DIR --instruct --max_tokens 1024 --temperature 0.35\n```\n\n对于大型模型，可以结合 `torchrun` 使用：\n\n```sh\ntorchrun --nproc-per-node 2 --no-python mistral-chat $M8x7B_DIR --instruct\n```\n\n*注意*：如有必要，可调整 `--nproc-per-node` 的值以匹配更多的 GPU 数量（*例如*，针对 8x22B 模型）。\n\n- **与 Codestral 对话**\n\n要将 [Codestral](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral\u002F) 用作编程助手，可以使用 `mistral-chat` 命令。请确保 `$M22B_CODESTRAL` 已设置为下载的 Codestral 模型文件夹的有效路径，例如 `$HOME\u002Fmistral_models\u002FCodestral-22B-v0.1`。\n\n```sh\nmistral-chat $M22B_CODESTRAL --instruct --max_tokens 256\n```\n\n如果您向模型提问：“请用 Rust 编写一个计算斐波那契数列的函数”，模型应会生成类似以下内容的回答：\n\n```sh\n当然，下面是一个用 Rust 编写的简单斐波那契数列计算函数。该函数接受一个整数 `n` 作为参数，并返回第 `n` 个斐波那契数。\n\nfn fibonacci(n: u32) -> u32 {\n    match n {\n        0 => 0,\n        1 => 1,\n        _ => fibonacci(n - 1) + fibonacci(n - 2),\n    }\n}\n\nfn main() {\n    let n = 10;\n    println!(\"第 {} 个斐波那契数是：{}\", n, fibonacci(n));\n}\n\n这个函数使用递归方式计算斐波那契数。不过，这种方法效率不高，因为它会重复计算许多中间结果。更高效的方案是使用循环来迭代计算斐波那契数。\n```\n\n之后您还可以继续对话，例如：“请将其翻译成 Python。”\n\n- **与 Codestral-Mamba 对话**\n\n要将 [Codestral-Mamba](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F) 用作编程助手，可以使用 `mistral-chat` 命令。请确保 `$7B_CODESTRAL_MAMBA` 已设置为下载的 Codestral-Mamba 模型文件夹的有效路径，例如 `$HOME\u002Fmistral_models\u002Fmamba-codestral-7B-v0.1`。\n\n随后，您还需要安装以下 Python 包：\n\n```\npip install packaging mamba-ssm causal-conv1d transformers\n```\n\n安装完成后即可开始对话：\n\n```sh\nmistral-chat $7B_CODESTRAL_MAMBA --instruct --max_tokens 256\n```\n\n- **与 Mathstral 对话**\n\n要将 [Mathstral](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F) 用作助手，可以使用 `mistral-chat` 命令。请确保 `$7B_MATHSTRAL` 已设置为下载的 Mathstral 模型文件夹的有效路径，例如 `$HOME\u002Fmistral_models\u002Fmathstral-7B-v0.1`。\n\n```sh\nmistral-chat $7B_MATHSTRAL --instruct --max_tokens 256\n```\n\n如果您向模型提问：“Albert 每周都喜欢冲浪一次，每次冲浪持续 4 小时，每小时收费 20 美元。那么 Albert 在 5 周内总共会花费多少钱？”模型应给出正确的计算结果。\n\n之后您可以继续对话，例如：“那他一年会花费多少钱？”\n\n- **与 Mistral Small 3.1 24B Instruct 对话**\n\n要将 [Mistral Small 3.1 24B Instruct](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-small-3-1\u002F) 用作助手，可以使用 `mistral-chat` 命令。请确保 `$MISTRAL_SMALL_3_1_INSTRUCT` 已设置为下载的 Mistral Small 模型文件夹的有效路径，例如 `$HOME\u002Fmistral_models\u002Fmistral-small-3.1-instruct`。\n\n```sh\nmistral-chat $MISTRAL_SMALL_3_1_INSTRUCT --instruct --max_tokens 256\n```\n\n如果您向模型展示一张图片，并提问：“上图所示的是哪个公园？请提供识别该公园的线索。”同时附上图片 URL *https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fpatrickvonplaten\u002Frandom_img\u002Fresolve\u002Fmain\u002Fyosemite.png*，模型应答为优胜美地国家公园，并给出相应的识别线索。\n\n之后您还可以继续对话，例如：“图中的湖泊叫什么名字？”模型应回答说那不是湖泊，而是一条河流。\n\n### Python\n\n- *指令遵循*：\n\n```py\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\n\n\ntokenizer = MistralTokenizer.from_file(\".\u002Fmistral-nemo-instruct-v0.1\u002Ftekken.json\")  # 更改为提取的分词器文件\nmodel = Transformer.from_folder(\".\u002Fmistral-nemo-instruct-v0.1\")  # 更改为提取的模型目录\n\nprompt = \"请合理估算，请一位窗户清洁工清洗巴黎所有窗户的费用大概是多少美元。\"\n\ncompletion_request = ChatCompletionRequest(messages=[UserMessage(content=prompt)])\n\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=1024, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])\n\nprint(result)\n```\n\n- *多模态指令遵循*：\n\n\n```python\nfrom pathlib import Path\n\nfrom huggingface_hub import snapshot_download\nfrom mistral_common.protocol.instruct.messages import ImageURLChunk, TextChunk\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_inference.generate import generate\nfrom mistral_inference.transformer import Transformer\n\nmodel_path = Path.home().joinpath(\"mistral_models\") \u002F \"mistral-small-3.1-instruct\" # 更改为提取的模型\ntokenizer = MistralTokenizer.from_file(model_path \u002F \"tekken.json\")\nmodel = Transformer.from_folder(model_path)\n\nurl = \"https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fpatrickvonplaten\u002Frandom_img\u002Fresolve\u002Fmain\u002Fyosemite.png\"\nprompt = \"上图展示的是哪个公园？请给出识别该公园的线索。\"\n\nuser_content = [ImageURLChunk(image_url=url), TextChunk(text=prompt)]\n\ntokens, images = tokenizer.instruct_tokenizer.encode_user_content(user_content, False)\n\nout_tokens, _ = generate(\n    [tokens],\n    model,\n    images=[images],\n    max_tokens=256,\n    temperature=0.15,\n    eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id,\n)\nresult = tokenizer.decode(out_tokens[0])\n\nprint(\"Prompt:\", prompt)\nprint(\"Completion:\", result)\n```\n\n- *函数调用*：\n\n```py\nfrom mistral_common.protocol.instruct.tool_calls import Function, Tool\n\ncompletion_request = ChatCompletionRequest(\n    tools=[\n        Tool(\n            function=Function(\n                name=\"get_current_weather\",\n                description=\"获取当前天气\",\n                parameters={\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"location\": {\n                            \"type\": \"string\",\n                            \"description\": \"城市和州，例如旧金山，加州\",\n                        },\n                        \"format\": {\n                            \"type\": \"string\",\n                            \"enum\": [\"摄氏度\", \"华氏度\"],\n                            \"description\": \"要使用的温度单位。根据用户所在位置推断。\",\n                        },\n                    },\n                    \"required\": [\"location\", \"format\"],\n                },\n            )\n        )\n    ],\n    messages=[\n        UserMessage(content=\"今天巴黎的天气怎么样？\"),\n        ],\n)\n\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])\n\nprint(result)\n```\n\n- *中间填空（FIM）*：\n\n请确保已安装 `mistral-common >= 1.2.0`：\n```\npip install --upgrade mistral-common\n```\n\n你可以按如下方式模拟代码补全的中间填空。\n\n```py\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.tokens.instruct.request import FIMRequest\n\ntokenizer = MistralTokenizer.from_model(\"codestral-22b\")\nmodel = Transformer.from_folder(\".\u002Fmistral_22b_codestral\")\n\nprefix = \"\"\"def add(\"\"\"\nsuffix = \"\"\"    return sum\"\"\"\n\nrequest = FIMRequest(prompt=prefix, suffix=suffix)\n\ntokens = tokenizer.encode_fim(request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=256, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.decode(out_tokens[0])\n\nmiddle = result.split(suffix)[0].strip()\nprint(middle)\n```\n\n### 测试\n\n运行 logits 等价性测试：\n```\npython -m pytest tests\n```\n\n## 部署\n\n`deploy` 文件夹包含用于构建带有所需依赖项的 [vLLM](https:\u002F\u002FM7B_DIR.com\u002Fvllm-project\u002Fvllm) 镜像的代码，以便部署 Mistral AI 模型。在该镜像中，使用了 [transformers](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002F) 库，而非参考实现。构建命令如下：\n\n```bash\ndocker build deploy --build-arg MAX_JOBS=8\n```\n\n运行该镜像的说明可在[官方文档](https:\u002F\u002Fdocs.mistral.ai\u002Fquickstart)中找到。\n\n## 模型平台\n\n- 在 [Mistral AI 官方 API](https:\u002F\u002Fconsole.mistral.ai\u002F)（La Plateforme）上使用 Mistral 模型。\n- 通过 [云服务提供商](https:\u002F\u002Fdocs.mistral.ai\u002Fdeployment\u002Fcloud\u002Foverview\u002F) 使用 Mistral 模型。\n\n## 参考文献\n\n[1]: [LoRA](https:\u002F\u002Farxiv.org\u002Fabs\u002F2106.09685)：大型语言模型的低秩适应，Hu 等人，2021 年。\n\n## 许可证\n\n本库采用 Apache 2.0 许可证授权。更多信息请参阅 [LICENCE](.\u002FLICENCE) 文件。\n\n*您不得以侵犯、盗用或以其他方式违反任何第三方权利（包括知识产权）的方式使用本库或我们的模型。*","# Mistral Inference 快速上手指南\n\n本指南帮助中国开发者快速部署并运行 Mistral AI 开源模型（如 Mistral 7B, Mixtral 8x7B, Codestral 等）。\n\n## 1. 环境准备\n\n在开始之前，请确保满足以下系统和硬件要求：\n\n*   **操作系统**: Linux (推荐) 或 macOS。\n*   **硬件**: \n    *   必须拥有 **NVIDIA GPU**。\n    *   安装过程依赖 `xformers`，该库需要 GPU 环境才能编译安装。\n    *   **显存建议**: \n        *   7B 模型：单卡即可运行。\n        *   8x7B \u002F 8x22B 等大模型：需要多卡并行运行。\n*   **软件依赖**:\n    *   Python 3.9+\n    *   PyTorch (需匹配 CUDA 版本)\n    *   Git\n\n## 2. 安装步骤\n\n你可以选择通过 PyPI 直接安装，或克隆源码进行本地开发。\n\n### 方式一：通过 PyPI 安装（推荐）\n\n```bash\npip install mistral-inference\n```\n\n### 方式二：本地源码安装\n\n如果你需要修改代码或使用最新特性：\n\n```bash\ncd $HOME && git clone https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\ncd $HOME\u002Fmistral-inference && poetry install .\n```\n\n## 3. 模型下载与准备\n\n在使用前，需下载模型权重并解压到本地目录。\n\n### 设置存储目录\n```sh\nexport MISTRAL_MODEL=$HOME\u002Fmistral_models\nmkdir -p $MISTRAL_MODEL\n```\n\n### 下载示例 (以 Mistral Nemo Instruct 为例)\n```sh\nexport 12B_DIR=$MISTRAL_MODEL\u002F12B_Nemo\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-instruct-2407.tar\nmkdir -p $12B_DIR\ntar -xf mistral-nemo-instruct-2407.tar -C $12B_DIR\n```\n\n> **注意**: \n> *   对于 **Mixtral 8x7B** 或 **8x22B** 等大模型，请下载对应的 `.tar` 包并解压。\n> *   部分模型（如 Codestral, Mistral Large）有特定的非商业许可证，使用前请查阅官方许可协议。\n> *   若网络受限，可尝试使用 Hugging Face Hub 下载（需配置国内镜像加速），参考下方 Python 代码段。\n\n## 4. 基本使用\n\n### 方法 A：命令行界面 (CLI)\n\n这是最快速的测试方式，支持对话和演示模式。\n\n#### 1. 运行演示 (Demo)\n测试模型是否能正常加载和推理。\n\n*   **单卡模型 (如 7B, 12B)**:\n    ```sh\n    mistral-demo $12B_DIR\n    ```\n\n*   **多卡模型 (如 8x7B, 8x22B)**:\n    需使用 `torchrun` 指定 GPU 数量（例如 2 卡）：\n    ```sh\n    torchrun --nproc-per-node 2 --no-python mistral-demo $M8x7B_DIR\n    ```\n    *(注：根据实际显卡数量调整 `--nproc-per-node`)*\n\n#### 2. 交互式对话 (Chat)\n与模型进行多轮对话。\n\n*   **标准对话**:\n    ```sh\n    mistral-chat $12B_DIR --instruct --max_tokens 1024 --temperature 0.35\n    ```\n\n*   **大模型多卡对话**:\n    ```sh\n    torchrun --nproc-per-node 2 --no-python mistral-chat $M8x7B_DIR --instruct\n    ```\n\n*   **特定模型对话 (如 Codestral)**:\n    确保变量指向正确的模型路径（例如 `$M22B_CODESTRAL`）：\n    ```sh\n    mistral-chat $M22B_CODESTRAL --instruct --max_tokens 256\n    ```\n\n### 方法 B：Python 代码调用\n\n适用于将模型集成到自己的应用中。以下是一个基础的指令跟随示例：\n\n```python\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\n\n# 1. 加载分词器和模型 (路径替换为你实际解压的目录)\ntokenizer = MistralTokenizer.from_file(\".\u002Fmistral-nemo-instruct-v0.1\u002Ftekken.json\")\nmodel = Transformer.from_folder(\".\u002Fmistral-nemo-instruct-v0.1\")\n\n# 2. 构建请求\nprompt = \"How expensive would it be to ask a window cleaner to clean all windows in Paris. Make a reasonable guess in US Dollar.\"\n\ncompletion_request = ChatCompletionRequest(\n    messages=[UserMessage(content=prompt)]\n)\n\n# 3. 分词并生成\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\nout_tokens, _ = generate(tokens, model, max_tokens=256, temperature=0.7)\nresult = tokenizer.decode(out_tokens)\n\nprint(result)\n```\n\n#### 附：通过 Hugging Face Hub 下载模型 (Python)\n如果直接下载链接受阻，可使用此脚本下载（建议配置 `HF_ENDPOINT` 为国内镜像）：\n\n```python\nfrom pathlib import Path\nfrom huggingface_hub import snapshot_download\n\n# 设置国内镜像加速 (可选)\n# import os\n# os.environ[\"HF_ENDPOINT\"] = \"https:\u002F\u002Fhf-mirror.com\"\n\nmistral_models_path = Path.home().joinpath(\"mistral_models\")\nmodel_path = mistral_models_path \u002F \"mistral-small-3.1-instruct\"\nmodel_path.mkdir(parents=True, exist_ok=True)\n\nrepo_id = \"mistralai\u002FMistral-Small-3.1-24B-Instruct-2503\"\n\nsnapshot_download(\n    repo_id=repo_id,\n    allow_patterns=[\"params.json\", \"consolidated.safetensors\", \"tekken.json\"],\n    local_dir=model_path,\n)\n```","某初创公司的后端工程师需要在本地 GPU 服务器上快速部署 Mistral 7B 模型，以构建一个低延迟的内部代码审查助手。\n\n### 没有 mistral-inference 时\n- **环境配置繁琐**：手动安装 `xformers` 等底层依赖极易因 CUDA 版本不匹配而失败，耗费数小时排查兼容性问题。\n- **推理代码冗余**：需自行编写复杂的 Tokenizer 加载、注意力掩码生成及采样逻辑，导致核心业务代码被大量样板代码淹没。\n- **模型加载缓慢**：缺乏优化的权重读取机制，大模型启动时间长，难以满足开发过程中频繁重启测试的需求。\n- **多模型切换困难**：尝试切换至 Mixtral 或 Codestral 等不同架构模型时，需大幅重构推理管线，维护成本极高。\n\n### 使用 mistral-inference 后\n- **一键就绪环境**：通过 `pip install mistral-inference` 即可自动解决包括 `xformers` 在内的所有 GPU 依赖，几分钟内完成环境搭建。\n- **极简推理接口**：仅需几行代码即可加载官方提供的 7B 或 Codestral 模型权重，内置高效的生成循环，让工程师专注业务逻辑。\n- **极速冷启动**：利用库内优化的权重加载策略，显著缩短模型初始化时间，实现代码审查服务的秒级响应与迭代。\n- **统一架构支持**：同一套调用接口无缝兼容从 Mistral 7B 到 Mixtral 8x22B 等多种模型，轻松对比不同模型在代码场景的表现。\n\nmistral-inference 通过提供官方优化的最小化推理路径，将开发者从繁琐的底层适配中解放出来，实现了高性能大模型在本地环境的即插即用。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmistralai_mistral-inference_6707f55c.png","mistralai","Mistral AI","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fmistralai_7094b1e0.png",null,"contact@mistral.ai","mistral.ai","https:\u002F\u002Fgithub.com\u002Fmistralai",[81,85,89,93],{"name":82,"color":83,"percentage":84},"Jupyter Notebook","#DA5B0B",62.6,{"name":86,"color":87,"percentage":88},"Python","#3572A5",36.7,{"name":90,"color":91,"percentage":92},"Dockerfile","#384d54",0.5,{"name":94,"color":95,"percentage":96},"Shell","#89e051",0.2,10774,1037,"2026-04-19T10:23:34","Apache-2.0","未说明","必需。安装过程需要 GPU（因为依赖 xformers）。运行大型模型（如 8x7B, 8x22B）需要多 GPU 设置；较小模型（如 12B）可在单 GPU 上运行。具体显存大小和 CUDA 版本未在文中明确列出。",{"notes":104,"python":101,"dependencies":105},"1. 安装必须使用 GPU，因为 'xformers' 库的安装需要 GPU 支持。\n2. 大型模型（如 8x7B 和 8x22B）必须使用多 GPU 环境运行（通过 torchrun 启动）。\n3. 若使用 Codestral-Mamba 模型，需额外安装 mamba-ssm 和 causal-conv1d 等特定包。\n4. 模型权重需单独下载（提供直接链接或 Hugging Face 下载方式），部分模型（如 Codestral 22B, Mistral Large 2）受非商业许可证限制。",[106,107,108,109,110,111,112,113],"xformers","torchrun","packaging","mamba-ssm","causal-conv1d","transformers","huggingface_hub","poetry",[36,14],[116,117,73],"llm","llm-inference","2026-03-27T02:49:30.150509","2026-04-20T21:07:31.536830",[121,126,131,136,141,145],{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},45778,"Mistral v2 模型是否还支持分层滑动窗口注意力（Layer-wise Sliding Window Attention）机制？","不支持。根据社区反馈，Mistral v2 版本已经不再包含滑动窗口注意力（SWA）机制。因此，关于该机制在 v2 中的具体实现细节（如不同层如何处理窗口滑动）已不再适用。","https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fissues\u002F40",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},45779,"在使用 Mistral-7b-instruct 的聊天模板时，如何正确处理系统提示（System Prompt）？","官方文档和 Hugging Face 的实现略有不同。Hugging Face 的 `apply_chat_template` 方法使用 `\u003C\u003CSYS>>` 和 `\u003C\u003C\u002FSYS>>` 标记将系统提示嵌入到第一条指令中。例如，消息列表中包含 role 为 'system' 的内容时，tokenizer 会自动将其格式化为 `[INST] \u003C\u003CSYS>> {system_content} \u003C\u003C\u002FSYS>> {user_content} [\u002FINST]`。如果官方文档链接失效，可以通过互联网档案馆（Web Archive）查看历史版本的 Guardrailing 文档获取详细格式说明。","https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fissues\u002F35",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},45780,"Mixtral 模型中的 MLP 块为什么包含三个线性层（w1, w2, w3）而不是标准的两个？","这是正常的 SwiGLU 激活函数实现，并非错误。标准的 SwiGLU 结构确实包含三个线性层：`w1` 和 `w3` 用于将输入映射到高维空间，其中 `w1` 的输出经过激活函数处理后与 `w3` 的输出进行逐元素相乘，最后通过 `w2` 映射回原始维度。代码逻辑为：`act_fn(w1(x)) * w3(x)`，然后传入 `w2`。这种设计增加了模型的表达能力，是现代 Transformer 变体中常见的做法。","https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fissues\u002F139",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},45781,"使用提供的 Dockerfile 构建 vLLM 时遇到编译错误或安装失败怎么办？","如果遇到构建问题，可以尝试修改 Dockerfile 中安装 vLLM 的命令。原命令 `pip3 install -v \"git+https:\u002F\u002Fgithub.com\u002Fvllm-project\u002Fvllm.git\"` 可能会因编译环境或依赖问题失败。建议尝试指定稳定的发布版本而不是直接从 git 主分支安装，或者确保构建参数 `MAX_JOBS` 设置合理以匹配服务器资源。此外，检查 CUDA 版本与 PyTorch 版本的兼容性也是关键步骤。","https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fissues\u002F99",{"id":142,"question_zh":143,"answer_zh":144,"source_url":125},45782,"Mistral 模型中每一层的缓存（Cache）具体存储的是什么数据？","Mistral 模型的每一层都有独立的缓存。这些缓存存储的是该层的输入值，实际上也就是前一层的输出值（针对前一个片段\u002Ffragment）。理解这一机制对于明白分层注意力如何处理长序列至关重要，因为每一层都在其特定的缓存基础上进行计算，而不是所有层共享同一套全局滑动逻辑。",{"id":146,"question_zh":147,"answer_zh":148,"source_url":130},45783,"在哪里可以找到 Mistral 官方关于 Guardrailing（护栏\u002F安全策略）的详细文档附录？","原始的官方文档链接可能已失效或更改。如果直接链接无法访问，可以使用互联网档案馆（Web Archive）查看快照，例如访问 `https:\u002F\u002Fweb.archive.org\u002Fweb\u002F20231030013339\u002Fhttps:\u002F\u002Fdocs.mistral.ai\u002Fusage\u002Fguardrailing\u002F#appendix`。此外，也可以尝试访问新的平台文档地址 `https:\u002F\u002Fdocs.mistral.ai\u002Fplatform\u002Fguardrailing` 获取最新信息。",[150,155,160,165,170,175],{"id":151,"version":152,"summary_zh":153,"released_at":154},360731,"v1.6.0","## 变更内容\n* 由 @theophilegervet 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F234 中修复了缺少换行符的问题\n* 由 @juliendenize 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F239 中新增对 Mistral Small 3.1 的支持\n* 由 @juliendenize 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F240 中移除了文件引用\n* 由 @juliendenize 发布了 1.6.0 版本，详情见 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F241\n\n## 新贡献者\n* @theophilegervet 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F234 中完成了首次贡献\n* @juliendenize 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F239 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fcompare\u002Fv1.5.0...v1.6.0","2025-03-20T15:03:08",{"id":156,"version":157,"summary_zh":158,"released_at":159},360732,"v1.4.0","**Pixtral**\n\nMistral 模型现在可以“看”了！\n\n```sh\npip install --upgrade mistral_inference   # >= 1.4.0\n```\n\n**下载**：\n\n```py\nfrom huggingface_hub import snapshot_download\nfrom pathlib import Path\n\nmistral_models_path = Path.home().joinpath('mistral_models', 'Pixtral')\nmistral_models_path.mkdir(parents=True, exist_ok=True)\n\nsnapshot_download(repo_id=\"mistralai\u002FPixtral-12B-2409\", allow_patterns=[\"params.json\", \"consolidated.safetensors\", \"tekken.json\"], local_dir=mistral_models_path)\n```\n\n**命令行示例**：\n\n```bash\nmistral-chat $HOME\u002Fmistral_models\u002FPixtral --instruct --max_tokens 256 --temperature 0.35\n```\n\n*例如*，尝试如下内容：\n\n```\n文本提示：你能在下面这张图片中看到什么？\n[你现在可以输入零张、一张或更多图片。]\n图片路径或网址 [留空并按回车键结束图片输入]：https:\u002F\u002Fpicsum.photos\u002Fid\u002F237\u002F200\u002F300\n图片路径或网址 [留空并按回车键结束图片输入]：\n我看到一只黑色的狗躺在木制表面上。这只狗似乎在抬头看，它的眼睛清晰可见。\n```\n\n**Python**：\n\n1. 加载模型\n\n```py\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage, TextChunk, ImageURLChunk\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\n\ntokenizer = MistralTokenizer.from_file(f\"{mistral_models_path}\u002Ftekken.json\")\nmodel = Transformer.from_folder(mistral_models_path)\n```\n\n2. 运行：\n\n```py\nurl = \"https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fpatrickvonplaten\u002Frandom_img\u002Fresolve\u002Fmain\u002Fyosemite.png\"\nprompt = \"描述这张图片。\"\n\ncompletion_request = ChatCompletionRequest(messages=[UserMessage(content=[ImageURLChunk(image_url=url), TextChunk(text=prompt)])])\n\nencoded = tokenizer.encode_chat_completion(completion_request)\n\nimages = encoded.images\ntokens = encoded.tokens\n\nout_tokens, _ = generate([tokens], model, images=[images], max_tokens=256, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.decode(out_tokens[0])\n\nprint(result)\n```\n\n","2024-09-13T13:09:47",{"id":161,"version":162,"summary_zh":163,"released_at":164},360733,"v1.3.0","# 欢迎来自 Mistral 的 Mistral-Nemo 🤝 NVIDIA\n\n更多关于 **Mistral-Nemo** 的信息，请参阅 [这里](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmistral-nemo\u002F)。\n\n**安装**\n\n```bash\npip install mistral-inference>=1.3.0\n```\n\n**下载**\n\n```bash\nexport NEMO_MODEL=$HOME\u002F12B_NEMO_MODEL\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fmistral-nemo-2407\u002Fmistral-nemo-instruct-2407.tar\nmkdir -p $NEMO_MODEL\ntar -xf mistral-nemo-instruct-v0.1.tar -C $NEMO_MODEL\n```\n\n**聊天**\n\n```bash\nmistral-chat $HOME\u002FNEMO_MODEL --instruct --max_tokens 1024\n```\n\n或者直接在 Python 中：\n\n```py\nimport os\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\n\ntokenizer = MistralTokenizer.from_model(\"mistral-nemo\")\nmodel = Transformer.from_folder(os.environ.get(\"NEMO_MODEL\"))\n\nprompt = \"请估算一下，请一位擦窗工人清洗巴黎所有窗户的费用大概是多少？请用美元做出合理猜测。\"\n\ncompletion_request = ChatCompletionRequest(messages=[UserMessage(content=prompt)])\n\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=1024, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.decode(out_tokens[0])\n\nprint(result)\n```\n\n**函数调用**：\n\n```py\nfrom mistral_common.protocol.instruct.tool_calls import Function, Tool\nfrom mistral_inference.transformer import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\n\n\ntokenizer = MistralTokenizer.from_model(\"mistral-nemo\")\nmodel = Transformer.from_folder(os.environ.get(\"NEMO_MODEL\"))\n\ncompletion_request = ChatCompletionRequest(\n    tools=[\n        Tool(\n            function=Function(\n                name=\"get_current_weather\",\n                description=\"获取当前天气\",\n                parameters={\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"location\": {\n                            \"type\": \"string\",\n                            \"description\": \"城市和州，例如旧金山，加州\",\n                        },\n                        \"format\": {\n                            \"type\": \"string\",\n                            \"enum\": [\"摄氏度\", \"华氏度\"],\n                            \"description\": \"要使用的温度单位。请根据用户所在位置推断。\",\n                        },\n                    },\n                    \"required\": [\"location\", \"format\"],\n                },\n            )\n        )\n    ],\n    messages=[\n        ","2024-07-18T14:01:35",{"id":166,"version":167,"summary_zh":168,"released_at":169},360734,"v1.2.0","# 欢迎 🐍 Codestral-Mamba 和 🔢 Mathstral\n\n```\npip install mistral-inference>=1.2.0\n```\n\n**Codestral-Mamba**\n\n```\npip install packaging mamba-ssm causal-conv1d transformers\n```\n\n1. 下载\n```\nexport MAMBA_CODE=$HOME\u002F7B_MAMBA_CODE\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fcodestral-mamba-7b-v0-1\u002Fcodestral-mamba-7B-v0.1.tar\nmkdir -p $MAMBA_CODE\ntar -xf codestral-mamba-7B-v0.1.tar -C $MAMBA_CODE\n```\n\n2. 对话\n```\nmistral-chat $HOME\u002F7B_MAMBA_CODE --instruct --max_tokens 256\n```\n\n**Mathstral**\n\n1. 下载\n```\nexport MATHSTRAL=$HOME\u002F7B_MATH\nwget https:\u002F\u002Fmodels.mistralcdn.com\u002Fmathstral-7b-v0-1\u002Fmathstral-7B-v0.1.tar\nmkdir -p $MATHSTRAL\ntar -xf mathstral-7B-v0.1.tar -C $MATHSTRAL\n```\n\n2. 对话\n```\nmistral-chat $HOME\u002F7B_MATH --instruct --max_tokens 256\n```\n\n**博客：**\nCodestral Mamba 7B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fcodestral-mamba\u002F) \\\nMathstral 7B 博客：[https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F](https:\u002F\u002Fmistral.ai\u002Fnews\u002Fmathstral\u002F)\n\n## 变更内容\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F158 中，@sophiamyang 添加了关于 GPU 要求的说明。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F164 中，@patrickvonplaten 添加了 Codestral。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F165 中，@patrickvonplaten 更新了 README.md。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F175 中，@didier-durand 修复了 README.md 中的类型错误。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F174 中，@CharlesCNorton 将 ModelArgs 中的“infered”修正为“inferred”。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F173 中，@CharlesCNorton 将 LoRALoaderMixin 中的“multipe”修正为“multiple”。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F167 中，@CharlesCNorton 将 classifier.ipynb 中的“alborithm”修正为“algorithm”。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F172 中，@CharlesCNorton 修复了 state_dict 验证错误信息中的拼写错误。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F171 中，@CharlesCNorton 修正了 ModelArgs 文档字符串中的拼写错误。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F168 中，@patrickvonplaten 更新了 README.md。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F179 中，@CharlesCNorton 修复了 HF_TOKEN 环境变量检查消息中的拼写错误。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F178 中，@pandora-s-git 添加了问题\u002F错误模板。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F183 中，@CharlesCNorton 发现并修复了 ModelArgs 类文档字符串中的拼写错误。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F184 中，@Simontwice 更新了 README.md。\n* 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F187 中，@patrickvonplaten 添加了 Mamba。\n\n## 新贡献者\n* @didier-durand 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-inference\u002Fpull\u002F175 中做出了首次贡献。\n* @CharlesCNorton 在 https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-in","2024-07-16T12:11:27",{"id":171,"version":172,"summary_zh":173,"released_at":174},360735,"v1.1.0","mistral-inference==1.1.0 支持运行使用以下仓库训练的 LoRA 模型：https:\u002F\u002Fgithub.com\u002Fmistralai\u002Fmistral-finetune\n\n在训练好一个 7B 参数的 LoRA 模型后，你可以按照如下方式使用 `mistral-inference`：\n\n```py\nfrom mistral_inference.model import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\n\n\nMODEL_PATH = \"下载的7B基础模型目录路径\"\n\ntokenizer = MistralTokenizer.from_file(f\"{MODEL_PATH}\u002Ftokenizer.model.v3\")  # 替换为解压后的分词器文件\nmodel = Transformer.from_folder(MODEL_PATH)  # 替换为解压后的模型目录\nmodel.load_lora(\"\u002F运行LoRA模型的目录\u002Fcheckpoints\u002Fcheckpoint_000300\u002Fconsolidated\u002Flora.safetensors\")\n\ncompletion_request = ChatCompletionRequest(messages=[UserMessage(content=\"请用简短的话向我解释一下机器学习。\")])\n\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])\n\nprint(result)\n```","2024-05-24T18:31:03",{"id":176,"version":177,"summary_zh":178,"released_at":179},360736,"v1.0.4","Mistral-inference 是所有 Mistral 模型的官方推理库：7B、8x7B 和 8x22B。\n\n\n通过以下命令安装：\n\n```py\npip install mistral-inference\n```\n\n运行方式如下：\n\n```py\nfrom mistral_inference.model import Transformer\nfrom mistral_inference.generate import generate\n\nfrom mistral_common.tokens.tokenizers.mistral import MistralTokenizer\nfrom mistral_common.protocol.instruct.messages import UserMessage\nfrom mistral_common.protocol.instruct.request import ChatCompletionRequest\nfrom mistral_common.protocol.instruct.tool_calls import Function, Tool\n\ntokenizer = MistralTokenizer.from_file(\"\u002Fpath\u002Fto\u002Ftokenizer\u002Ffile\")  # 替换为解压后的分词器文件路径\nmodel = Transformer.from_folder(\".\u002Fpath\u002Fto\u002Fmodel\u002Ffolder\")  # 替换为解压后的模型目录路径\n\nfrom mistral_common.protocol.instruct.tool_calls import Function, Tool\n\ncompletion_request = ChatCompletionRequest(\n    tools=[\n        Tool(\n            function=Function(\n                name=\"get_current_weather\",\n                description=\"获取当前天气\",\n                parameters={\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"location\": {\n                            \"type\": \"string\",\n                            \"description\": \"城市和州，例如旧金山，加州\",\n                        },\n                        \"format\": {\n                            \"type\": \"string\",\n                            \"enum\": [\"摄氏度\", \"华氏度\"],\n                            \"description\": \"要使用的温度单位。可根据用户所在地区推断。\",\n                        },\n                    },\n                    \"required\": [\"location\", \"format\"],\n                },\n            )\n        )\n    ],\n    messages=[\n        UserMessage(content=\"今天巴黎的天气怎么样？\"),\n    ],\n)\n\ntokens = tokenizer.encode_chat_completion(completion_request).tokens\n\nout_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)\nresult = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])\n\nprint(result)\n```","2024-05-22T16:30:02"]