Model file loading method and device and electronic equipment
By obtaining the target identifier in the model file loading request, determining the target data format and selecting the transmission path, and using shared memory and thread pool to process the model file, the problem of low adaptability of model file calls is solved, and the general loading and data privacy protection of model files is realized.
Patent Information
- Application Number
- CN202510442937.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-09
- Publication Date
- 2025-08-12
AI Technical Summary
In the prior art, the model file calling method causes each calling program to only call and load specific model files, which are low in adaptability and complex in operation.
By obtaining the target identifier in the model file loading request, determining the target data format, and selecting the transmission path based on the format, sending the model file to the target terminal, and using the shared memory cache and thread pool for encryption and decryption processing, ensuring data privacy and load universality.
It realizes common loading and scheduling of different model files, improves the adaptability and operation simplicity of model files, and ensures data privacy.
Smart Images

Figure CN120469732A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a model file loading method, device and electronic device. Background Art
[0002] With the development of artificial intelligence technology, large models have been further developed and applied to various industries. The core of large models is their corresponding model files, which need to be protected.
[0003] Generally speaking, you can provide access to large models through remote access via an Application Programming Interface (API), thereby preventing the exposure of the model files. Alternatively, you can provide encrypted model files for deployment in the environment where the large model is used. By encrypting the model files, you can prevent the internal structure and key parameters of the large model from being exposed, making it difficult for third parties to easily copy or learn the corresponding large model.
[0004] In related technologies, when calling the model file of a model, different calling programs need to be developed for different models. After the corresponding calling program obtains the model file of the corresponding model, the obtained model file is transmitted to the model file receiving module of the terminal to realize the loading and use of the model.
[0005] However, using the above model file calling method, because the model file corresponding to a specific model format needs to be used with a specific calling program (for example, calling program A with model file A, calling program B with model file B), each calling program can only call and load specific model files. Therefore, using the above method will result in low adaptability when calling model files and more complicated operations. Summary of the Invention
[0006] The embodiments of the present application provide a model file loading method, device and electronic device to improve the versatility and adaptability of calling and loading model files of different models.
[0007] In a first aspect, the present application provides a model file loading method, the method comprising:
[0008] Get the model file loading request, and obtain the target identifier corresponding to the target model from the loading request;
[0009] Determining a target data format corresponding to the model file to be loaded based on the target identifier and the correspondence between the candidate identifier and the data format; wherein the data format represents the type of model file that the terminal can receive;
[0010] Send the model file to be loaded to the target terminal in the target data format.
[0011] The above method avoids the technical defect in the traditional method that a model service can only load a model file of a known format corresponding to one model for transmission and storage. It can load the model files corresponding to different models, thereby improving the versatility of model file loading and scheduling.
[0012] In an optional embodiment, sending the model file to be loaded to the target terminal based on the target data format includes:
[0013] Based on the target data format, obtaining a target data transmission path corresponding to the target format setting;
[0014] The model file to be loaded is obtained through the target data transmission path, and the model file to be loaded is sent to the target terminal.
[0015] Through the above method, the corresponding target data transmission path can be selected according to the target data format of different model files, and the model file to be loaded can be obtained through the target transmission path.
[0016] In an optional embodiment, before sending the model file to be loaded to the target terminal based on the target data format, the method further includes:
[0017] Set a file lock for the model file to be loaded, and determine whether the model file to be loaded has the corresponding shared memory;
[0018] If yes, then output the first address corresponding to the model file to be loaded from the existing shared memory;
[0019] If not, create a target shared memory and store the model file to be loaded in the model data location in the target shared memory; wherein the target shared memory includes a header data location, a model data location and a tail data location, and the model data location is used to store the model file to be loaded.
[0020] Through the above method, shared memory is used to cache the model data to be loaded, so that different model files to be loaded can be saved after being obtained, and the user can accurately load the corresponding model file through shared memory.
[0021] In an optional implementation, before obtaining a model file loading request and obtaining a target identifier corresponding to a target model from the loading request, the method further includes:
[0022] Determine the length of the CPU cache line and the preset multiple;
[0023] Determine the block file size based on the length of the CPU cache line and the preset multiple;
[0024] Perform block calculation on the model file to be loaded based on the size of the block files, and determine the number of block files to be loaded;
[0025] Create a thread pool according to the number of block files to be loaded;
[0026] A thread in the thread pool is used to encrypt a block file split from the model file to be loaded.
[0027] Through the above method, the file to be encrypted can be divided into blocks, so that each block file can be encrypted, so that each block file can be encrypted without exposing too much plaintext data to the outside.
[0028] In an optional implementation, each block file is encrypted using a thread in a thread pool, including:
[0029] For each chunk file, perform the following operations:
[0030] Generate an encryption key based on a preset key factor and a random number;
[0031] The target thread in the thread pool is used to perform an encryption operation on the target block file using an encryption key to obtain the encrypted target block file.
[0032] Through the above method, each thread uses the encryption key to encrypt the corresponding block file, fully encrypting each block file and ensuring the privacy of the data.
[0033] In an optional implementation, storing the to-be-loaded model file in the model data location in the target shared memory includes:
[0034] Determine the number of block files corresponding to the model file to be loaded;
[0035] Create a thread pool according to the number of block files;
[0036] Use one thread in the thread pool to decrypt a block file corresponding to the model file to be loaded;
[0037] Store the decrypted block file in the model data location in the target shared memory.
[0038] In a second aspect, the present application provides a model file loading device, the device comprising:
[0039] The acquisition module is used to obtain a model file loading request and obtain the target identifier corresponding to the target model from the loading request;
[0040] A processing module, configured to determine a target data format corresponding to the model file to be loaded based on the target identifier and the correspondence between the candidate identifier and the data format; wherein the data format represents the type of model file that the terminal can receive;
[0041] The sending module is used to send the model file to be loaded to the target terminal in the target data format.
[0042] In an optional implementation, when sending the model file to be loaded to the target terminal based on the target data format, the sending module is specifically configured to:
[0043] Based on the target data format, obtaining a target data transmission path corresponding to the target format setting;
[0044] Obtain the model file to be loaded through the target data transmission path, and send the model file to be loaded to the target terminal.
[0045] In an optional implementation, before sending the model file to be loaded to the target terminal based on the target data format, the processing module is further configured to:
[0046] Set a file lock for the model file to be loaded, and determine whether the model file to be loaded has the corresponding shared memory;
[0047] If yes, output the first address corresponding to the model file to be loaded from the existing shared memory;
[0048] If not, create a target shared memory and store the model file to be loaded in the model data location in the target shared memory; wherein the target shared memory includes a header data location, a model data location and a tail data location, and the model data location is used to store the model file to be loaded.
[0049] In an optional embodiment, before obtaining a model file loading request and obtaining a target identifier corresponding to the target model from the loading request, the processing module is further configured to:
[0050] Determine the length of the CPU cache line and the preset multiple;
[0051] Determine the block file size based on the length of the CPU cache line and the preset multiple;
[0052] Performing block calculation on the model file to be loaded based on the size of the block files to determine the number of block files to be loaded;
[0053] Create a thread pool according to the number of block files to be loaded;
[0054] A thread in the thread pool is used to encrypt a block file split from the model file to be loaded.
[0055] In an optional implementation, when a thread in a thread pool is used to encrypt a block file split from a model file to be loaded, the processing module is specifically configured to:
[0056] For each chunk file, perform the following operations:
[0057] Generate an encryption key based on a preset key factor and a random number;
[0058] The target thread in the thread pool is used to perform an encryption operation on the target block file using an encryption key to obtain the encrypted target block file.
[0059] In an optional implementation, when storing the model file to be loaded into the model data location in the target shared memory, the processing module is specifically configured to:
[0060] Determine the number of block files corresponding to the model file to be loaded;
[0061] Create a thread pool according to the number of block files;
[0062] Use one thread in the thread pool to decrypt a block file corresponding to the model file to be loaded;
[0063] Store the decrypted block file in the model data location in the target shared memory.
[0064] In a third aspect, the present application provides an electronic device comprising a processor and a memory, wherein the memory stores program code, and when the program code is executed by the processor, the processor executes the steps of the model file loading method described in the first aspect above.
[0065] In a fourth aspect, the present application provides a computer-readable storage medium comprising a program code. When the program code is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the model file loading method described in the first aspect above.
[0066] In a fifth aspect, the present application provides a computer program product, which, when called by a computer, enables the computer to execute the steps of the model file loading method as described in the first aspect.
[0067] In addition, other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or may be understood by practicing the present application. The objectives and other advantages of the present application can be realized and obtained through the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without inventive work. In the drawings:
[0069] Figure 1 A schematic diagram of an implementation flow of a model file loading method provided in an embodiment of the present application;
[0070] Figure 2 A logical diagram for determining a model file transmission path provided in an embodiment of the present application;
[0071] Figure 3 A schematic structural diagram of a model file loading device provided in an embodiment of the present application;
[0072] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0073] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of the technical solutions of this application, but not all of them. Based on the embodiments described in this application document, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the technical solutions of this application.
[0074] It should be noted that in the description of this application, "multiple" is understood to mean "at least two." "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. A and B are connected, which can mean: A and B are directly connected, and A and B are connected through C. In addition, in the description of this application, words such as "first" and "second" are only used for the purpose of distinguishing descriptions, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying an order.
[0075] In addition, the collection, dissemination, and use of data in the technical solution of this application comply with the requirements of relevant national laws and regulations.
[0076] The following is a brief introduction to the design concept of the embodiment of this application:
[0077] With the development of artificial intelligence technology, large models have been further developed and applied in various industries. The core part of large models is their corresponding model files, which need to be protected.
[0078] Generally speaking, you can provide access to large models by providing an API, thereby preventing the model files from being exposed, or by providing encrypted model files for deployment in the environment where the large model is used. By encrypting the model files, the internal structure and key parameters of the large model are not exposed, making it difficult for third parties to easily copy or learn the corresponding large model.
[0079] In related technologies, when calling the model file of a model, different calling programs need to be developed for different models. After the corresponding calling program obtains the model file of the corresponding model, the obtained model file is transmitted to the model file receiving module of the terminal to realize the loading and use of the model.
[0080] However, using the above model file calling method, because the model file corresponding to a specific model needs to be used with a specific calling program (for example, calling program A with model file A, calling program B with model file B), each calling program can only call and load specific model files. Therefore, using this method will result in low adaptability when calling model files and more complicated operations.
[0081] In view of this, the present application provides a model file loading method. Specifically, the method includes: first, obtaining a model file loading request, and obtaining a target identifier corresponding to the target model from the loading request; then, based on the target identifier and the correspondence between the candidate identifier and the data format, determining the target data format corresponding to the model file to be loaded; wherein the data format represents the type of model file that the terminal can receive; finally, sending the model file to be loaded to the target terminal through the target data format. Through the above method, the technical defect of the traditional method that a model service can only load a model file of a known format for transmission and storage is avoided, and different model files corresponding to different models can be transmitted, thereby improving the versatility of model file scheduling or loading.
[0082] The following describes a model file loading method provided by an exemplary embodiment of the present application with reference to the accompanying drawings.
[0083] For further information, see Figure 1 FIG. 1 is a schematic diagram of an implementation process of a model file loading method provided in an embodiment of the present application. The specific implementation process of the method is as follows:
[0084] S101: Obtain a model file loading request, and obtain a target identifier corresponding to a target model from the loading request.
[0085] In an embodiment of the present application, when a load request for loading a corresponding model file is received, the target identifier corresponding to the target model can be parsed from the load request. The target data format of the model file to be loaded corresponding to the target model can be determined through the target identifier.
[0086] In particular, the server can receive model file loading requests corresponding to multiple terminals; then, after obtaining the model file loading requests corresponding to each terminal, the server can obtain the target identifier corresponding to the target model contained in each model file loading request. Taking three terminals as an example, the model file loading requests and target identifiers corresponding to the target models sent by each terminal are shown in Table 1:
[0087] Table 1
[0088] Terminal 1 Terminal 2 Terminal 3 Load Request 1 Loading Request 2 Loading Request 3 Target ID 1 Target ID 2 Target ID 3
[0089] As can be seen from the table above, the server can obtain the target identifier of each target model from the model file loading request sent by each terminal. For example, taking terminal 1 as an example, after receiving model file loading request 1 from terminal 1, the server can parse model file loading request 1 to obtain the target identifier 1 corresponding to the target model.
[0090] S102: Based on the target identifier and the correspondence between the candidate identifier and the data format, determine the target data format corresponding to the model file to be loaded.
[0091] In the embodiment of the present application, the data format represents the model file type that the terminal can receive.
[0092] In an optional implementation, when executing step S102 , after obtaining the target identifier corresponding to the target model, the target data format corresponding to the model file to be loaded may be determined based on the correspondence between the candidate identifier interval and the data format.
[0093] Specifically, after obtaining the target identifier, the target identifier type interval to which the target identifier belongs may be determined.
[0094] For example, assuming that the target model identifier can be divided into the first interval, the second interval, and the third interval according to the identifier type, then, taking three target models with three different candidate identifier intervals as an example, the candidate identifiers and candidate identifier intervals corresponding to each target model are shown in Table 2:
[0095] Table 2
[0096] Model 1 Model 2 Model 3 Candidate ID 1 Candidate ID 2 Candidate ID 3 First interval Second interval The third interval
[0097] As can be seen from the above table, the server can determine the candidate identifier interval to which the candidate identifier of the corresponding model belongs based on the identifier of the model. For example, taking model 1 as an example, the server can determine that candidate identifier 1 belongs to the first interval based on candidate identifier 1 of model 1.
[0098] Furthermore, after determining the target identification interval to which the target identification of the target model belongs, the target data format corresponding to the model file to be loaded by the target model may be determined based on the correspondence between the candidate identification type interval and the data format.
[0099] For example, different candidate identifiers may correspond to encrypted or unencrypted model files. For example, if candidate identifier 1 corresponds to an encrypted model file, then if model 1 corresponds to candidate identifier 1, then the model file corresponding to model 1 is an encrypted model file. The candidate identifier can be used to determine the encryption format corresponding to the model file to be loaded. Subsequently, when loading the file to be loaded, the encrypted model file must be decrypted according to the model file path of the model file to be loaded before it can be transmitted.
[0100] S103: Send the model file to be loaded to the target terminal in the target data format.
[0101] In an optional implementation, before sending the model file to be loaded to the target terminal in the target data format, it is also necessary to set a file lock on the model file to be loaded and determine whether the model file to be loaded has a corresponding shared memory.
[0102] Specifically, setting a file lock for the model file to be loaded can enable the target process to load the model file to be loaded, that is, using one process to load the model file to be loaded, preventing multiple processes from loading the same model file to be loaded at the same time, thereby ensuring the consistency and integrity of the data. In addition, it is determined whether the model file to be loaded has a corresponding shared memory. If so, it means that the model file to be loaded already exists in the shared memory, and the model data corresponding to the model file to be loaded or the first address corresponding to the model data can be directly output from the shared memory. If the model file to be loaded does not have a corresponding shared memory, a corresponding target shared memory is created for the model file to be loaded, and the target shared memory is used to save the model file to be loaded. In an embodiment of the present application, the target shared memory includes a header data position, a model data position, and a tail data position, wherein the model data position is used to store the model file to be loaded. After the shared memory is created, the header length and tail length of the shared memory can be randomly filled so that the first address in the shared memory is not the first address of the model data, which is convenient for hiding the true first address of the model file.
[0103] When setting the header length and tail length of the shared memory, a random number generator is used to randomly generate the header length and tail length. The value indicates that when generating the header length and tail length, the header length and tail length do not exceed the preset size, and the generated header length and tail length of the shared memory are saved to a preset designated file, so that the model file to be loaded can be accurately read according to the header length and tail length of the shared memory.
[0104] In an optional embodiment, before receiving a model file load request and obtaining the target identifier corresponding to the target model from the load request, it is further necessary to determine the number of sub-files of the file to be encrypted. That is, before deploying the target model to the runtime environment, it may be necessary to encrypt the model file corresponding to the target model to prevent the model file from exposing plaintext data.
[0105] Specifically, first, determine the length of the CPU cache line and the preset multiple. It should be noted that in the embodiment of the present application, the length of the CPU cache line is the minimum unit of data stored in the CPU cache, such as 128 bytes. That is, when the CPU processes data, the size of the data block that can be read or written from the cache at one time. Some third-party tools or related query instructions can be used to obtain the performance parameters of the CPU, which may include the length of the CPU cache line. In addition, the preset multiple can be set according to actual needs, for example, set to 2 times, 4 times, etc.
[0106] Furthermore, after determining the length of the CPU cache line and the preset multiple, the size of each block file can be determined. Then, based on the block file size, block calculation is performed on the model file to be loaded, thereby determining the number of block files to be loaded.
[0107] For example, in the embodiment of the present application, the size of each block file can be obtained by multiplying the length of the CPU cache line by a preset multiple. For example, if the length of the CPU cache line is 128 bytes and the preset multiple is 8, the size of the block file is 128×8=1024 bytes.
[0108] After determining the size of the block files, the block calculation can be performed on the file to be encrypted in the file path, thereby determining the number of block files of the file to be encrypted.
[0109] For example, if the size of the file to be encrypted determined according to the file path is 1024 bytes, then the file to be encrypted may be divided into 10 block files according to the size of each block file.
[0110] After determining the number of block files to be loaded, a thread pool can be created according to the number of block files to be loaded. A thread pool with a corresponding number of threads is created based on the number of block files.
[0111] For example, assuming that a block operation is currently performed on a file to be encrypted to obtain 8 block files, a thread pool with 8 threads is created accordingly, wherein each block file is associated with a corresponding thread, as shown in Table 3:
[0112] Table 3
[0113]
[0114] Based on the above table, we can see that thread 1 corresponds to block file 1, and thread 2 corresponds to block file 2. Each thread can process a block file in a targeted manner, thereby fully utilizing the processing performance of the CPU and ensuring that each block file can be fully encrypted.
[0115] In an embodiment of the present application, a cacheable thread pool can be created when creating a thread pool. If the number of threads exceeds the number required to process the block files, the threads can be recycled after a period of caching. If the number of threads is insufficient, new threads can be created. In addition, a fixed-size thread pool can be created to control the number of concurrent threads.
[0116] In the embodiments of the present application, the specific method of creating a thread pool is not limited. In actual applications, a suitable thread pool creation method can be selected according to needs.
[0117] A thread in the thread pool is used to encrypt each block file split from the model file to be loaded. Specifically, a preset key factor is first obtained from a preset configuration file, and a random number is generated using a random number generator. Then, the preset key factor and random number are used to generate a corresponding encryption key. When generating the encryption key, a mathematical operation such as multiplication or modular operation can be performed on the preset key factor and random number. A hash operation can also be used to process the preset key factor and random number to obtain the encryption key.
[0118] Further, each thread in the thread pool uses the obtained encryption key to encrypt the corresponding block file to obtain the encrypted block file. After the encryption is completed, the generated random number also needs to be saved in the description file for use during decryption. The description file can also save information such as the file name of the encrypted block file. For example, block file 1 and block file 2, these file names are saved in the description file, indicating that these block files have been encrypted. After the encryption is completed, the random number used for encryption also needs to be output to the preset description file for use during decryption. In the preset description file, the file name and model file path of the encrypted block file output can also be saved.
[0119] When encrypting a block file, each thread obtains the address of a block file and, based on the block file's address, retrieves the corresponding block file. For example, if thread 1 obtains file address 1, thread 1 can obtain block file 1. Thread 1 can then encrypt block 1 using the encryption key, obtaining the encrypted block file 1.
[0120] In an optional embodiment, when the server obtains the target data format corresponding to the model file to be loaded, it can select a target data transmission path set corresponding to the target data format. Then, through the target transmission path, the server obtains the model file to be loaded and sends the model file to be loaded to the target terminal.
[0121] For example, see Figure 2 As shown, each different target model corresponds to a model file to be loaded in a different target data format, and the server can obtain the model file to be loaded based on the target transmission path set corresponding to the different target data formats. For example, model file 1 to be loaded is the model file corresponding to model 1, model file 2 to be loaded is the model file corresponding to model 2, and model file 3 to be loaded is the model file corresponding to model 3. Data transmission path 1 is set for model file 1 to be loaded, data transmission path 2 is set for model file 2 to be loaded, and data transmission path 3 is set for model file 3 to be loaded. Next, for example, the server can obtain model file 1 to be loaded through data transmission path 1 or obtain model file 2 to be loaded through data transmission path 2, and store the obtained model file to be loaded in the shared memory set in the model service. Furthermore, the server can obtain the model file to be loaded from the shared memory in the model service, and send the model file to be loaded to the target terminal after unlocking the file lock operation.
[0122] Furthermore, when the model file to be loaded is stored in the model data position in the target shared memory, the encrypted block file needs to be decrypted according to the encryption format of the model file to be loaded, and the decrypted block file needs to be stored in the model data position in the target shared memory. Specifically, when decrypting the block file, it is also necessary to determine the size of the encrypted block file based on the length of the CPU cache line and the preset multiple, and then determine the number of the encrypted block files. In order to create a thread pool based on the number of encrypted block files, the number of threads in the thread pool can be greater than or equal to the number of encrypted block files. Furthermore, the threads in the thread pool can be used to decrypt the encrypted block files.
[0123] Similarly, during decryption, one thread corresponds to one encrypted block file, for example, thread 1 corresponds to block file 1, and thread 2 corresponds to block file 2. When each thread obtains the address of the block file to be encrypted, it obtains the random number and key factor used for encryption from the encrypted output description file, and thus obtains the decryption key based on the random number and key factor. The thread uses the decryption key to decrypt the encrypted block file and then saves the decrypted block file to the model data location in the target shared memory.
[0124] In an embodiment of the present application, after successfully loading the model file, it is also necessary to determine whether the loaded model file is a model file that was encrypted when the model was deployed. If it is an encrypted model file, it is also necessary to disassociate the target shared memory from the target process. After exceeding the preset time, the data in the target shared memory is deleted to release the model file.
[0125] Through the above method, one model service can be used to load the model files corresponding to different models through different data transmission paths, avoiding the problem of setting up model services for different models to read the model files corresponding to different models. The model files to be loaded are cached in shared memory through different transmission paths, and the model files are transmitted externally through shared memory, thereby improving the versatility of model file loading.
[0126] Furthermore, based on the same technical concept, the embodiment of the present application provides a model file loading device, which is used to implement the above-mentioned model file loading method process of the embodiment of the present application. Figure 3 As shown, the device includes: an acquisition module 301, a processing module 302 and a sending module 303, wherein:
[0127] The acquisition module 301 is used to obtain a model file loading request and obtain a target identifier corresponding to the target model from the loading request;
[0128] Processing module 302, for determining a target data format corresponding to the model file to be loaded based on the target identifier and the correspondence between the candidate identifier and the data format; wherein the data format represents the type of model file that the terminal can receive;
[0129] The sending module 303 is used to send the model file to be loaded to the target terminal in the target data format.
[0130] In an optional implementation, when the model file to be loaded is sent to the target terminal based on the target data format, the sending module 303 is specifically configured to:
[0131] Based on the target data format, obtaining a target data transmission path corresponding to the target format setting;
[0132] Obtain the model file to be loaded through the target data transmission path, and send the model file to be loaded to the target terminal.
[0133] In an optional implementation, before sending the to-be-loaded model file to the target terminal based on the target data format, the processing module 302 is further configured to:
[0134] Set a file lock for the model file to be loaded, and determine whether the model file to be loaded has the corresponding shared memory;
[0135] If yes, output the first address corresponding to the model file to be loaded from the existing shared memory;
[0136] If not, create a target shared memory and store the model file to be loaded in the model data location in the target shared memory; wherein the target shared memory includes a header data location, a model data location and a tail data location, and the model data location is used to store the model file to be loaded.
[0137] In an optional implementation, before obtaining a model file loading request and obtaining a target identifier corresponding to a target model from the loading request, the processing module 302 is further configured to:
[0138] Determine the length of the CPU cache line and the preset multiple;
[0139] Determine the block file size based on the length of the CPU cache line and the preset multiple;
[0140] Performing block calculation on the model file to be loaded based on the size of the block files to determine the number of block files to be loaded;
[0141] Create a thread pool according to the number of block files to be loaded;
[0142] A thread in the thread pool is used to encrypt a block file split from the model file to be loaded.
[0143] In an optional implementation, when a thread in the thread pool is used to encrypt a block file split from the model file to be loaded, the processing module 302 is specifically configured to:
[0144] For each chunk file, perform the following operations:
[0145] Generate an encryption key based on a preset key factor and a random number;
[0146] The target thread in the thread pool is used to perform an encryption operation on the target block file using an encryption key to obtain the encrypted target block file.
[0147] In an optional implementation, when storing the model file to be loaded into the model data location in the target shared memory, the processing module 302 is specifically configured to:
[0148] Determine the number of block files corresponding to the model file to be loaded;
[0149] Create a thread pool according to the number of block files;
[0150] Use one thread in the thread pool to decrypt a block file corresponding to the model file to be loaded;
[0151] Store the decrypted block file in the model data location in the target shared memory.
[0152] Based on the same technical concept, the embodiment of the present application also provides an electronic device, which can implement the model file loading method provided in the above embodiment of the present application. In one embodiment, the electronic device can be a server, or a terminal device or other electronic device. Figure 4 As shown, the electronic device may include:
[0153] At least one processor 401, and a memory 402 connected to the at least one processor 401. The specific connection medium between the processor 401 and the memory 402 is not limited in the embodiment of the present application. Figure 4 In the example, the processor 401 and the memory 402 are connected via a bus 400. Figure 4 The bus 400 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4The diagram is represented by only one thick line, but this does not mean that there is only one bus or one type of bus. Alternatively, the processor 401 may also be referred to as a controller, without limitation to the name.
[0154] In the embodiment of the present application, the memory 402 stores instructions that can be executed by at least one processor 401. At least one processor 401 can execute a model file loading method discussed above by executing the instructions stored in the memory 402. The processor 501 can implement Figure 3 The functions of each module in the device shown.
[0155] Among them, the processor 401 is the control center of the device, which can use various interfaces and lines to connect the various parts of the entire control device, and monitor the device as a whole by running or executing instructions stored in the memory 402 and calling data stored in the memory 402, the various functions of the device and processing data.
[0156] In one possible design, processor 401 may include one or more processing units. Processor 401 may integrate an application processor and a modem processor. The application processor primarily processes the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 401. In some embodiments, processor 401 and memory 402 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.
[0157] The processor 401 can be a general-purpose processor, such as a CPU, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the model file loading method disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.
[0158] The memory 402 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 402 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 402 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 402 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0159] By designing and programming the processor 401, the code corresponding to the model file loading method described in the above embodiment can be fixed into the chip, so that the chip can execute the code when running. Figure 1 The steps of a model file loading method in the embodiment shown are as follows: How to design and program the processor 401 is a technique well known to those skilled in the art and will not be described in detail here.
[0160] Based on the same inventive concept, an embodiment of the present application further provides a storage medium storing computer instructions. When the computer instructions are executed on a computer, the computer executes a model file loading method discussed above.
[0161] In some possible implementations, the present application also provides various aspects of a model file loading method that can also be implemented in the form of a program product, which includes program code. When the program product is run on the device, the program code is used to enable the control device to execute the steps of a model file loading method according to various exemplary implementations of the present application described above in this specification.
[0162] It should be noted that although several units or subunits of the device are mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, depending on the embodiment of the application, the features and functions of two or more units described above can be embodied in a single unit. Conversely, the features and functions of a single unit described above can be further divided and embodied by multiple units.
[0163] Furthermore, although the operations of the method of the present application are described in a particular order in the accompanying drawings, this does not require or imply that the operations must be performed in this particular order, or that all illustrated operations must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0164] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0165] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. 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 generate a server, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0166] The program code used to perform the operations of the present application may be written using any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's device, as a stand-alone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0167] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0168] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.
Claims
1. A model file loading method, characterized in that: The method comprises: Obtain a model file loading request, and obtain a target identifier corresponding to the target model from the loading request; Determining a target data format corresponding to the model file to be loaded based on the target identifier and the correspondence between the candidate identifier and the data format; wherein the data format represents the type of model file that the terminal can receive; The model file to be loaded is sent to the target terminal in the target data format.
2. The method according to claim 1, wherein The sending the to-be-loaded model file to the target terminal based on the target data format includes: Based on the target data format, obtaining a target data transmission path set corresponding to the target format; The model file to be loaded is obtained through the target data transmission path, and the model file to be loaded is sent to the target terminal.
3. The method according to claim 1, wherein Before sending the model file to be loaded to the target terminal based on the target data format, the method further includes: Setting a file lock for the model file to be loaded, and determining whether the model file to be loaded has a corresponding shared memory; If yes, output the first address corresponding to the model file to be loaded from the existing shared memory; If not, create a target shared memory and store the model file to be loaded in the model data position in the target shared memory; wherein the target shared memory includes a header data position, a model data position and a tail data position, and the model data position is used to store the model file to be loaded.
4. The method according to claim 1, wherein Before obtaining the model file loading request and obtaining the target identifier corresponding to the target model from the loading request, the method further includes: Determine the length of the CPU cache line and the preset multiple; Determine the size of the block file according to the length of the CPU cache line and a preset multiple; Performing block calculation on the model files to be loaded based on the sizes of the block files to determine the number of the model files to be loaded; Create a thread pool according to the determined number of model files to be loaded; A thread in the thread pool is respectively used to encrypt a block file split from the model file to be loaded.
5. The method according to claim 4, wherein The step of respectively using a thread in the thread pool to encrypt a block file split from the model file to be loaded comprises: For each chunk file, perform the following operations: Generate an encryption key based on a preset key factor and a random number; The target thread in the thread pool uses the encryption key to perform an encryption operation on the target block file to obtain the encrypted target block file.
6. The method according to any one of claims 3 to 5, wherein: The step of storing the to-be-loaded model file in the model data location in the target shared memory includes: Determine the number of block files corresponding to the model file to be loaded; Create a thread pool according to the number of block files; Decrypting a block file corresponding to the model file to be loaded by respectively using a thread in the thread pool; The decrypted block files are stored in the model data location in the target shared memory.
7. A model file loading device, characterized in that: The device comprises: An acquisition module is used to obtain a model file loading request and obtain a target identifier corresponding to a target model from the loading request; A processing module, configured to determine a target data format corresponding to the model file to be loaded based on the target identifier and the correspondence between the candidate identifier and the data format; wherein the data format represents the type of model file that the terminal can receive; The sending module is used to send the model file to be loaded to the target terminal through the target data format.
8. The device according to claim 7, wherein When sending the model file to be loaded to the target terminal based on the target data format, the sending module is specifically configured to: Based on the target data format, obtaining a target data transmission path set corresponding to the target format; The model file to be loaded is obtained through the target data transmission path, and the model file to be loaded is sent to the target terminal.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.