From 84bfefc95043fac708031b2a5fd8b23ab306dcab Mon Sep 17 00:00:00 2001 From: Dingjiahui Date: Tue, 11 Mar 2025 00:10:29 +0800 Subject: [PATCH 1/3] =?UTF-8?q?opt:=20=E5=A2=9E=E5=8A=A0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E4=BB=B6=E6=97=B6=E7=9A=84=E9=B2=81=E6=A3=92=E6=80=A7=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=96=AD=E7=82=B9=E9=87=8D=E4=BC=A0=E4=B8=8E?= =?UTF-8?q?sha256=E6=A0=A1=E9=AA=8C=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/deepseek-r1/config.yaml | 13 ++-- plugins/deepseek-r1/workspace/download.sh | 87 ++++++++++++++++++++++ plugins/deepseek-r1/workspace/install.yaml | 76 ++++++++++--------- 3 files changed, 135 insertions(+), 41 deletions(-) create mode 100644 plugins/deepseek-r1/workspace/download.sh diff --git a/plugins/deepseek-r1/config.yaml b/plugins/deepseek-r1/config.yaml index 16c2f59..6f45aa0 100644 --- a/plugins/deepseek-r1/config.yaml +++ b/plugins/deepseek-r1/config.yaml @@ -12,13 +12,11 @@ all: # ansible_password: PASSWORD # 密码 vars: deepseek_version: 8b - # ollama官方下载地址: https://ollama.com/download/ollama-linux-amd64.tgz,注意区分amd64和arm64 - # 为提高下载速度,已暂存在OEPKGS服务器上 - ollama_download: https://repo.oepkgs.net/openEuler/rpm/openEuler-24.03-LTS/contrib/oedp/2025.0330/ollama-linux-amd64.tgz + # ollama官方下载地址: https://ollama.com/download/ollama-linux-amd64.tgz # amd64 or arm64 + ollama_download: https://repo.oepkgs.net/openEuler/rpm/openEuler-24.03-LTS/contrib/oedp/files/ollama-linux-amd64.tgz # amd64 or arm64 ollama_download_path: /tmp # 下载的目标路径 # 模型文件下载地址: https://www.modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Llama-8B-GGUF/resolve/master/DeepSeek-R1-Distill-Llama-8B-Q4_K_M.gguf - # 为提高下载速度,已暂存在OEPKGS服务器上 - modelfile_download: https://repo.oepkgs.net/openEuler/rpm/openEuler-24.03-LTS/contrib/oedp/2025.0330/DeepSeek-R1-Distill-Llama-8B-Q4_K_M.gguf + modelfile_download: https://repo.oepkgs.net/openEuler/rpm/openEuler-24.03-LTS/contrib/oedp/files/DeepSeek-R1-Distill-Llama-8B-Q4_K_M.gguf modelfile_download_path: /tmp # 下载的目标路径 # 模型参数 parameter: @@ -26,7 +24,10 @@ all: top_p: 0.7 top_k: 30 num_ctx: 4096 - num_thread: 8 # 线程数,建议不超过CPU核数 + num_thread: 4 # 线程数,建议不超过CPU核数 num_gpu: 0 # GPU数 0 for none, -1 for all. + download_checksum: true # 是否打开sha256sum校验 + download_timeout: 600 # 下载大文件时的超时时间(秒) + download_retry: 6 # 下载大文件重试次数 ansible_ssh_common_args: '-o StrictHostKeyChecking=no' diff --git a/plugins/deepseek-r1/workspace/download.sh b/plugins/deepseek-r1/workspace/download.sh new file mode 100644 index 0000000..e639f9b --- /dev/null +++ b/plugins/deepseek-r1/workspace/download.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +download_url=$1 +store_path=$2 +check=$3 +timeout=$4 +retry=$5 + +download_file=$(basename "$download_url") + +download_file_with_retry() { + local url=$1 + local dest=$2 + local retries=$3 + local timeout=$4 + local attempt=0 + + while [ $attempt -lt $retries ]; do + echo "Attempt $(($attempt + 1)) to download $url..." + curl -C - --max-time "$timeout" -o "$dest" "$url" + if [ $? -eq 0 ]; then + return 0 + fi + attempt=$(($attempt + 1)) + done + + return 1 +} + +# 关闭sha256校验 +if [ "$check" -eq 0 ]; then + download_file_with_retry "$download_url" "$store_path/$download_file" "$retry" "$timeout" + if [ $? -eq 0 ]; then + echo "Download succeeded." + exit 0 + else + echo "Download failed." + exit 1 + fi +fi + +# 打开sha256校验 +if [ "$check" -eq 1 ]; then + sha256sum_url="${download_url}.sha256sum" + sha256sum_file="$store_path/${download_file}.sha256sum" + curl -s --max-time 60 -o "$sha256sum_file" "$sha256sum_url" + if [ $? -ne 0 ]; then + echo "Failed to download SHA256 checksum file." + exit 1 + fi + + remote_sum=$(cat "$sha256sum_file" | awk '{print $1}') + + local_file="$store_path/$download_file" + if [ -f "$local_file" ]; then + local_sum=$(sha256sum "$local_file" | awk '{print $1}') + if [ "$local_sum" == "$remote_sum" ]; then + echo "Local file checksum matches remote checksum." + exit 0 + fi + fi + + attempt=0 + while [ $attempt -lt $retry ]; do + echo "Attempt $(($attempt + 1)) to download $download_url and verify checksum..." + download_file_with_retry "$download_url" "$local_file" 1 "$timeout" + if [ $? -ne 0 ]; then + echo "Download failed." + attempt=$(($attempt + 1)) + continue + fi + + local_sum=$(sha256sum "$local_file" | awk '{print $1}') + if [ "$local_sum" == "$remote_sum" ]; then + echo "Checksum matches. Download succeeded." + exit 0 + fi + + attempt=$(($attempt + 1)) + done + + echo "Checksum verification failed after $retry attempts." + exit 1 +fi + +echo "Invalid check parameter. Must be 0 or 1." +exit 1 \ No newline at end of file diff --git a/plugins/deepseek-r1/workspace/install.yaml b/plugins/deepseek-r1/workspace/install.yaml index 6d44cbf..15f6890 100644 --- a/plugins/deepseek-r1/workspace/install.yaml +++ b/plugins/deepseek-r1/workspace/install.yaml @@ -32,23 +32,27 @@ state: directory mode: '0755' - - name: Download Ollama package - get_url: - url: "{{ ollama_download }}" - dest: "{{ ollama_download_path }}/{{ ollama_file }}" - timeout: 1800 + - name: Copy download.sh to remote + copy: + src: download.sh + dest: "{{ ollama_download_path }}/download.sh" + owner: root + group: root + mode: '0644' + + - name: Execute download.sh + shell: > + bash {{ ollama_download_path }}/download.sh + {{ ollama_download }} + {{ ollama_download_path }} + {{ 1 if download_checksum else 0 }} + {{ download_timeout }} + {{ download_retry }} + >> {{ ollama_download_path }}/download.log + ignore_errors: no + async: 0 register: download_result - when: ollama_download is not none - - - name: Check if download succeeded - stat: - path: "{{ ollama_download_path }}/{{ ollama_file }}" - register: download_check - - - name: Fail if download failed - fail: - msg: "Download failed." - when: not download_check.stat.exists + failed_when: download_result.rc != 0 - name: Extract Ollama package unarchive: @@ -116,25 +120,27 @@ state: directory mode: '0755' - - name: Download modelfile from URL - get_url: - url: "{{ modelfile_download }}" - dest: "{{ modelfile_download_path }}/{{ modelfile_file }}" - timeout: 1800 - when: modelfile_download is defined and modelfile_download != "" - ignore_errors: yes - - - name: Check if download succeeded - stat: - path: "{{ modelfile_download_path }}/{{ modelfile_file }}" - register: download_check - - - name: Fail if download failed - fail: - msg: > - Failed to download modelfile from URL. - URL: {{ modelfile_download }} - when: not download_check.stat.exists + - name: Copy download.sh to remote + copy: + src: download.sh + dest: "{{ modelfile_download_path }}/download.sh" + owner: root + group: root + mode: '0644' + + - name: Execute download.sh + shell: > + bash {{ modelfile_download_path }}/download.sh + {{ modelfile_download }} + {{ modelfile_download_path }} + {{ 1 if download_checksum else 0 }} + {{ download_timeout }} + {{ download_retry }} + >> {{ modelfile_download_path }}/download.log + ignore_errors: no + async: 0 + register: download_result + failed_when: download_result.rc != 0 rescue: - name: Print error message of downloading modelfile -- Gitee From 86bb40e5c78e4c66ec8fa3899614fc1baf69f2a8 Mon Sep 17 00:00:00 2001 From: Dingjiahui Date: Tue, 11 Mar 2025 21:37:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?opt:=20=E5=A2=9E=E5=8A=A0=E5=AF=B9=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E7=9A=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/deepseek-r1/config.yaml | 4 ++-- plugins/deepseek-r1/workspace/install.yaml | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/deepseek-r1/config.yaml b/plugins/deepseek-r1/config.yaml index 6f45aa0..77a0925 100644 --- a/plugins/deepseek-r1/config.yaml +++ b/plugins/deepseek-r1/config.yaml @@ -14,10 +14,10 @@ all: deepseek_version: 8b # ollama官方下载地址: https://ollama.com/download/ollama-linux-amd64.tgz # amd64 or arm64 ollama_download: https://repo.oepkgs.net/openEuler/rpm/openEuler-24.03-LTS/contrib/oedp/files/ollama-linux-amd64.tgz # amd64 or arm64 - ollama_download_path: /tmp # 下载的目标路径 + ollama_download_path: /root/tmp # 下载的目标路径 # 模型文件下载地址: https://www.modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Llama-8B-GGUF/resolve/master/DeepSeek-R1-Distill-Llama-8B-Q4_K_M.gguf modelfile_download: https://repo.oepkgs.net/openEuler/rpm/openEuler-24.03-LTS/contrib/oedp/files/DeepSeek-R1-Distill-Llama-8B-Q4_K_M.gguf - modelfile_download_path: /tmp # 下载的目标路径 + modelfile_download_path: /root/tmp # 下载的目标路径 # 模型参数 parameter: temperature: 0.7 diff --git a/plugins/deepseek-r1/workspace/install.yaml b/plugins/deepseek-r1/workspace/install.yaml index 15f6890..52e322a 100644 --- a/plugins/deepseek-r1/workspace/install.yaml +++ b/plugins/deepseek-r1/workspace/install.yaml @@ -32,6 +32,18 @@ state: directory mode: '0755' + - name: Check architecture + set_fact: + arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'arm64' }}" + + - name: Validate ollama_file contains correct architecture + assert: + that: + - ollama_file is defined + - arch in ollama_file + success_msg: "Architecture validation passed (contains {{ arch }})" + fail_msg: "Critical error: ollama_file must contain {{ arch }} architecture identifier, current filename is {{ ollama_file }}" + - name: Copy download.sh to remote copy: src: download.sh -- Gitee From 6ec309209e4a00b9072d4b3cffc088477219296d Mon Sep 17 00:00:00 2001 From: Dingjiahui Date: Fri, 14 Mar 2025 15:31:09 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20curl=E5=91=BD=E4=BB=A4=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A2=9E=E5=8A=A0-fL?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/deepseek-r1/workspace/download.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/deepseek-r1/workspace/download.sh b/plugins/deepseek-r1/workspace/download.sh index e639f9b..712f46f 100644 --- a/plugins/deepseek-r1/workspace/download.sh +++ b/plugins/deepseek-r1/workspace/download.sh @@ -17,7 +17,7 @@ download_file_with_retry() { while [ $attempt -lt $retries ]; do echo "Attempt $(($attempt + 1)) to download $url..." - curl -C - --max-time "$timeout" -o "$dest" "$url" + curl -fL -C - --max-time "$timeout" -o "$dest" "$url" if [ $? -eq 0 ]; then return 0 fi @@ -43,7 +43,7 @@ fi if [ "$check" -eq 1 ]; then sha256sum_url="${download_url}.sha256sum" sha256sum_file="$store_path/${download_file}.sha256sum" - curl -s --max-time 60 -o "$sha256sum_file" "$sha256sum_url" + curl -sfL --max-time 60 -o "$sha256sum_file" "$sha256sum_url" if [ $? -ne 0 ]; then echo "Failed to download SHA256 checksum file." exit 1 -- Gitee