您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

deploy_local_llm.mdx 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. ---
  2. sidebar_position: 2
  3. slug: /deploy_local_llm
  4. ---
  5. # Deploy local models
  6. import Tabs from '@theme/Tabs';
  7. import TabItem from '@theme/TabItem';
  8. Deploy and run local models using Ollama, Xinference, or other frameworks.
  9. ---
  10. RAGFlow supports deploying models locally using Ollama, Xinference, IPEX-LLM, or jina. If you have locally deployed models to leverage or wish to enable GPU or CUDA for inference acceleration, you can bind Ollama or Xinference into RAGFlow and use either of them as a local "server" for interacting with your local models.
  11. RAGFlow seamlessly integrates with Ollama and Xinference, without the need for further environment configurations. You can use them to deploy two types of local models in RAGFlow: chat models and embedding models.
  12. :::tip NOTE
  13. This user guide does not intend to cover much of the installation or configuration details of Ollama or Xinference; its focus is on configurations inside RAGFlow. For the most current information, you may need to check out the official site of Ollama or Xinference.
  14. :::
  15. ## Deploy local models using Ollama
  16. [Ollama](https://github.com/ollama/ollama) enables you to run open-source large language models that you deployed locally. It bundles model weights, configurations, and data into a single package, defined by a Modelfile, and optimizes setup and configurations, including GPU usage.
  17. :::note
  18. - For information about downloading Ollama, see [here](https://github.com/ollama/ollama?tab=readme-ov-file#ollama).
  19. - For a complete list of supported models and variants, see the [Ollama model library](https://ollama.com/library).
  20. :::
  21. ### 1. Deploy Ollama using Docker
  22. ```bash
  23. $ sudo docker run --name ollama -p 11434:11434 ollama/ollama
  24. > time=2024-12-02T02:20:21.360Z level=INFO source=routes.go:1248 msg="Listening on [::]:11434 (version 0.4.6)"
  25. > time=2024-12-02T02:20:21.360Z level=INFO source=common.go:49 msg="Dynamic LLM libraries" runners="[cpu cpu_avx cpu_avx2 cuda_v11 cuda_v12]"
  26. ```
  27. Ensure Ollama is listening on all IP address:
  28. ```bash
  29. $ sudo ss -tunlp | grep 11434
  30. > tcp LISTEN 0 4096 0.0.0.0:11434 0.0.0.0:* users:(("docker-proxy",pid=794507,fd=4))
  31. > tcp LISTEN 0 4096 [::]:11434 [::]:* users:(("docker-proxy",pid=794513,fd=4))
  32. ```
  33. Pull models as you need. We recommend that you start with `llama3.2` (a 3B chat model) and `bge-m3` (a 567M embedding model):
  34. ```bash
  35. $ sudo docker exec ollama ollama pull llama3.2
  36. > pulling dde5aa3fc5ff... 100% ▕████████████████▏ 2.0 GB
  37. > success
  38. ```
  39. ```bash
  40. $ sudo docker exec ollama ollama pull bge-m3
  41. > pulling daec91ffb5dd... 100% ▕████████████████▏ 1.2 GB
  42. > success
  43. ```
  44. ### 2. Ensure Ollama is accessible
  45. - If RAGFlow runs in Docker and Ollama runs on the same host machine, check if Ollama is accessible from inside the RAGFlow container:
  46. ```bash
  47. $ sudo docker exec -it ragflow-server bash
  48. $ curl http://host.docker.internal:11434/
  49. > Ollama is running
  50. ```
  51. - If RAGFlow is launched from source code and Ollama runs on the same host machine as RAGFlow, check if Ollama is accessible from RAGFlow's host machine:
  52. ```bash
  53. $ curl http://localhost:11434/
  54. > Ollama is running
  55. ```
  56. - If RAGFlow and Ollama run on different machines, check if Ollama is accessible from RAGFlow's host machine:
  57. ```bash
  58. $ curl http://${IP_OF_OLLAMA_MACHINE}:11434/
  59. > Ollama is running
  60. ```
  61. ### 3. Add Ollama
  62. In RAGFlow, click on your logo on the top right of the page **>** **Model providers** and add Ollama to RAGFlow:
  63. ![add ollama](https://github.com/infiniflow/ragflow/assets/93570324/10635088-028b-4b3d-add9-5c5a6e626814)
  64. ### 4. Complete basic Ollama settings
  65. In the popup window, complete basic settings for Ollama:
  66. 1. Ensure that your model name and type match those been pulled at step 1 (Deploy Ollama using Docker). For example, (`llama3.2` and `chat`) or (`bge-m3` and `embedding`).
  67. 2. In Ollama base URL, as determined by step 2, replace `localhost` with `host.docker.internal`.
  68. 3. OPTIONAL: Switch on the toggle under **Does it support Vision?** if your model includes an image-to-text model.
  69. :::caution WARNING
  70. Improper base URL settings will trigger the following error:
  71. ```bash
  72. Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xffff98b81ff0>: Failed to establish a new connection: [Errno 111] Connection refused'))
  73. ```
  74. :::
  75. ### 5. Update System Model Settings
  76. Click on your logo **>** **Model providers** **>** **System Model Settings** to update your model:
  77. - *You should now be able to find **llama3.2** from the dropdown list under **Chat model**, and **bge-m3** from the dropdown list under **Embedding model**.*
  78. - _If your local model is an embedding model, you should find it under **Embedding model**._
  79. ### 6. Update Chat Configuration
  80. Update your model(s) accordingly in **Chat Configuration**.
  81. ## Deploy a local model using Xinference
  82. Xorbits Inference ([Xinference](https://github.com/xorbitsai/inference)) enables you to unleash the full potential of cutting-edge AI models.
  83. :::note
  84. - For information about installing Xinference Ollama, see [here](https://inference.readthedocs.io/en/latest/getting_started/).
  85. - For a complete list of supported models, see the [Builtin Models](https://inference.readthedocs.io/en/latest/models/builtin/).
  86. :::
  87. To deploy a local model, e.g., **Mistral**, using Xinference:
  88. ### 1. Check firewall settings
  89. Ensure that your host machine's firewall allows inbound connections on port 9997.
  90. ### 2. Start an Xinference instance
  91. ```bash
  92. $ xinference-local --host 0.0.0.0 --port 9997
  93. ```
  94. ### 3. Launch your local model
  95. Launch your local model (**Mistral**), ensuring that you replace `${quantization}` with your chosen quantization method:
  96. ```bash
  97. $ xinference launch -u mistral --model-name mistral-v0.1 --size-in-billions 7 --model-format pytorch --quantization ${quantization}
  98. ```
  99. ### 4. Add Xinference
  100. In RAGFlow, click on your logo on the top right of the page **>** **Model providers** and add Xinference to RAGFlow:
  101. ![add xinference](https://github.com/infiniflow/ragflow/assets/93570324/10635088-028b-4b3d-add9-5c5a6e626814)
  102. ### 5. Complete basic Xinference settings
  103. Enter an accessible base URL, such as `http://<your-xinference-endpoint-domain>:9997/v1`.
  104. > For rerank model, please use the `http://<your-xinference-endpoint-domain>:9997/v1/rerank` as the base URL.
  105. ### 6. Update System Model Settings
  106. Click on your logo **>** **Model providers** **>** **System Model Settings** to update your model.
  107. *You should now be able to find **mistral** from the dropdown list under **Chat model**.*
  108. > If your local model is an embedding model, you should find your local model under **Embedding model**.
  109. ### 7. Update Chat Configuration
  110. Update your chat model accordingly in **Chat Configuration**:
  111. > If your local model is an embedding model, update it on the configuration page of your knowledge base.
  112. ## Deploy a local model using IPEX-LLM
  113. [IPEX-LLM](https://github.com/intel-analytics/ipex-llm) is a PyTorch library for running LLMs on local Intel CPUs or GPUs (including iGPU or discrete GPUs like Arc, Flex, and Max) with low latency. It supports Ollama on Linux and Windows systems.
  114. To deploy a local model, e.g., **Qwen2**, using IPEX-LLM-accelerated Ollama:
  115. ### 1. Check firewall settings
  116. Ensure that your host machine's firewall allows inbound connections on port 11434. For example:
  117. ```bash
  118. sudo ufw allow 11434/tcp
  119. ```
  120. ### 2. Launch Ollama service using IPEX-LLM
  121. #### 2.1 Install IPEX-LLM for Ollama
  122. :::tip NOTE
  123. IPEX-LLM's supports Ollama on Linux and Windows systems.
  124. :::
  125. For detailed information about installing IPEX-LLM for Ollama, see [Run llama.cpp with IPEX-LLM on Intel GPU Guide](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/llama_cpp_quickstart.md):
  126. - [Prerequisites](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/llama_cpp_quickstart.md#0-prerequisites)
  127. - [Install IPEX-LLM cpp with Ollama binaries](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/llama_cpp_quickstart.md#1-install-ipex-llm-for-llamacpp)
  128. *After the installation, you should have created a Conda environment, e.g., `llm-cpp`, for running Ollama commands with IPEX-LLM.*
  129. #### 2.2 Initialize Ollama
  130. 1. Activate the `llm-cpp` Conda environment and initialize Ollama:
  131. <Tabs
  132. defaultValue="linux"
  133. values={[
  134. {label: 'Linux', value: 'linux'},
  135. {label: 'Windows', value: 'windows'},
  136. ]}>
  137. <TabItem value="linux">
  138. ```bash
  139. conda activate llm-cpp
  140. init-ollama
  141. ```
  142. </TabItem>
  143. <TabItem value="windows">
  144. Run these commands with *administrator privileges in Miniforge Prompt*:
  145. ```cmd
  146. conda activate llm-cpp
  147. init-ollama.bat
  148. ```
  149. </TabItem>
  150. </Tabs>
  151. 2. If the installed `ipex-llm[cpp]` requires an upgrade to the Ollama binary files, remove the old binary files and reinitialize Ollama using `init-ollama` (Linux) or `init-ollama.bat` (Windows).
  152. *A symbolic link to Ollama appears in your current directory, and you can use this executable file following standard Ollama commands.*
  153. #### 2.3 Launch Ollama service
  154. 1. Set the environment variable `OLLAMA_NUM_GPU` to `999` to ensure that all layers of your model run on the Intel GPU; otherwise, some layers may default to CPU.
  155. 2. For optimal performance on Intel Arc™ A-Series Graphics with Linux OS (Kernel 6.2), set the following environment variable before launching the Ollama service:
  156. ```bash
  157. export SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS=1
  158. ```
  159. 3. Launch the Ollama service:
  160. <Tabs
  161. defaultValue="linux"
  162. values={[
  163. {label: 'Linux', value: 'linux'},
  164. {label: 'Windows', value: 'windows'},
  165. ]}>
  166. <TabItem value="linux">
  167. ```bash
  168. export OLLAMA_NUM_GPU=999
  169. export no_proxy=localhost,127.0.0.1
  170. export ZES_ENABLE_SYSMAN=1
  171. source /opt/intel/oneapi/setvars.sh
  172. export SYCL_CACHE_PERSISTENT=1
  173. ./ollama serve
  174. ```
  175. </TabItem>
  176. <TabItem value="windows">
  177. Run the following command *in Miniforge Prompt*:
  178. ```cmd
  179. set OLLAMA_NUM_GPU=999
  180. set no_proxy=localhost,127.0.0.1
  181. set ZES_ENABLE_SYSMAN=1
  182. set SYCL_CACHE_PERSISTENT=1
  183. ollama serve
  184. ```
  185. </TabItem>
  186. </Tabs>
  187. :::tip NOTE
  188. To enable the Ollama service to accept connections from all IP addresses, use `OLLAMA_HOST=0.0.0.0 ./ollama serve` rather than simply `./ollama serve`.
  189. :::
  190. *The console displays messages similar to the following:*
  191. ![](https://llm-assets.readthedocs.io/en/latest/_images/ollama_serve.png)
  192. ### 3. Pull and Run Ollama model
  193. #### 3.1 Pull Ollama model
  194. With the Ollama service running, open a new terminal and run `./ollama pull <model_name>` (Linux) or `ollama.exe pull <model_name>` (Windows) to pull the desired model. e.g., `qwen2:latest`:
  195. ![](https://llm-assets.readthedocs.io/en/latest/_images/ollama_pull.png)
  196. #### 3.2 Run Ollama model
  197. <Tabs
  198. defaultValue="linux"
  199. values={[
  200. {label: 'Linux', value: 'linux'},
  201. {label: 'Windows', value: 'windows'},
  202. ]}>
  203. <TabItem value="linux">
  204. ```bash
  205. ./ollama run qwen2:latest
  206. ```
  207. </TabItem>
  208. <TabItem value="windows">
  209. ```cmd
  210. ollama run qwen2:latest
  211. ```
  212. </TabItem>
  213. </Tabs>
  214. ### 4. Configure RAGflow
  215. To enable IPEX-LLM accelerated Ollama in RAGFlow, you must also complete the configurations in RAGFlow. The steps are identical to those outlined in the *Deploy a local model using Ollama* section:
  216. 1. [Add Ollama](#4-add-ollama)
  217. 2. [Complete basic Ollama settings](#5-complete-basic-ollama-settings)
  218. 3. [Update System Model Settings](#6-update-system-model-settings)
  219. 4. [Update Chat Configuration](#7-update-chat-configuration)
  220. ## Deploy a local model using jina
  221. To deploy a local model, e.g., **gpt2**, using jina:
  222. ### 1. Check firewall settings
  223. Ensure that your host machine's firewall allows inbound connections on port 12345.
  224. ```bash
  225. sudo ufw allow 12345/tcp
  226. ```
  227. ### 2. Install jina package
  228. ```bash
  229. pip install jina
  230. ```
  231. ### 3. Deploy a local model
  232. Step 1: Navigate to the **rag/svr** directory.
  233. ```bash
  234. cd rag/svr
  235. ```
  236. Step 2: Run **jina_server.py**, specifying either the model's name or its local directory:
  237. ```bash
  238. python jina_server.py --model_name gpt2
  239. ```
  240. > The script only supports models downloaded from Hugging Face.