Artificial intelligence model encryption and deployment method and device based on assembly line

By building a basic image pipeline and an encrypted image pipeline, we automate the deployment and encryption process of artificial intelligence models, solving the problems of high computing resource requirements and complex environment configuration of artificial intelligence models, and improving development efficiency and code security.

CN118550556APending Publication Date: 2024-08-27SHANDONG INSPUR SCI RES INST CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410683008.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2024-08-27

AI Technical Summary

Technical Problem

Artificial intelligence models have high demands on computing resources and complex hardware and software environment configurations, resulting in inefficient resource allocation and difficulty in model deployment and migration. Traditional code protection methods are insufficient to meet the needs of modern software development.

Method used

Generate the environment required for the artificial intelligence model by building a basic image pipeline, build an encrypted image pipeline to encrypt the source code, and generate a deployment image containing all environments and encryption codes through the project pipeline, using pipeline automation to accelerate the model deployment and encryption process.

Benefits of technology

It improves the efficiency of development and deployment, reduces the learning cost of algorithm engineers, ensures environmental consistency and code security, simplifies the deployment and configuration process, and enhances code security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550556A
    Figure CN118550556A
Patent Text Reader

Abstract

The invention provides an artificial intelligence model encryption and deployment method and device based on an assembly line, and belongs to the technical field of software development management. According to the technical scheme, a basic mirror image assembly line is constructed, basic mirror images on which all artificial intelligence models depend are generated, and each mirror image comprises an artificial intelligence frame, a driver, a Python environment and a Python public dependency package; constructing an encrypted mirror image assembly line, generating an encrypted mirror image containing an encrypted script, and encrypting the source code by using the mirror image in the project construction process; and constructing a project assembly line, and generating a project deployment mirror image which comprises all environments of project operation deployment and encrypted codes. By using the assembly line, the model encryption and deployment process can be automated, and manual intervention is reduced, so that the development and deployment efficiency is remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a pipeline-based artificial intelligence model encryption and deployment method and device, belonging to the technical field of software development management. Background Art

[0002] With the rapid development of artificial intelligence technology, the types and frameworks of artificial intelligence models are becoming increasingly diverse, and the requirements for the operating environment are also different. These models usually require specific hardware and software environments to support their operation, including but not limited to central processing units (CPUs), graphics processing units (GPUs), operating systems, deep learning frameworks, and dependent libraries.

[0003] Artificial intelligence models often have high demands for computing resources, especially for large-scale neural network training and complex reasoning tasks. However, high-performance hardware resources are often expensive and difficult to scale and maintain. In addition, different models may have different requirements for hardware, resulting in inefficient resource allocation and utilization.

[0004] The configuration and management of the software environment is equally complex. Different AI frameworks (such as TensorFlow, PyTorch, etc.) and dependent libraries may require different versions of operating systems and toolchain support. In addition, the inconsistency of the software environment will lead to differences in the performance of the model on different machines or platforms, increasing the difficulty of model deployment and migration.

[0005] The emergence of containerization technologies such as Docker provides a new solution to the above problems. By packaging applications and their dependencies into independent container images, containerization technology provides isolation, portability, and consistency, making model deployment more convenient and flexible. However, the construction and management of container images also face challenges, such as slow image construction speed, complex construction process, and difficult to control image size.

[0006] In order to improve the efficiency of development and deployment, automated building and deployment processes are required. Automation can not only reduce manual operations and human errors, but also speed up experiments and iterations. However, the design and implementation of automated processes need to take into account the diversity of models, the consistency of environments, and the flexibility of deployment.

[0007] The security of source code is also an important consideration during the development and deployment of AI models. Source code may contain sensitive information or trade secrets, and measures need to be taken to protect it from unauthorized access or tampering. Traditional code protection methods may not be flexible or powerful enough to meet the needs of modern software development. Summary of the invention

[0008] The purpose of the present invention is to provide a pipeline-based artificial intelligence model encryption and deployment method and device to improve development and deployment efficiency and reduce the learning cost of algorithm engineers.

[0009] In order to achieve the above object, the present invention is implemented through the following technical solutions: Build a basic image pipeline to generate the basic image that all AI models rely on. The image includes the AI ​​framework, driver, Python environment, and Python public dependency package. Build an encrypted image pipeline to generate an encrypted image containing an encrypted script, and use the image to encrypt the source code during the project building process; Build the project pipeline and generate a project deployment image, which includes all environments and encrypted codes for running and deploying the project.

[0010] Preferably, the image produced by the encrypted image building pipeline is encrypted by accurately selecting or fuzzily selecting the files and folders that need to be encrypted.

