WO2025201476A1 - 模型文件保护 - Google Patents
模型文件保护Info
- Publication number
- WO2025201476A1 WO2025201476A1 PCT/CN2025/085432 CN2025085432W WO2025201476A1 WO 2025201476 A1 WO2025201476 A1 WO 2025201476A1 CN 2025085432 W CN2025085432 W CN 2025085432W WO 2025201476 A1 WO2025201476 A1 WO 2025201476A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- file
- model
- tvm
- operators
- target model
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/62—Protecting access to data via a platform, e.g. using keys or access control rules
- G06F21/6209—Protecting access to data via a platform, e.g. using keys or access control rules to a single file or object, e.g. in a secure envelope, encrypted and accessed using a key, or with access control rules appended to the object itself
Definitions
- This document relates to the field of artificial intelligence model security technology, and in particular to methods and devices for protecting model files.
- one or more embodiments of the present specification provide a model file protection method, including: obtaining a model file corresponding to a target model to be protected, wherein the model file is constructed based on a model graph composed of multiple operators; based on the model file, compiling the target model through a preset compiler to obtain a binary file corresponding to the target model, and sending the binary file corresponding to the target model to a terminal device, wherein the binary file corresponding to the target model is used to trigger the terminal device to run the target model by running the binary file.
- a model file protection device including: a model file acquisition module, which acquires a model file corresponding to a target model to be protected, wherein the model file is constructed based on a model graph composed of multiple operators; a compilation module, which compiles the target model based on the model file through a preset compiler to obtain a binary file corresponding to the target model, and sends the binary file corresponding to the target model to a terminal device, wherein the binary file corresponding to the target model is used to trigger the terminal device to run the target model by running the binary file.
- one or more embodiments of the present specification provide an electronic device, comprising a processor and a memory arranged to store computer-executable instructions, wherein when the executable instructions are executed, the processor is enabled to: obtain a model file corresponding to a target model to be protected, wherein the model file is constructed based on a model graph composed of multiple operators; based on the model file, compile the target model through a preset compiler to obtain a binary file corresponding to the target model, and send the binary file corresponding to the target model to a terminal device, wherein the binary file corresponding to the target model is used to trigger the terminal device to run the target model by running the binary file.
- one or more embodiments of the present specification provide a storage medium for storing a computer program, which can be executed by a processor to implement the following process: obtaining a model file corresponding to the target model to be protected, wherein the model file is constructed based on a model graph composed of multiple operators; based on the model file, compiling the target model through a preset compiler to obtain a binary file corresponding to the target model, and sending the binary file corresponding to the target model to a terminal device, wherein the binary file corresponding to the target model is used to trigger the terminal device to run the target model by running the binary file.
- FIG1 is a schematic flow chart of a model file protection method according to an embodiment of this specification.
- FIG2 is a schematic flow chart of another model file protection method according to an embodiment of this specification.
- FIG3 is a schematic diagram illustrating the implementation principle of model conversion processing based on the TVM compiler according to an embodiment of this specification.
- FIG4 is a schematic diagram showing the implementation principle of a model file protection method according to an embodiment of this specification.
- FIG5 is a schematic block diagram of a model file protection device according to an embodiment of this specification.
- FIG6 is a schematic block diagram of an electronic device according to an embodiment of this specification.
- One or more embodiments of this specification provide a model file protection method and device.
- an embodiment of this specification provides a model file protection method.
- the method can be executed by a server.
- the server can be a standalone server or a server cluster consisting of multiple servers.
- the server can be a backend server in the financial field or online shopping field, or a backend server for an application.
- the method can specifically include the following steps.
- step S102 a model file corresponding to the target model to be protected is obtained, where the model file is constructed based on a model graph composed of multiple operators.
- the training process of artificial intelligence models is usually completed on the server side, and then the model file corresponding to the trained artificial intelligence model is sent to the terminal device to run the artificial intelligence model.
- the model file protection method in the embodiment of this specification is to process the model file on the server side and send it to the terminal device for operation. Since the training process of artificial intelligence models requires a large investment, artificial intelligence models and their corresponding model files are usually the core assets of an enterprise. Therefore, it is necessary not only to ensure the safe operation of artificial intelligence models on terminal devices, but also to protect the security and privacy of model files.
- step S104 based on the model file, the target model is compiled by a preset compiler to obtain a binary file corresponding to the target model, and the binary file corresponding to the target model is sent to the terminal device.
- the binary file corresponding to the target model is used to trigger the terminal device to run the target model by running the binary file.
- the original model file format usually adopts a standard model file format such as ONNX format, TensorFlow Lite format, etc.
- a standard model file format such as ONNX format, TensorFlow Lite format, etc.
- the embodiment of this specification compiles the target model through a preset compiler, thereby converting the model file into a binary file (such as ELF (Executable and Linkable Format, executable and linkable format) file, AXF (ARM Executable File, ARM executable file) file and BIN (binary data structure file format) file, etc.).
- the model file can be directly compiled into a binary file through a preset compiler, or the model file can be first converted into an equivalent intermediate file through a preset compiler (such as the TVM compiler, MLIR compiler, etc.), and then the preset compiler (such as the Clang compiler) is used to convert the intermediate file into a binary file that can be run directly on the terminal device.
- a preset compiler such as the TVM compiler, MLIR compiler, etc.
- the preset compiler such as the Clang compiler
- step S1042 the model file is parsed to convert the model file into a source code file corresponding to the target model.
- model files into the source code files corresponding to the target model can be achieved by designing a custom model file conversion tool and defining parsing functions within the tool to achieve the goal of converting model files into source code files.
- secondary development can be conducted based on existing open source tools (such as the MLIR compiler and TVM compiler), adding specific model file parsing functions to the open source tools based on specific application scenarios and functional requirements.
- adding the step of converting the model file into a source code file can further increase the difficulty of reverse analysis of the binary file obtained by the terminal device, thereby improving the security of the model file.
- relevant privacy protection processing can be performed based on the source code file, such as: encrypting the source code file, performing code obfuscation processing on the source code file, etc., thereby further increasing the difficulty of reverse analysis of the binary file and also helping to improve the security of the model file.
- the processing methods of the above step S1042 can be various.
- Three processing methods based on the TVM (Tensor Virtual Machine, end-to-end deep learning compiler) compiler i.e., the preset compiler is the TVM compiler
- the implementation principles of the three optional processing methods for model conversion processing based on the TVM compiler are shown in Figure 3.
- the conventional default optimization pass processing method based on the TVM compiler can be adopted, the customized obfuscation pass processing method based on the TVM compiler can be adopted, and the conversion processing method for special operators (such as user-defined operators in the model file) based on the TVM compiler can be adopted.
- a combination of any two or three of the above three methods can also be adopted.
- step A2 the model file is parsed based on the TVM compiler and converted into a TVM intermediate code file corresponding to the target model.
- the TVM compiler comes from the Apache TVM project, an open source project incubated by the Apache Software Foundation. The project is committed to maintaining a diverse community of experts and practitioners in machine learning, compilers, and system architecture.
- the TVM compiler is an accessible, extensible, and automated open source framework. It is an end-to-end deep learning compilation framework that can support hardware platforms to optimize current machine learning models and develop new machine learning models.
- the TVM compiler can compile trained models of various deep learning frameworks (such as the TensorFlow framework and the PyTorch framework) into code that can be efficiently executed on different hardware platforms.
- the TVM compiler can compile deep learning models into the smallest deployable modules. It can also automatically generate the infrastructure for optimizing the model on the back end, thereby further improving the performance of deep learning models.
- a pass in the TVM compiler is also called a transform.
- Each transform is used to convert and optimize an existing program into an equivalent program, or to lower the existing program to the next pass.
- step A4 the operators in the TVM intermediate code file are converted to obtain the source code file corresponding to the target model.
- synonym replacement processing can be performed on operators in the TVM intermediate code file in a random manner.
- the random processing method includes: randomly selecting the proportion of operators to be replaced, randomly selecting the operators to be replaced, and the same operator can correspond to multiple different conversion results, and the conversion result selected for the same operator is random.
- step B4 can be performed as follows: selecting operators to be synonymously replaced in the TVM intermediate code file according to a randomly set ratio, performing synonymous replacement on the selected operators, and obtaining updated operators in the TVM intermediate code file based on the selected operators and other operators in the TVM intermediate code file.
- the ratio is set to 10% during the first compilation, 10% of the operators in the TVM intermediate code file will be randomly selected for synonymous replacement. If the ratio is set to 58% during the second compilation, 58% of the operators in the TVM intermediate code file will be randomly selected for synonymous replacement. The ratio is set differently each time, allowing operators to be randomly selected for synonymous replacement.
- step B4 can be performed as follows: randomly selecting operators to be synonymously replaced in the TVM intermediate code file according to a preset ratio, performing synonymous replacement on the randomly selected operators, and obtaining updated operators in the TVM intermediate code file based on the randomly selected operators and other operators in the TVM intermediate code file.
- the preset ratio is 30%, then 30% of the operators are randomly selected from the TVM intermediate code file for synonym replacement in multiple compilation processes.
- the ratio of the selected operators is fixed, but the operators selected each time are random.
- step B4 may be performed as follows: operators to be subjected to synonymous replacement processing in the TVM intermediate code file are selected according to a randomly set ratio, each of the selected operators is randomly matched with a result after synonymous replacement processing from multiple synonymous replacement processing results, and an updated TVM intermediate code file operator is obtained based on the selected operator and other operators in the TVM intermediate code file.
- step B4 may be performed as follows: randomly selecting operators to be synonymously replaced in the TVM intermediate code file according to a preset ratio, randomly matching each of the randomly selected operators with a result from multiple synonymously replaced results, and obtaining an updated operator in the TVM intermediate code file based on the randomly selected operator and other operators in the TVM intermediate code file.
- steps B2-B6 synonymous substitution is performed on the operators in the TVM intermediate code file, which is equivalent to customizing an obfuscation pass in the TVM compiler.
- This source code file through synonymous substitution, implements privacy protection for the operators in the TVM intermediate code file.
- Subsequent steps compile this source code file to obtain the corresponding binary file, further increasing the difficulty of reverse engineering the binary file obtained by the terminal device and thus improving the security of the model file.
- the third optional processing method is to convert special operators based on the TVM compiler. For details, see the processing steps C2-C6 below.
- step C2 based on the preset operator processing rules, operators that exist in the model file but do not exist in the TVM compiler are identified, and conversion results corresponding to the identified operators are determined.
- the TVM compiler supports a limited number of operators, when compiling a model file, some operators may exist in the model file but not in the TVM compiler. For example, these operators may be user-defined in the model file or operators that have not been updated in the TVM compiler in a timely manner. Consequently, the conversion results of these operators will not be available in the TVM compiler.
- the operator is first identified and its corresponding conversion result is determined based on the preset operator processing rules.
- step C4 the identified operator and its corresponding conversion result are added to the TVM compiler to update the TVM compiler, thereby obtaining an updated TVM compiler.
- the TVM compiler complements and performs compatibility processing on operators that exist in the model file but not in the TVM compiler itself, thereby achieving compatibility between the TVM compiler and the model file. This helps improve the efficiency and accuracy of converting source code files from model files.
- step D2 the source code file is compiled by a preset compiler, and during the compilation process, the intermediate code corresponding to the target model is obtained.
- obfuscation processing not only can obfuscation processing be performed during the conversion process of the model file to the source code file (operator synonym replacement processing), but obfuscation processing can also be performed during the conversion process of the source code file to the binary code file. In implementation, obfuscation processing can also be performed simultaneously in the above two conversion processes. Through the above obfuscation processing process, the difficulty of reverse analysis of the binary file obtained by the terminal device can be effectively improved, thereby improving the security of the model file.
- Figure 4 is a schematic diagram of the implementation principle of the model file protection method according to an embodiment of the present specification.
- the model file protection method of the embodiment of the present specification is mainly executed on the server side.
- the model file to be protected is first subjected to model conversion processing on the server side to obtain the converted source code file, and then the converted source code file is obfuscated and compiled to obtain the protected binary file.
- the protected binary file can be downloaded to the terminal device by sending the file to the terminal device through the server side.
- the protected binary file can run normally directly on the terminal device, and can exchange information with other model engines on the terminal device, and the running result of the protected binary file on the terminal device is equivalent to the running result of running the model file to be protected directly on the terminal device.
- model file protection method provided in one or more embodiments of this specification. Based on the same idea, one or more embodiments of this specification also provide a model file protection device, as shown in FIG5 .
- the model file protection device includes: a model file acquisition module 210 and a compilation module 220, wherein: the model file acquisition module 210 obtains the model file corresponding to the target model to be protected, and the model file is constructed based on a model graph composed of multiple operators; the compilation module 220, based on the model file, compiles the target model through a preset compiler to obtain a binary file corresponding to the target model, and sends the binary file corresponding to the target model to the terminal device, and the binary file corresponding to the target model is used to trigger the terminal device to run the target model by running the binary file.
- another implementation of the source code file acquisition unit includes: an operator identification subunit, which identifies operators that exist in the model file but do not exist in the TVM compiler based on preset operator processing rules, and determines conversion results corresponding to the identified operators; a TVM compiler update subunit, which adds the identified operators and their corresponding conversion results to the TVM compiler to update the TVM compiler and obtain an updated TVM compiler; and a parsing subunit, which parses the model file including the identified operators based on the updated TVM compiler to obtain a source code file corresponding to the target model.
- a typical implementation device is a computer.
- the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
- These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.
- These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.
- These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.
- Memory may include non-permanent storage in a computer-readable medium, in the form of random access memory (RAM) and/or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
- RAM random access memory
- ROM read-only memory
- flash RAM flash random access memory
- Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information.
- the information can be computer-readable instructions, data structures, program modules or other data.
- Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
- computer-readable media does not include transitory media such as modulated data signals and carrier waves.
- program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types.
- This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network.
- program modules may be located in local and remote computer storage media, including storage devices.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Health & Medical Sciences (AREA)
- Bioethics (AREA)
- General Health & Medical Sciences (AREA)
- Computer Hardware Design (AREA)
- Computer Security & Cryptography (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
本说明书一个或多个实施例公开了一种模型文件保护方法及装置。其中,所述方法首先获取待保护的目标模型对应的模型文件,其中,该模型文件基于多个算子构成的模型图而构建;然后基于所获取的模型文件,通过预设的编译器对目标模型进行编译处理,得到目标模型对应的二进制文件,并将目标模型对应的二进制文件发送至终端设备,其中,目标模型对应的二进制文件用于触发终端设备通过运行二进制文件以运行目标模型。
Description
本文件涉及人工智能模型安全技术领域,尤其涉及用于模型文件保护的方法及装置。
当前,手机等终端设备已成为人们生活中不可缺少的互联网设备,基于用户体验的需求,越来越多的人工智能模型文件直接运行于手机等终端设备上。而人工智能模型文件通常是企业的重要资产,将其直接运行于终端设备,存在着被攻击或窃取等安全风险,且随着人们对自己的隐私数据越来越重视,需要对运行于终端设备上的人工智能模型进行保护,以防止人工智能模型文件被攻击或窃取,基于此,需要提供一种能够提高人工智能模型文件的窃取难度、有效防止人工智能模型文件被逆向操作的模型文件保护方法及装置。
一方面,本说明书一个或多个实施例提供一种模型文件保护方法,包括:获取待保护的目标模型对应的模型文件,所述模型文件基于多个算子构成的模型图而构建;基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,并将所述目标模型对应的二进制文件发送至终端设备,所述目标模型对应的二进制文件用于触发终端设备通过运行所述二进制文件以运行所述目标模型。
另一方面,本说明书一个或多个实施例提供一种模型文件保护装置,包括:模型文件获取模块,获取待保护的目标模型对应的模型文件,所述模型文件基于多个算子构成的模型图而构建;编译模块,基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,并将所述目标模型对应的二进制文件发送至终端设备,所述目标模型对应的二进制文件用于触发终端设备通过运行所述二进制文件以运行所述目标模型。
又一方面,本说明书一个或多个实施例提供一种电子设备,包括处理器以及被安排成存储计算机可执行指令的存储器,在所述可执行指令被执行时,能够使得所述处理器:获取待保护的目标模型对应的模型文件,所述模型文件基于多个算子构成的模型图而构建;基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,并将所述目标模型对应的二进制文件发送至终端设备,所述目标模型对应的二进制文件用于触发终端设备通过运行所述二进制文件以运行所述目标模型。
再一方面,本说明书一个或多个实施例提供存储介质,用于存储计算机程序,所属计算机程序能够被处理器执行以实现以下流程:获取待保护的目标模型对应的模型文件,所述模型文件基于多个算子构成的模型图而构建;基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,并将所述目标模型对应的二进制文件发送至终端设备,所述目标模型对应的二进制文件用于触发终端设备通过运行所述二进制文件以运行所述目标模型。
为了更清楚地说明本说明书一个或多个实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书一个或多个实施例中记载的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是根据本说明书一实施例的一种模型文件保护方法的示意性流程图。
图2是根据本说明书一实施例的另一种模型文件保护方法的示意性流程图。
图3是根据本说明书一实施例基于TVM编译器进行模型转换处理的实现原理示意图。
图4是根据本说明书一实施例的模型文件保护方法的实现原理示意图。
图5是根据本说明书一实施例的一种模型文件保护装置的示意性框图。
图6是根据本说明书一实施例的一种电子设备的示意性框图。
本说明书一个或多个实施例提供一种模型文件保护方法及装置。
为了使本技术领域的人员更好地理解本说明书一个或多个实施例中的技术方案,下面将结合本说明书一个或多个实施例中的附图,对本说明书一个或多个实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书一个或多个实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都应当属于本文件保护的范围。
如图1所示,本说明书实施例提供一种模型文件保护方法,该方法的执行主体可以为服务器。该服务器可以是独立的一个服务器,还可以是由多个服务器构成的服务器集群等,该服务器可以是如金融领域或网络购物领域等的后台服务器,也可以是某应用程序的后台服务器等。该方法具体可以包括以下步骤。
在步骤S102中,获取待保护的目标模型对应的模型文件,模型文件基于多个算子构成的模型图而构建。
本说明书实施例中的模型文件指的是人工智能模型的文件,该模型文件以模型图的形式构建,且模型图由多个算子构成。模型文件的格式采用标准文件格式,如:ONNX格式(文件后缀为.onnx),TensorFlow Lite格式(文件后缀为.tflite)等。
随着手机等终端设备的兴起,通常人工智能模型的训练过程在服务端完成,然后将训练后的人工智能模型对应的模型文件发送至终端设备以运行该人工智能模型。本说明书实施例中的模型文件保护方法是在服务端对模型文件进行处理,并下发至终端设备运行。由于人工智能模型的训练过程投资较大,人工智能模型及其对应的模型文件通常是企业的核心资产,因此,不仅需要确保终端设备上人工智能模型的安全运行,还需要对模型文件进行安全和隐私保护。
在步骤S104中,基于模型文件,通过预设的编译器对目标模型进行编译处理,得到目标模型对应的二进制文件,并将目标模型对应的二进制文件发送至终端设备,目标模型对应的二进制文件用于触发终端设备通过运行二进制文件以运行目标模型。
原始的模型文件格式通常采用如ONNX格式、TensorFlow Lite格式等标准模型文件格式,上述标准模型文件格式的模型文件发送至终端设备执行时,如果模型文件被窃取,窃取方非常容易对其进行逆向分析,从而影响目标模型的安全性。本说明书实施例通过预设的编译器对目标模型进行编译处理,从而将模型文件转换为二进制文件(如ELF(Executable and Linkable Format,可执行与可链接格式)文件、AXF(ARM Executable File,ARM可执行文件)文件以及BIN(binary数据结构的文件格式)文件等),由于上述二进制文件在终端设备中运行时被逆向分析的难度相比于对模型文件逆向分析的难度显著提升,且上述二进制文件在终端设备上的运行结果与直接在终端设备上运行原始的模型文件的结果等效,因此,通过预设的编译器将模型文件转化成二进制文件,能够有效保护终端设备上的模型文件。
在实施中,可以通过预设的编译器直接将模型文件编译为二进制文件,也可以首先通过预设的编译器(如TVM编译器、MLIR编译器等)将模型文件转换为等效的中间文件,再利用预设的编译器(如Clang编译器)将中间文件转换为可以直接在终端设备上运行的二进制文件。
本说明书实施例提供一种模型文件保护方法,应用于服务器,首先获取待保护的目标模型对应的模型文件,然后基于所获取的模型文件,通过预设的编译器对目标模型进行编译处理,得到目标模型对应的二进制文件,并将目标模型对应的二进制文件发送至终端设备,这样,在对模型文件进行处理时,通过将目标模型对应的模型文件转换为目标模型对应的可直接在终端设备上运行的二进制文件,从而将模型文件与执行引擎进行融合,使得终端设备上不存在模型文件加载到执行引擎以及执行引擎运行模型文件的步骤,从而显著提升模型文件的安全性。而且,通过该二进制文件逆向分析获取模型文件的难度较大,也有利于大大提高模型文件的窃取难度,从而提高模型文件的安全性。
如图2所示,本说明书实施例中,上述步骤S104中基于模型文件,通过预设的编译器对目标模型进行编译处理,得到目标模型对应的二进制文件的处理方式可以多种多样,以下提供一种可选的处理方式,具体可以参见以下步骤S1042-S1044的处理。
在步骤S1042中,通过对模型文件进行解析处理,将模型文件转换为目标模型对应的源代码文件。
其中,源代码文件可以是基于C语言、C++语言、python语言等语言创建的文件,相应地,可以将模型文件转换为C代码文件、C++代码文件、python代码文件等源代码文件。
在实施中,将模型文件转换为目标模型对应的源代码文件的处理方式,可以是设计一自定义功能的模型文件转化工具,通过在该模型文件转换工具中定义解析处理的功能,实现将模型文件转换为源代码文件的目的。也可以基于现有的开源工具(如:MLIR编译器、TVM编译器等)进行二次开发,根据具体应用场景和功能要求,在开源工具中增加对模型文件解析处理的具体功能。
在将模型文件编译处理为二进制文件的过程中,增加将模型文件转换为源代码文件的步骤,能够进一步提升对终端设备所获取到的二进制文件进行逆向分析的难度,从而提高模型文件的安全性。此外,通过增加将模型文件转换为源代码文件的步骤,还可以基于源代码文件进行相关的隐私保护处理,例如:对源代码文件进行加密,对源代码文件进行代码混淆处理等,从而进一步提升对二进制文件进行逆向分析的难度,也有利于提高模型文件的安全性。
在步骤S1044中,通过预设的编译器对源代码文件进行编译处理,得到目标模型对应的二进制文件。
通过步骤S1042获取到源代码文件后,再对源代码文件进行编译处理,得到相应的二进制文件。在实施中,可以直接对源代码文件中的源代码进行编译处理,获取目标模型对应的二进制文件,也可以首先将源代码文件中的源代码进行编译处理获取中间代码,再对中间代码进行相关处理,例如:对中间代码进行加密,对中间代码进行代码混淆处理等,再基于中间代码获取二进制文件。
本说明书实施例中,上述步骤S1042的处理方式可以多种多样,以下提供三种基于TVM(Tensor Virtual Machine,端到端深度学习编译器)编译器(即:预设的编译器是TVM编译器)的处理方式,三种可选的处理方式基于TVM编译器进行模型转换处理的实现原理如图3所示,在实施中,可以基于TVM编译器采用常规的默认优化pass处理的方式,可以基于TVM编译器采用定制混淆pass处理的方式,也可以基于TVM编译器对特殊算子(如:模型文件中用户自定义的算子)进行转化处理的方式,还可以采用上述三种方式中的任意两种或三种方式的组合处理方式。
第一种可选的处理方式为基于TVM编译器采用默认优化pass处理的方式,具体可以参见以下步骤A2-A4的处理。
在步骤A2中,基于TVM编译器对模型文件进行解析处理,将模型文件转换为目标模型对应的TVM中间代码文件。
TVM编译器来自Apache TVM项目,该项目是基于Apache软件基金会孵化的开源项目,该项目致力于维护一个由机器学习、编译器和系统架构方面的专家及从业者组成的多样化社区。TVM编译器是一个可访问、可扩展且自动化的开源框架,是一种端到端的深度学习编译框架,能够支持硬件平台优化当前机器学习模型以及开发新的机器学习模型。具体地,通过TVM编译器能够将各种深度学习框架(如TensorFlow框架和PyTorch框架等)训练后的模型编译成能够在不同硬件平台上高效执行的代码,即:通过TVM编译器能够将深度学习模型编译成最小可部署的模块。还能够在后端自动生成优化模型的基础设施,从而进一步提高深度学习模型的性能。
TVM编译器中的pass(转化过程)又称transform(变换),每一个transform用于将现有程序转换并优化为一个等价程序,或者用于把现有程序lower(下降处理)到下一层pass中。
在步骤A4中,对TVM中间代码文件中的算子进行转换处理,获取目标模型对应的源代码文件。
通过采用TVM编译器作为预设的编译器,能够兼容较多的模型文件类型以及模型文件格式,大大减少使预设的编译器与模型文件适配的工作量,有利于提高将模型文件转换我源代码文件的转换效率。
第二种可选的处理方式为基于TVM编译器采用定制混淆pass处理的方式,具体可以参见以下步骤B2-B6的处理。
在步骤B2中,基于TVM编译器对模型文件进行解析处理,将模型文件转换为目标模型对应的TVM中间代码文件。
在步骤B4中,对TVM中间代码文件中的算子进行同义替换处理,以对TVM中间代码文件中的算子进行更新,得到更新后的TVM中间代码文件算子。
在实施中,对TVM中间代码文件中的算子进行同义替换处理,可以采用随机处理的方式进行同义替换处理,随机处理的方式包括:选择待替换的算子的比例是随机的,所选择的待替换的算子是随机的,同一个算子可对应多个不同的转换结果,对同一个算子所选择的转换结果是随机的。
在一种可能的实现方式中,步骤B4可以处理为:按照随机设定的比例选择TVM中间代码文件中进行同义替换处理的算子,对所选择的算子进行同义替换处理,并基于所选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子。
例如:在多次编译处理中,第一次编译处理时设定的比例为10%,则第一次从TVM中间代码文件中随机选择10%的算子进行同义替换处理。第二次编译处理时设定的比例为58%,则第二次从TVM中间代码文件中随机选择58%的算子进行同义替换处理。每次设定的比例均不同从而实现随机设定比例选择进行同义替换处理的算子。
在另一种可能的实现方式中,步骤B4可以处理为:按照预设的比例随机选择TVM中间代码文件中进行同义替换处理的算子,对随机选择的算子进行同义替换处理,并基于随机选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子。
例如:预设的比例是30%,则多次编译处理均从TVM中间代码文件中随机选择30%的算子进行同义替换处理,所选择算子的比例是固定的,但是每次所选择的算子是随机的。
在又一种可能的实现方式中,步骤B4可以处理为:按照随机设定的比例选择TVM中间代码文件中进行同义替换处理的算子,使所选择的算子中的每个算子从多个同义替换处理后的结果中随机匹配一个同义替换处理后的结果,并基于所选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子。
在再一种可能的实现方式中,步骤B4可以处理为:按照预设的比例随机选择TVM中间代码文件中进行同义替换处理的算子,使随机选择的算子中的每个算子从多个同义替换处理后的结果中随机匹配一个同义替换处理后的结果,并基于随机选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子。
在步骤B6中,基于TVM编译器对更新后的TVM中间代码文件算子进行转换处理,获取目标模型对应的源代码文件。
在步骤B2-B6中,通过对TVM中间代码文件中的算子进行同义替换处理,相当于在TVM编译器中定制混淆pass,能够获取到与目标模型对应的更加复杂的源代码文件,且该源代码文件通过同义替换处理能够对TVM中间代码文件中的算子实现隐私保护功能,后续步骤基于该源代码文件进行编译处理获取对应的二进制文件,能够进一步提升对终端设备所获取到的二进制文件进行逆向分析的难度,从而提高模型文件的安全性。
第三种可选的处理方式为基于TVM编译器对特殊算子进行转化处理,具体可以参见以下步骤C2-C6的处理。
在步骤C2中,基于预设的算子处理规则,识别存在于模型文件中且不存在于TVM编译器中的算子,并确定所识别的算子对应的转换结果。
由于TVM编译器支持的算子有限,在对模型文件进行编译处理时,可能有一部分算子存在于模型文件中且不存在于TVM编译器中,例如:模型文件中用户自定义的算子,TVM编译器中未及时更新的算子等,相应地,该部分算子的转换结果也不会存在于TVM编译器中。在对上述算子进行转换处理时,首先基于预设的算子处理规则,识别上述算子并确定上述算子对应的转换结果。
在步骤C4中,将所识别的算子及其对应的转换结果添加至TVM编译器中,以更新TVM编译器,得到更新后的TVM编译器。
在步骤C6中,基于更新后的TVM编译器对包括所识别的算子的模型文件进行解析处理,获取目标模型对应的源代码文件。
在以上步骤C2-C6中,通过在TVM编译器中对存在于模型文件中且不存在于TVM编译器中的算子进行补充和兼容处理,从而实现TVM编译器与模型文件的适配度,有利于提高基于模型文件获取源代码文件的转换效率和转换的准确性。
本说明书实施例中,上述步骤S1044的处理方式可以多种多样,以下提供一种可选的处理方式,具体可以参见以下步骤D2-D4的处理。
在步骤D2中,通过预设的编译器对源代码文件进行编译处理,并在编译处理的过程中,获取目标模型对应的中间代码。
在步骤D4中,基于预设的代码混淆策略,对中间代码进行代码混淆处理,得到包括混淆的代码的二进制文件,预设的代码混淆策略包括:指令变换处理、程序控制流扁平化处理、添加无效程序控制流分支的处理方式以及基于无效程序控制流分支添加无效代码的处理方式中的一种或多种。
其中,指令变化处理的代码混淆策略指的是,指令同义变换处理。程序控制流扁平化处理的代码混淆策略指的是隐藏程序控制流的中间路径,仅能看到程序控制流节点图中的第一个节点和末位节点,在节点图中程序控制流呈现平铺状态、平坦化状态。例如:某一节点图中包含ABDE、ACDE、ADE多个程序控制流,通过程序控制流扁平化处理后,节点图中只能看到从节点A经由黑盒子到节点E的平坦化状态的程序控制流,黑盒子中包括隐藏了中间节点的程序控制流。添加无效程序控制流分支的代码混淆策略,指的是在程序控制流路径中增加一些实际上并不执行的无效程序控制流分支,从而增加代码的复杂度,进而提升对基于该代码的二进制文件进行逆向分析难度。添加无效代码的代码混淆策略,指的是基于无效程序控制流分支添加实际上并不执行的无效代码(或称垃圾代码),也能够增加代码的复杂度,进而提升对基于该代码的二进制文件进行逆向分析难度。需要注意的是,在采用添加无效代码的代码混淆策略时,需要基于无效程序控制流分支添加无效代码,而不是基于真实程序控制流添加无效代码,以免导致所获取的二进制文件与原始的模型文件不等效。
由以上步骤D2和D4可知,本说明书实施例中不但可以在模型文件向源代码文件转换处理的过程中进行混淆处理(进行算子同义替换处理),还可以在源代码文件向二进制代码文件的转换处理过程中进行混淆处理,在实施中还可以同时在上述两个转换处理过程中进行混淆处理,通过上述混淆处理过程,能够有效提升对终端设备所获取的二进制文件进行逆向分析难度,从而提高模型文件的安全性。
图4是根据本说明书一实施例的模型文件保护方法的实现原理示意图,由图4可知,本说明书实施例的模型文件保护方法主要是在服务端执行。具体地,在服务端对待保护的模型文件首先进行模型转换处理,获取转化后的源代码文件,然后对转化后的源代码文件进行混淆、编译处理获取保护后的二进制文件,最后可以通过服务端向终端设备下发文件的方式,将保护后的二进制文件下载至终端设备。该保护后的二进制文件能够直接在终端设备上正常运行,并能够与终端设备上的其他模型引擎进行信息交互,且该保护后的二进制文件在终端设备上的运行结果与直接在终端设备上运行待保护模型文件的运行结果是等效的。
综上,已经对本主题的特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作可以按照不同的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序,以实现期望的结果。在某些实施方式中,多任务处理和并行处理可以是有利的。
以上为本说明书一个或多个实施例提供的模型文件保护方法,基于同样的思路,本说明书一个或多个实施例还提供一种模型文件保护装置,如图5所示。
该模型文件保护装置包括:模型文件获取模块210和编译模块220,其中:模型文件获取模块210,获取待保护的目标模型对应的模型文件,模型文件基于多个算子构成的模型图而构建;编译模块220,基于模型文件,通过预设的编译器对目标模型进行编译处理,得到目标模型对应的二进制文件,并将目标模型对应的二进制文件发送至终端设备,目标模型对应的二进制文件用于触发终端设备通过运行二进制文件以运行目标模型。
本说明书实施例中,编译模块220包括:源代码文件获取单元,通过对模型文件进行解析处理,将模型文件转换为目标模型对应的源代码文件;二进制文件获取单元,通过预设的编译器对源代码文件进行编译处理,得到目标模型对应的二进制文件,并将目标模型对应的二进制文件发送至终端设备。
本说明书实施例中,源代码文件获取单元的一种实现方式包括:第一TVM中间代码文件获取子单元,基于TVM编译器对模型文件进行解析处理,将模型文件转换为目标模型对应的TVM中间代码文件;第一转换处理子单元,对TVM中间代码文件中的算子进行转换处理,获取目标模型对应的源代码文件。
本说明书实施例中,源代码文件获取单元的另一种实现方式包括:第二TVM中间代码文件获取子单元,基于TVM编译器对模型文件进行解析处理,将模型文件转换为目标模型对应的TVM中间代码文件;同义替换处理子单元,对TVM中间代码文件中的算子进行同义替换处理,以对TVM中间代码文件中的算子进行更新,得到更新后的TVM中间代码文件算子;第二转换处理子单元,基于TVM编译器对更新后的TVM中间代码文件算子进行转换处理,获取目标模型对应的源代码文件。
本说明书实施例中,源代码文件获取单元的又一种实现方式包括:算子识别子单元,基于预设的算子处理规则,识别存在于模型文件中且不存在于TVM编译器中的算子,并确定所识别的算子对应的转换结果;TVM编译器更新子单元,将所识别的算子及其对应的转换结果添加至TVM编译器中,以更新TVM编译器,得到更新后的TVM编译器;解析处理子单元,基于更新后的TVM编译器对包括所识别的算子的模型文件进行解析处理,获取目标模型对应的源代码文件。
本说明书实施例中,同义替换处理子单元,按照随机设定的比例选择TVM中间代码文件中进行同义替换处理的算子,对所选择的算子进行同义替换处理,并基于所选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子;或者,按照预设的比例随机选择TVM中间代码文件中进行同义替换处理的算子,对随机选择的算子进行同义替换处理,并基于随机选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子;或者,按照随机设定的比例选择TVM中间代码文件中进行同义替换处理的算子,使所选择的算子中的每个算子从多个同义替换处理后的结果中随机匹配一个同义替换处理后的结果,并基于所选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子;或者,按照预设的比例随机选择TVM中间代码文件中进行同义替换处理的算子,使随机选择的算子中的每个算子从多个同义替换处理后的结果中随机匹配一个同义替换处理后的结果,并基于随机选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子。
本说明书实施例中,二进制文件获取单元包括:编译处理子单元,通过预设的编译器对源代码文件进行编译处理,并在编译处理的过程中,获取目标模型对应的中间代码;混淆处理子单元,基于预设的代码混淆策略,对中间代码进行代码混淆处理,得到包括混淆的代码的二进制文件,预设的代码混淆策略包括:指令变换处理、程序控制流扁平化处理、添加无效程序控制流分支的处理方式以及基于无效程序控制流分支添加无效代码的处理方式中的一种或多种。
本领域的技术人员应可理解,上述模型文件保护装置能够用来实现前文所述的模型文件保护方法,其中的细节描述应与前文方法部分描述类似,为避免繁琐,此处不另赘述。
基于同样的思路,本说明书一个或多个实施例还提供一种电子设备,如图6所示。电子设备可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上的处理器301和存储器302,存储器302中可以存储有一个或一个以上存储应用程序或数据。其中,存储器302可以是短暂存储或持久存储。存储在存储器302的应用程序可以包括一个或一个以上模块(图示未示出),每个模块可以包括对电子设备中的一系列计算机可执行指令。更进一步地,处理器301可以设置为与存储器302通信,在电子设备上执行存储器302中的一系列计算机可执行指令。电子设备还可以包括一个或一个以上电源303,一个或一个以上有线或无线网络接口304,一个或一个以上输入输出接口305,一个或一个以上键盘306。
具体在本实施例中,电子设备包括有存储器,以及一个或一个以上的程序,其中一个或者一个以上程序存储于存储器中,且一个或者一个以上程序可以包括一个或一个以上模块,且每个模块可以包括对电子设备中的一系列计算机可执行指令,且经配置以由一个或者一个以上处理器执行该一个或者一个以上程序包含用于进行以下计算机可执行指令:获取待保护的目标模型对应的模型文件,模型文件基于多个算子构成的模型图而构建;基于模型文件,通过预设的编译器对目标模型进行编译处理,得到目标模型对应的二进制文件,并将目标模型对应的二进制文件发送至终端设备,目标模型对应的二进制文件用于触发终端设备通过运行二进制文件以运行目标模型。
本说明书一个或多个实施例提供一种存储介质,存储介质用于存储计算机可执行指令,可执行指令在被处理器执行时实现以下流程:获取待保护的目标模型对应的模型文件,模型文件基于多个算子构成的模型图而构建;基于模型文件,通过预设的编译器对目标模型进行编译处理,得到目标模型对应的二进制文件,并将目标模型对应的二进制文件发送至终端设备,目标模型对应的二进制文件用于触发终端设备通过运行二进制文件以运行目标模型。
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程门阵列(Field Programmable Gate Array,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware Description Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby Hardware Description Language)等,目前最普遍使用的是VHDL(Very-High-Speed Integrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。
控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。
为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本说明书一个或多个实施例时可以把各单元的功能在同一个或多个软件和/或硬件中实现。
本领域内的技术人员应明白,本说明书一个或多个实施例可提供为方法、系统、或计算机程序产品。因此,本说明书一个或多个实施例可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本说明书一个或多个实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本说明书一个或多个实施例是参照根据本说明书实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。
本说明书一个或多个实施例可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本说明书,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
以上所述仅为本说明书一个或多个实施例而已,并不用于限制本申请。对于本领域技术人员来说,本说明书一个或多个实施例可以有各种更改和变化。凡在本说明书一个或多个实施例的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例的权利要求范围之内。
Claims (10)
- 一种模型文件保护方法,应用于服务器,所述方法包括:获取待保护的目标模型对应的模型文件,所述模型文件基于多个算子构成的模型图而构建;基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,并将所述目标模型对应的二进制文件发送至终端设备,所述目标模型对应的二进制文件用于触发终端设备通过运行所述二进制文件以运行所述目标模型。
- 根据权利要求1所述的方法,所述基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,包括:通过对所述模型文件进行解析处理,将所述模型文件转换为所述目标模型对应的源代码文件;通过预设的编译器对所述源代码文件进行编译处理,得到所述目标模型对应的二进制文件。
- 根据权利要求2所述的方法,所述通过预设的编译器对所述源代码文件进行编译处理,得到所述目标模型对应的二进制文件,包括:通过预设的编译器对所述源代码文件进行编译处理,并在编译处理的过程中,获取目标模型对应的中间代码;基于预设的代码混淆策略,对所述中间代码进行代码混淆处理,得到包括混淆的代码的所述二进制文件,所述预设的代码混淆策略包括:指令变换处理、程序控制流扁平化处理、添加无效程序控制流分支的处理方式以及基于无效程序控制流分支添加无效代码的处理方式中的一种或多种。
- 根据权利要求2所述的方法,所述预设的编译器是TVM编译器,所述通过对所述模型文件进行解析处理,将所述模型文件转换为所述目标模型对应的源代码文件,包括:基于TVM编译器对所述模型文件进行解析处理,将所述模型文件转换为目标模型对应的TVM中间代码文件;对所述TVM中间代码文件中的算子进行转换处理,获取所述目标模型对应的源代码文件。
- 根据权利要求4所述的方法,基于TVM编译器对所述模型文件进行解析处理,将所述模型文件转换为目标模型对应的TVM中间代码文件之后,所述方法还包括:对所述TVM中间代码文件中的算子进行同义替换处理,以对所述TVM中间代码文件中的算子进行更新,得到更新后的TVM中间代码文件算子;所述对所述TVM中间代码文件中的算子进行转换处理,获取所述目标模型对应的源代码文件,包括:基于TVM编译器对更新后的TVM中间代码文件算子进行转换处理,获取所述目标模型对应的源代码文件。
- 根据权利要求5所述的方法,所述对所述TVM中间代码文件中的算子进行同义替换处理,以对所述TVM中间代码文件中的算子进行更新,得到更新后的TVM中间代码文件算子,包括:按照随机设定的比例选择TVM中间代码文件中进行同义替换处理的算子,对所选择的算子进行同义替换处理,并基于所选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子;或者,按照预设的比例随机选择TVM中间代码文件中进行同义替换处理的算子,对随机选择的算子进行同义替换处理,并基于随机选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子;或者,按照随机设定的比例选择TVM中间代码文件中进行同义替换处理的算子,使所选择的算子中的每个算子从多个同义替换处理后的结果中随机匹配一个同义替换处理后的结果,并基于所选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子;或者,按照预设的比例随机选择TVM中间代码文件中进行同义替换处理的算子,使随机选择的算子中的每个算子从多个同义替换处理后的结果中随机匹配一个同义替换处理后的结果,并基于随机选择的算子和TVM中间代码文件中的其他算子,获取更新后的TVM中间代码文件算子。
- 根据权利要求2所述的方法,所述预设的编译器是TVM编译器,所述通过对所述模型文件进行解析处理,将所述模型文件转换为所述目标模型对应的源代码文件,包括:基于预设的算子处理规则,识别存在于所述模型文件中且不存在于所述TVM编译器中的算子,并确定所识别的算子对应的转换结果;将所识别的算子及其对应的转换结果添加至TVM编译器中,以更新所述TVM编译器,得到更新后的TVM编译器;基于更新后的TVM编译器对包括所识别的算子的所述模型文件进行解析处理,获取所述目标模型对应的源代码文件。
- 根据权利要求2所述的方法,所述源代码文件是基于C语言或C++语言创建的文件,所述二进制文件是基于ELF格式创建的文件。
- 一种模型文件保护装置,包括:模型文件获取模块,获取待保护的目标模型对应的模型文件,所述模型文件基于多个算子构成的模型图而构建;编译模块,基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,并将所述目标模型对应的二进制文件发送至终端设备,所述目标模型对应的二进制文件用于触发终端设备通过运行所述二进制文件以运行所述目标模型。
- 一种电子设备,包括:处理器;以及被安排成存储计算机可执行指令的存储器,在所述可执行指令被执行时,能够使得所述处理器:获取待保护的目标模型对应的模型文件,所述模型文件基于多个算子构成的模型图而构建;基于所述模型文件,通过预设的编译器对所述目标模型进行编译处理,得到所述目标模型对应的二进制文件,并将所述目标模型对应的二进制文件发送至终端设备,所述目标模型对应的二进制文件用于触发终端设备通过运行所述二进制文件以运行所述目标模型。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410384161.9A CN118194352A (zh) | 2024-03-29 | 2024-03-29 | 一种模型文件保护方法及装置 |
| CN202410384161.9 | 2024-03-29 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2025201476A1 true WO2025201476A1 (zh) | 2025-10-02 |
Family
ID=91399633
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2025/085432 Pending WO2025201476A1 (zh) | 2024-03-29 | 2025-03-27 | 模型文件保护 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN118194352A (zh) |
| WO (1) | WO2025201476A1 (zh) |
Families Citing this family (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118194352A (zh) * | 2024-03-29 | 2024-06-14 | 支付宝(杭州)信息技术有限公司 | 一种模型文件保护方法及装置 |
| CN119538268A (zh) * | 2024-11-27 | 2025-02-28 | 蚂蚁区块链科技(上海)有限公司 | 程序代码的保护方法、优化方法、设备、存储介质及产品 |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20200293309A1 (en) * | 2019-03-12 | 2020-09-17 | Northrop Grumman Systems Corporation | Diagram model for a program |
| CN114647612A (zh) * | 2020-12-21 | 2022-06-21 | 平头哥(上海)半导体技术有限公司 | 处理单元、片上系统及处理方法 |
| CN116627421A (zh) * | 2023-04-27 | 2023-08-22 | 中国人民解放军战略支援部队信息工程大学 | 基于随机混淆的多样化编译方法及系统 |
| CN116821931A (zh) * | 2023-06-27 | 2023-09-29 | 杭州博盾习言科技有限公司 | 安全多方计算的模型运算方法、装置、电子设备及介质 |
| CN118194352A (zh) * | 2024-03-29 | 2024-06-14 | 支付宝(杭州)信息技术有限公司 | 一种模型文件保护方法及装置 |
| CN118349967A (zh) * | 2024-01-29 | 2024-07-16 | 浪潮智慧科技有限公司 | 一种基于代码混淆的端侧深度学习模型保护方法及系统 |
-
2024
- 2024-03-29 CN CN202410384161.9A patent/CN118194352A/zh active Pending
-
2025
- 2025-03-27 WO PCT/CN2025/085432 patent/WO2025201476A1/zh active Pending
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20200293309A1 (en) * | 2019-03-12 | 2020-09-17 | Northrop Grumman Systems Corporation | Diagram model for a program |
| CN114647612A (zh) * | 2020-12-21 | 2022-06-21 | 平头哥(上海)半导体技术有限公司 | 处理单元、片上系统及处理方法 |
| CN116627421A (zh) * | 2023-04-27 | 2023-08-22 | 中国人民解放军战略支援部队信息工程大学 | 基于随机混淆的多样化编译方法及系统 |
| CN116821931A (zh) * | 2023-06-27 | 2023-09-29 | 杭州博盾习言科技有限公司 | 安全多方计算的模型运算方法、装置、电子设备及介质 |
| CN118349967A (zh) * | 2024-01-29 | 2024-07-16 | 浪潮智慧科技有限公司 | 一种基于代码混淆的端侧深度学习模型保护方法及系统 |
| CN118194352A (zh) * | 2024-03-29 | 2024-06-14 | 支付宝(杭州)信息技术有限公司 | 一种模型文件保护方法及装置 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN118194352A (zh) | 2024-06-14 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2025201476A1 (zh) | 模型文件保护 | |
| JP5848778B2 (ja) | Fsmを実装するための専用要素の利用 | |
| TWI502501B (zh) | 用以控制自動機之內分支度及/或外分支度之展開量化 | |
| CN110245002B (zh) | 系统交互方法、装置、设备及存储介质 | |
| US20200225921A1 (en) | Lookup table optimization for programming languages that target synchronous digital circuits | |
| CN108628947A (zh) | 一种业务规则匹配处理方法、装置及处理设备 | |
| KR102165134B1 (ko) | 상태 기계 엔진에서 상태 벡터 데이터를 사용하기 위한 방법들 및 시스템들 | |
| KR20140104991A (ko) | 상태 기계에서의 데이터 분석을 위한 방법들 및 시스템들 | |
| KR20140105005A (ko) | 상태 기계에서 라우팅하기 위한 방법들 및 시스템들 | |
| US12346442B2 (en) | System and method for computer security augmented data set algorithm training | |
| EP3912075A1 (en) | Generating synchronous digital circuits from source code constructs that map to circuit implementations | |
| US8141042B2 (en) | Extending portability of java code through the use of AOP | |
| WO2020149999A1 (en) | Generating a synchronous digital circuit from a source code construct defining a function call | |
| US9875088B2 (en) | Optimized compiling of a template function | |
| WO2025139355A1 (zh) | 代码分析 | |
| US9454382B2 (en) | Verification of UML state machines | |
| WO2025060632A1 (zh) | 代码生成方法和装置、电子设备 | |
| EP4330810A1 (en) | Code injection from natural language derived intent | |
| CN113692570B (zh) | 支持管道式数据转换的数据移动器系统 | |
| US20200004784A1 (en) | Index generation method, data retrieval method, apparatus of index generation | |
| CN111061523B (zh) | 一种软件包调用管理方法、系统、装置及存储介质 | |
| WO2020211074A1 (zh) | 一种多方安全计算数据处理方法、装置及系统 | |
| US11663334B1 (en) | System and method for computer security augmented data set algorithm training | |
| CN120122953A (zh) | 代码库封装方法、程序编译方法、装置、设备和介质 | |
| JP6211995B2 (ja) | 言語モデル作成装置、言語モデル作成方法及びプログラム |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 25775250 Country of ref document: EP Kind code of ref document: A1 |