diff --git a/plugins/deepseek-r1/config.yaml b/plugins/deepseek-r1/config.yaml index 16c2f59d84cb8369abba7b3554dd3f3a1a276f11..77a092538652dedf69dda068f44020a7116154fe 100644 --- a/plugins/deepseek-r1/config.yaml +++ b/plugins/deepseek-r1/config.yaml @@ -12,21 +12,22 @@ 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_download_path: /tmp # 下载的目标路径 + # 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: /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 - # 为提高下载速度,已暂存在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_path: /tmp # 下载的目标路径 + 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: /root/tmp # 下载的目标路径 # 模型参数 parameter: temperature: 0.7 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 0000000000000000000000000000000000000000..712f46f64d180c0ce599877a11a691b0dd0e5985 --- /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 -fL -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 -sfL --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 6d44cbffc7e888a46bb35f006a5ae2c7c30acbc9..52e322ad77d1d30b07d3c31d78d278729d03881b 100644 --- a/plugins/deepseek-r1/workspace/install.yaml +++ b/plugins/deepseek-r1/workspace/install.yaml @@ -32,23 +32,39 @@ state: directory mode: '0755' - - name: Download Ollama package - get_url: - url: "{{ ollama_download }}" - dest: "{{ ollama_download_path }}/{{ ollama_file }}" - timeout: 1800 + - 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 + 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 +132,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