[0011] Preferably, for Python code encryption, it is selected to compile it into a bytecode file for encryption.

[0012] Preferably, the Python code is encrypted using third-party tools, including PyInstaller, Cython, and PyArmor.

[0013] Preferably, an obfuscation tool is used to rename, replace, or delete the Python code.

[0014] Preferably, the basic image building pipeline starts with the CUDA and cuDNN versions and the Ubuntu operating system, installs the Python basic environment, and replaces the pip source with the domestic source.

[0015] Preferably, the project image building pipeline is built based on the base image and uses a two-stage build. In the first-stage build, based on the encrypted image, the unencrypted source code is encrypted by an encrypted script.

[0016] Preferably, use a build cache to speed up the execution of the pipeline, and set the directory where the dependencies are installed as the build cache directory.

[0017] Preferably, after the project image is built, it is deployed to the target machine through a shell script, in which global pipeline parameters are set, including whether to encrypt the selection field, the name of the built image, the version of the image, and the target folder in the deployment target machine.

[0018] The advantages of the present invention are that the use of the pipeline of the present invention can automate the model encryption and deployment process, reduce manual intervention, and thus significantly improve the efficiency of development and deployment. By building a cache, the execution speed of the pipeline can be accelerated and the time for repeated construction can be reduced. The unified pipeline configuration and deployment process reduces the different deployment methods that engineers need to master and learn, allowing them to focus more on the algorithm and model itself. By setting global pipeline parameters, the deployment configuration process is simplified and the risk of configuration errors is reduced. The encrypted image pipeline can encrypt the source code, protect intellectual property rights, and prevent code leakage. Accurately or fuzzily select the files and folders to be encrypted, and use obfuscation tools to rename, replace, and delete Python code, further enhancing the security of the code. The pipeline design allows customization according to specific needs, such as selecting encrypted files and folders, selecting encryption tools, etc. The modular design of the pipeline allows each part to be updated and optimized independently, improving the maintainability of the system. The basic image contains all the basic environments that the artificial intelligence model depends on, ensuring the consistency of the environment when deployed on different machines. The project image contains all the environments and encrypted code for the project operation deployment, further ensuring the consistency of the environment after deployment. The technical solution can be easily integrated with existing development processes and tool chains to support projects and teams of different sizes. The modular design of the pipeline makes it easy to expand to other types of projects or applications. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.

[0020] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0022] like Figure 1 As shown, a pipeline-based artificial intelligence model encryption and deployment method includes: an encrypted image building pipeline, a basic image building pipeline, and a project image building pipeline.

[0023] S1: Build a basic image pipeline to generate the basic image that all AI models depend on. The image contains the AI ​​framework, driver, Python environment, and Python public dependency package.

[0024] S2: Build an encrypted image pipeline to generate an encrypted image containing an encrypted script, and use the image to encrypt the source code during the project building process.

[0025] S3: Build the project pipeline and generate a project deployment image, which contains all the environments and encrypted codes for the project operation and deployment.

[0026] As a refinement of step S1, the encrypted image construction pipeline produces an image containing an encrypted script and its operating environment. The pipeline pushes the produced encrypted image to harbor. Through this image, the code to be encrypted can be copied to the container started by the image, the encrypted script is executed to encrypt the source code object, and the encrypted code is copied out of the image for deployment. The files and folders to be encrypted can be accurately selected, and the files and folders to be encrypted can be fuzzily selected. The script for Python code encryption is not the focus of the present invention. There are many options, including but not limited to compiling it into a bytecode file (.pyc file) for simple encryption. Although this method is not true encryption, because the bytecode can be decompiled back to the source code, it can at least prevent ordinary users from reading the code directly. There are also third-party tools that can encrypt Python code, such as PyInstaller, Cython, and PyArmor. These tools convert Python source code into machine code or other forms of bytecode, making the code difficult to understand and modify. The obfuscation tool can also rename, replace, delete, and other operations on the Python code, making the code difficult to understand and analyze. For example, tools such as PyObfuscate and Pyminifier can obfuscate Python code. Cython used in the present invention is a compiler for the Python language for writing C extensions. It enables Python code to be compiled into C language and then compiled into Python extension modules, thereby improving the execution efficiency and security of Python code.

[0027] As a refinement of step S2, the basic image construction pipeline includes the basic environment required for the project operation. In the present invention, the basic image is built from cuda:11.7.1, cudnn8 and ubuntu20.04, and the Python basic environment is installed. The pip source is replaced with a domestic source, and the Python environment shared by the installation project is relied on. This environment relies on Flask and uWSGI, and web services are provided to the outside by Flask and uWSGI in the basic image. At the same time, the apt source is replaced with a domestic source to speed up the speed of apt installation software in the image that depends on this image. In building the basic image, it can be selected whether to encrypt the basic code. If encryption is required, the unencrypted source code can be copied to the encrypted image in the first stage of the construction by a two-stage construction method, and the source code is encrypted by executing an encrypted script, and the encrypted code is copied to the code deployment position from the encrypted image when the second stage is built, and the basic image is built.

