From d21997b0d94fef6edcd37f85866ce0e228a312d2 Mon Sep 17 00:00:00 2001 From: drholy Date: Wed, 4 Feb 2026 03:04:27 +0700 Subject: [PATCH] init commit --- Dockerfile | 22 ++++++++++++++++++++++ build.sh | 26 ++++++++++++++++++++++++++ entrypoint.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 Dockerfile create mode 100644 build.sh create mode 100644 entrypoint.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44e5277 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM ubuntu:22.04 AS builder + +# Установка зависимостей + +RUN apt update && apt-get install -y \ + python3 pip git curl wget nano sudo apt-utils && \ + rm -rf /var/lib/apt/lists/* + +# Установка RKLLM Toolkit +RUN git clone https://github.com/airockchip/rknn-llm + +# Установка Python-пакета +RUN pip3 install /ezrknn-llm/rkllm-toolkit/packages/rkllm_toolkit-1.2.3-cp312-cp312-linux_x86_64.whl + +# Клонирование модели +WORKDIR /models + +# Копируем скрипт компиляции +COPY entrypoint.py /entrypoint.py + +# Точка входа для компиляции +ENTRYPOINT ["python3", "/entrypoint.py"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..0769816 --- /dev/null +++ b/build.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +MODELS_PATH="./models" +OUTPUT_DIR="./compiled-models" +IMAGE_NAME="rkllm-builder" +CONTAINER_NAME="rkllm-compile-$$" + +mkdir -p "$OUTPUT_DIR" + +echo "🏗️ Сборка образа для компиляции..." +docker build -f Dockerfile -t "$IMAGE_NAME" . + +mkdir -p "$MODELS_PATH" +cd "$MODELS_PATH" +git clone https://huggingface.co/simaai/Qwen3-4B-Instruct-2507-a16w4 && \ + cd Qwen3-4B-Instruct-2507-a16w4 && git lfs pull + +echo "⚙️ Запуск компиляции (может занять 30-60 минут)..." +docker run --rm \ + --name "$CONTAINER_NAME" \ + -v "$(pwd)/"$MODELS_PATH":/models" \ + -v "$(pwd)/$OUTPUT_DIR:/output" \ + "$IMAGE_NAME" + +echo "✅ Модель сохранена в: $OUTPUT_DIR" \ No newline at end of file diff --git a/entrypoint.py b/entrypoint.py new file mode 100644 index 0000000..120487b --- /dev/null +++ b/entrypoint.py @@ -0,0 +1,35 @@ +from rkllm.api import RKLLM +from tqdm import tqdm +import torch +from torch import nn +import os + +modelpath = '/models/Qwen3-4B-Instruct-2507-a16w4/devkit' +output = '/output/Qwen3-4B-Instruct-2507-a16w4.rkllm' +os.makedirs("/output", exist_ok=True) + +print(f"Загрузка модели из: {modelpath}") + +llm = RKLLM() +ret = llm.load_huggingface(model=modelpath, model_lora = None, device='cpu') + +if ret != 0: + print(f"❌ Ошибка загрузки модели: {ret}") + exit(ret) + +print("Компиляция для RK3588 (NPU)...") +ret = llm.build(do_quantization=True, optimization_level=1, quantized_dtype='w4a16', + quantized_algorithm='normal', target_platform='rk3588', num_npu_core=3, extra_qparams=None) + +if ret != 0: + print(f"❌ Ошибка компиляции: {ret}") + exit(ret) + +# Export rkllm model +ret = llm.export_rkllm(output) +if ret != 0: + print(f"❌ Ошибка экспорта: {ret}") + exit(ret) + +print(f"✅ Модель скомпилирована: {output}") +print(f"Размер: {os.path.getsize(output) / 1024**3:.2f} GB") \ No newline at end of file