[0028] As a refinement of step S3, the project image building pipeline includes the project and the dependencies required by the project. In the present invention, the project image is built based on the basic image, and a two-stage build is used. In the first-stage build, the encrypted image is used to encrypt the unencrypted source code through the encryption script, and the encrypted file is copied to the project deployment location in the second-stage build. Artificial intelligence models usually have many dependencies. At the same time, in order to ensure the simplicity and stability of the basic image, too many dependencies will not be stored in the basic image. Usually, the dependencies required by the project will be installed during the project image building process. However, in the pipeline, the time for installing the dependency may be too long, causing the pipeline to fail to execute. In order to avoid this problem, the build cache is used in the present invention to speed up the execution speed of the pipeline, and the directory where the dependency is installed is set as the build cache directory. After the first complete execution of the pipeline, the build cache directory will be fully uploaded. Before the build cache expires, the pipeline will be executed again to mount the cache directory to the image. If there are related dependencies in the cache directory, the related dependencies will not be downloaded.

[0029] After the project image is built, it can be deployed to the target machine through a shell script in the pipeline. In the pipeline construction, the present invention sets global pipeline parameters, and the global parameters include whether to encrypt the selection field isEncryt, the name of the built image imageName, the version tag of the image, and the target folder targetFloder in the target machine for deployment. First, a target folder is created on the target machine, and image pulling and docker-compose.yml file pulling are executed in the target folder, and the container is run through the docker compose up –d command.

[0030] The following is the sample code of this embodiment.

[0031] (1) The content of the Dockerfile for building the encrypted image is as follows: ARG python_version=3.8.10 FROM python:${python_version} ARG dir_exact_dict_arg=[] ARG dir_fuzzy_dict_arg=[] ARG file_exact_dict_arg=['__init__.py'] ARG file_fuzzy_dict_arg=['.*_run\.py','.*base_main\.py'] # Directory exact dictionary ENV dir_exact_dict=${dir_exact_dict_arg} # Directory fuzzy dictionary regular matching ENV dir_fuzzy_dict=${dir_fuzzy_dict_arg} # File-accurate dictionary ENV file_exact_dict=${file_exact_dict_arg} # File fuzzy dictionary regular matching ENV file_fuzzy_dict=${file_fuzzy_dict_arg} WORKDIR / home / work COPY . / encrypt . / encryt COPY encrypt.sh . / encrypt.sh RUN pip install pip Cython --target / usr / local / lib / python3.8 -ihttps: / / mirrors.aliyun.com / pypi / simple / &&chmod u+x . / encrypt.sh WORKDIR / home / code (2) The content of the Dockerfile built by the base image is as follows: FROM ssr-luckycat-docker-local.repo.inspur.com / ssr_common / encrypt-script:python-3.8.10 AS builder COPY . / code . / code RUN / home / work / encrypt.sh FROM nvidia / cuda:11.7.1-cudnn8-runtime-ubuntu20.04 ENV DEBIAN_FRONTEND=noninteractive ENV TZ=Asia / Shanghai RUN echo ""> / etc / apt / sources.list&&echo "deb http: / / mirrors.aliyun.com / ubuntu / focal main restricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb-src http: / / mirrors.aliyun.com / ubuntu / focal main restricteduniverse multiverse">> / etc / apt / sources.list&&\ echo "deb http: / / mirrors.aliyun.com / ubuntu / focal-security mainrestricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb-src http: / / mirrors.aliyun.com / ubuntu / focal-security mainrestricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb http: / / mirrors.aliyun.com / ubuntu / focal-updates mainrestricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb-src http: / / mirrors.aliyun.com / ubuntu / focal-updates mainrestricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb http: / / mirrors.aliyun.com / ubuntu / focal-proposed mainrestricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb-src http: / / mirrors.aliyun.com / ubuntu / focal-proposed mainrestricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb http: / / mirrors.aliyun.com / ubuntu / focal-backports mainrestricted universe multiverse">> / etc / apt / sources.list&&\ echo "deb-src http: / / mirrors.aliyun.com / ubuntu / focal-backports mainrestricted universe multiverse">> / etc / apt / sources.list&&\ apt-get update # install python3.8.10 RUN apt-get install -y python3 python3-pip \ &&apt-get install -y libcairo2-dev pkg-config python3-dev \ &&apt-get autoremove -y&&apt-get clean RUN ln -s / usr / bin / python3 / usr / bin / python RUN ln -sf / usr / share / zoneinfo / Asia / Shanghai / etc / localtime&&echo "Asia / shanghai"> / etc / timezone WORKDIR / home / work # project code COPY --from=builder / home / code / code . / code # project config COPY . / uwsgi_config.ini . / uwsgi_config.ini # project log RUN mkdir logs&&touch logs / uwsgi.log # install requirements.txt COPY requirements.txt . RUN python3 -m pip config set global.index-url https: / / pypi.mirrors.ustc.edu.cn / simple / &&python3 -m pip install --upgrade pip&&pip3install --upgrade setuptools \ &&pip3 install --no-cache-dir -r requirements.txt。

[0032] (3) The content of the Dockerfile for building the project image is as follows: FROM ssr-luckycat-docker-local.repo.inspur.com / ssr_common / encrypt-script:python-3.8.10 AS builder COPY requirements.txt . RUN python3 -m pip config set global.index-url https: / / pypi.mirrors.ustc.edu.cn / simple / && pip3 install --no-cache-dir -r requirements.txt COPY. . / code RUN / home / work / encrypt.sh # install requirements.txt FROM ssr-luckycat-docker-local.repo.inspur.com / ssr_common / ubuntu / iast.ai.frame:1.0_cuda_runtime_python_dev_encrypt as prod WORKDIR / home / work RUN apt-get install -y libgl1-mesa-glx COPY --from=builder / usr / local / lib / python3.8 / site-packages / usr / local / lib / python3.8 / dist-packages # project code #COPY. . / code / python_frame / app / ocr COPY --from=builder / home / code / code . / code / python_frame / app / ocr ENTRYPOINT ["uwsgi", "--ini", "uwsgi_config.ini"] (4) The commands executed by shell are as follows: mkdir -p ${targetFloder} cd ${targetFloder} docker pull ssr-luckycat-docker-local.repo.inspur.com / ${imageName}:${tag} git archive --remote=ssh: / / git@devops.inspur.com / ssr_engine / ocr.gitHEAD docker-compose.yml | tar -x docker-compose up -d.

[0033] The embodiment of the present disclosure also provides a pipeline-based artificial intelligence model encryption and deployment device, including a processor and a memory. Optionally, the device may also include a communication interface and a bus. The processor, the communication interface, and the memory may communicate with each other through the bus. The communication interface may be used for information transmission. The processor may call the logic instructions in the memory to execute the pipeline-based artificial intelligence model encryption and deployment method of the above embodiment.

[0034] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.

[0035] As a computer-readable storage medium, the memory can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor executes functional applications and data processing by running the program instructions / modules stored in the memory, that is, implementing the pipeline-based artificial intelligence model encryption and deployment method in the above embodiment.

[0036] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory may include a high-speed random access memory and may also include a non-volatile memory.

[0037] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A pipeline-based artificial intelligence model encryption and deployment method, characterized in that: The following steps are involved: Build a basic image pipeline to generate the basic image that all AI models rely on. The image includes the AI ​​framework, driver, Python environment, and Python public dependency package. Build an encrypted image pipeline to generate an encrypted image containing an encrypted script, and use the image to encrypt the source code during the project building process; Build the project pipeline and generate a project deployment image, which includes all environments and encrypted codes for running and deploying the project.

2. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: The images produced by the encrypted image building pipeline are encrypted by precise or fuzzy selection of files and folders that need to be encrypted.

3. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: For Python code encryption, choose to compile it into a bytecode file for encryption.

4. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: Use third-party tools to encrypt Python code, including PyInstaller, Cython, and PyArmor.

5. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: Use obfuscation tools to rename, replace, and delete Python code.

6. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: The basic image building pipeline starts with the CUDA and cuDNN versions and the Ubuntu operating system, installs the Python basic environment, and replaces the pip source with the domestic source.

7. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: The project image building pipeline is built based on the base image and uses a two-stage build. In the first-stage build, based on the encrypted image, the unencrypted source code is encrypted through the encryption script.

8. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: Use build cache to speed up the execution of the pipeline. Set the directory where the dependencies are installed as the build cache directory.

9. The pipeline-based artificial intelligence model encryption and deployment method according to claim 1, characterized in that: After the project image is built, it is deployed to the target machine through a shell script, which sets the global pipeline parameters, including whether to encrypt the selection field, the name of the built image, the version of the image, and the target folder in the target machine.

10. A pipeline-based artificial intelligence model encryption and deployment device, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the pipeline-based artificial intelligence model encryption and deployment method as described in any one of claims 1-9 when running the program instructions.