End-side model download method, apparatus, electronic device and storage medium
By generating a candidate download source queue and implementing a breakpoint resume mechanism, the problems of weak region awareness and opaque progress feedback in edge model download are solved, achieving an efficient and stable model download process.
Patent Information
- Application Number
- CN202611496744.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-23
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, the process of downloading models on the device side suffers from weak area awareness, low breakpoint recovery efficiency, and opaque progress feedback, resulting in low download efficiency and poor user experience.
By receiving model preparation request data, obtaining regional preference information and regional priority, generating a candidate download source queue, sorting multiple sources, and using the number of downloaded bytes in the local temporary file to resume interrupted downloads, the download progress data is pushed in real time.
It achieves efficient download recovery in complex network environments, improves download stability and observability, reduces resource consumption, and enhances user experience.
Smart Images

Figure CN123123336A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data download technology for smart terminal devices, specifically to a method, apparatus, electronic device, and storage medium for downloading terminal-side models. Background Technology
[0002] With the widespread application of edge artificial intelligence (AI) models, the demand for deploying and updating large model files on AI-enabled smart devices such as mobile terminals is increasing. The process of downloading model files often faces challenges such as complex network environments and limited device resources.
[0003] In existing technologies, model download functionality is often directly integrated into the calling application or model service, forming a monolithic implementation. Alternatively, it relies solely on standard network protocols (such as regular HTTP) and the system's default background task mechanism for downloading.
[0004] The existing methods described above have significant technical drawbacks: First, the download logic is highly coupled with business logic, resulting in blurred permission boundaries. Upgrades or anomalies in the download module can directly impact the functionality and stability of the main application. Second, existing solutions lack the ability to perceive network regional differences, making it difficult to intelligently select the optimal download source from multiple alternatives based on the device's network environment or user configuration. This leads to inefficient downloads or even failures in specific regions or network environments. Third, when downloads are interrupted due to network fluctuations or system reclaiming of processes, existing solutions typically struggle to efficiently resume from the breakpoint, potentially requiring a complete re-download of the entire content, resulting in wasted bandwidth and time. Finally, the download process status is opaque to the caller, who cannot reliably obtain crucial information such as download progress, speed, and reasons for failure in real time, impacting user experience and system observability.
[0005] Therefore, there is an urgent need for an edge-side model download solution that can unify and integrate area awareness, multi-source selection, breakpoint resume, and progress feedback. Summary of the Invention
[0006] In view of the aforementioned problems, this application is proposed to provide an end-side model download method, apparatus, electronic device, and storage medium that overcomes or at least partially solves the aforementioned problems, comprising: A method for downloading edge-side models, comprising: Receive model preparation request data sent by the caller, wherein the model preparation request data includes a model identifier; Read model configuration data based on the model identifier. The model configuration data includes multiple download sources and the regional priority of each download source. Obtain the current device's region preference information, sort each download source based on the region preference information and the region priority, and generate a candidate download source queue; Check if the local official model file corresponding to the model preparation request data exists and is complete; If the local official model file exists but is incomplete, then check if a local temporary file corresponding to the local official model file exists in the model cache directory; If the local temporary file exists in the model cache directory, a resume request is sent to the first download source in the candidate download source queue based on the number of bytes already downloaded from the local temporary file. The file data returned by the first download source is appended to the local temporary file, and the download progress data is calculated based on the number of bytes written to the local temporary file and the total number of bytes in the file. The download progress data is converted into streaming status events and continuously pushed to the caller.
[0007] Further, the step of obtaining the current device's regional preference information, and sorting each download source based on the regional preference information and the regional priority to generate a candidate download source queue includes: Obtain the network region identifier of the current device, and / or the region preference parameters corresponding to the user configuration information of the current device; The network region identifier and / or the region preference parameter shall be used as the region preference information; The region preference information is matched with the region priority to obtain the matching degree corresponding to each download source; The download sources are sorted in descending order of matching degree to obtain the candidate download source queue.
[0008] Further, the step of sending a resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded from the local temporary file includes: Read the current file length of the local temporary file as the number of bytes downloaded; The interrupted resume request is sent to the first download source. The interrupted resume request includes an HTTP request header, which carries a Range field. The starting byte position of the Range field is set to the number of bytes already downloaded, so that the first download source starts returning file data from the starting byte position.
[0009] Furthermore, after checking whether the local official model file corresponding to the model preparation request data exists and is complete, the process further includes: If the local official model file does not exist, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file; If the local official model file exists and is complete, then the local official file is read, the corresponding status event is generated, and pushed to the caller.
[0010] Furthermore, after querying whether a local temporary file corresponding to the local official model file exists in the model cache directory, the process also includes: If the local temporary file does not exist in the model cache directory, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file.
[0011] Furthermore, before appending the file data returned by the first download source to the local temporary file and calculating the download progress data based on the number of bytes written to the local temporary file and the total number of bytes in the file, the method further includes: If the download from the first download source fails, the reason for the failure is recorded, the next download source after the first download source is selected from the candidate download source queue as the target download source, and the breakpoint resume request is resent to the target download source.
[0012] Furthermore, the step of converting the download progress data into streaming status events and continuously pushing them to the caller includes: The download progress data is encapsulated into the streaming status event; The streaming status events are pushed to the caller in real time through a long connection channel that associates the caller with the model's prepared request data.
[0013] An end-side model download device, comprising: The request receiving module is used to receive model preparation request data sent by the caller, wherein the model preparation request data includes a model identifier; The data reading module is used to read model configuration data according to the model identifier, wherein the model configuration data includes multiple download sources and the regional priority of each download source; The queue generation module is used to obtain the current device's regional preference information, sort each download source based on the regional preference information and the regional priority, and generate a candidate download source queue. The file inspection module is used to check whether the local formal model file corresponding to the model preparation request data exists and is complete. The directory query module is used to query whether a local temporary file corresponding to the local official model file exists in the model cache directory if the local official model file exists but is incomplete. The request sending module is used to send a breakpoint resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded of the local temporary file if the local temporary file exists in the model cache directory. The data calculation module is used to append the file data returned by the first download source to the local temporary file, and calculate the download progress data based on the number of bytes written to the local temporary file and the total number of bytes in the file; The event push module is used to convert the download progress data into streaming status events and continuously push them to the caller.
[0014] A computer electronic device includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the end-side model download method as described above.
[0015] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the end-side model download method as described above.
[0016] This application has the following advantages: In the embodiments of this application, in view of the problems of "weak awareness of the download region on the device side, low efficiency of breakpoint recovery, and opaque progress feedback" in the prior art, this application provides a solution, specifically: "receiving model preparation request data sent by the caller, the model preparation request data including a model identifier; reading model configuration data according to the model identifier, the model configuration data including multiple download sources and the regional priority of each download source; obtaining the regional preference information of the current device, sorting each download source based on the regional preference information and the regional priority, and generating a candidate download source queue; checking the local official file corresponding to the model preparation request data." The system checks whether the model file exists and is complete. If the local official model file exists but is incomplete, it queries whether a local temporary file corresponding to the local official model file exists in the model cache directory. If the local temporary file exists in the model cache directory, it sends a resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded from the local temporary file. The file data returned by the first download source is appended to the local temporary file, and the download progress data is calculated based on the number of bytes already written to the local temporary file and the total number of bytes in the file. The download progress data is converted into a streaming status event and continuously pushed to the caller. This application generates a candidate download source queue by sorting multiple download sources based on regional preference information and regional priority, and combines steps such as checking the local file status, querying the local temporary file, and sending a resume request to construct a collaborative technical closed loop. This method intelligently sorts and selects the most suitable download source, solving the problem of weak region awareness in existing technologies. By constructing a resume request based on the number of bytes already downloaded from a local temporary file, it achieves efficient recovery after download task interruption, avoiding duplicate downloads. By converting real-time calculated download progress data into streaming status events and continuously pushing them, the caller can transparently and in real-time observe the download process. Therefore, the technical solution of this application comprehensively improves the stability, efficiency, and observability of edge-side model downloads. Attached Figure Description
[0017] To more clearly illustrate the technical solution of this application, the drawings used in the description of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a flowchart illustrating the steps of a terminal-side model download method according to an embodiment of this application; Figure 2 This is a structural block diagram of an end-side model downloading device provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a computer electronic device provided in an embodiment of the present invention; 1. A computer electronic device; 2. An external device; 3. A processing unit; 4. A bus; 5. A network adapter; 6. An I / O interface; 7. A display; 8. Memory; 9. Random access memory; 10. A cache memory; 11. A storage system; 12. A program / utility; 13. A program module. Detailed Implementation
[0019] To make the objectives, features, and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0020] This application's embodiments can be applied to scenarios involving the download and update of edge models on AI smart devices. AI smart devices include, but are not limited to, AI smart cash registers, AI smart cash register tablets, AI smart POS machines, AI smartphones, AI smart handheld terminals, AI tablets, and other smart terminals equipped with local models, AI agents, or system capability gateways. These devices typically run resource-constrained mobile operating systems, resulting in large edge model files. The download process is easily affected by factors such as network regional differences, weak network fluctuations, and background processes being reclaimed by the system. The method provided in this application's embodiments can be executed collaboratively by the edge model ensure coordinator and the foreground download task, completing a complete closed loop of download source sorting, breakpoint resumption, and streaming progress push during the model preparation (ensure) process.
[0021] It should be noted that, for ease of understanding of the technical solution of this application, the following explanations are provided for the key terms involved in the embodiments of this application: Model preparation request data (ensure request data): The structured data carried in a model preparation request initiated by the model ensure coordinator on the calling side, used to trigger the complete preparation process of the model from inspection, download to loading or warm-up.
[0022] Candidate download source queue: A list of download sources arranged from high to low priority, formed after matching and sorting multiple alternative download addresses for the same model file based on regional preference information.
[0023] Local official model file: A model file that has been downloaded and passed integrity verification, and is stored in the device's local storage space with an official file name, which can be directly loaded when the model runs.
[0024] Local temporary files: Intermediate files used to store partially received file data during the download process. They are usually stored in the model cache directory and will only be atomically replaced with the local official model file after the download is complete and passes verification.
[0025] Streaming status events: Structured event data continuously pushed to the caller in a streaming manner, used to describe the status changes at each stage of the model preparation process, and may include fields such as download stage, progress, speed, and source.
[0026] Region preference information: Information used to characterize the network region where the current device is located or the user's preferences, which may come from the device's network region identifier or the region preference parameters in the user configuration information.
[0027] Resume download request: A network request based on the HTTP Range mechanism that requires the server to return file data starting from a specified byte position, used to continue downloading based on existing file data.
[0028] Reference Figure 1 This application illustrates an embodiment of a terminal model download method, specifically including: S101. Receive model preparation request data sent by the caller, wherein the model preparation request data includes a model identifier; S102. Read model configuration data according to the model identifier, wherein the model configuration data includes multiple download sources and the regional priority of each download source; S103. Obtain the current device's region preference information, sort each download source based on the region preference information and the region priority, and generate a candidate download source queue; S104. Check if the local formal model file corresponding to the model preparation request data exists and is complete; S105. If the local formal model file exists but is incomplete, then query the model cache directory to see if there is a local temporary file corresponding to the local formal model file. S106. If the local temporary file exists in the model cache directory, then based on the number of bytes downloaded from the local temporary file, send a resume request to the first download source in the candidate download source queue. S107. The file data returned by the first download source is appended to the local temporary file, and the download progress data is calculated based on the number of bytes written to the local temporary file and the total number of bytes in the file. S108. Convert the download progress data into a streaming status event and continuously push it to the caller.
[0029] In the embodiments of this application, the above steps work together to form a complete closed loop for model file preparation. In step S101, after receiving the model preparation request data carrying the model identifier initiated by the caller, the end-side model ensure coordinator does not directly bind to a fixed download source. Instead, it first obtains multiple download sources corresponding to the same model and their respective regional priorities in step S102, and then sorts these download sources based on the current device's regional preference information in step S103, ensuring that the download source most suitable for the current network environment is at the head of the candidate download source queue. Subsequently, the coordinator performs a two-level check on the local file status in steps S104 and S105—first determining whether the local formal model file exists and is complete, and then, if incomplete, determining whether there is a reusable local temporary file in the model cache directory—thus avoiding unnecessary full downloads. When a local temporary file exists, step S106 constructs a resume request based on the number of bytes already downloaded, continuing the download from the breakpoint; step S107 appends the returned file data and calculates the download progress data in real time; step S108 converts the download progress data into a streaming status event and continuously pushes it to the caller, enabling the caller to have transparent observation capabilities of the entire download process. Steps S101 to S108 unify region-aware multi-source selection, HTTP Range resume, and foreground task progress bridging into a single model ensure flow, solving the technical problems of weak region awareness, low breakpoint recovery efficiency, and opaque progress feedback during the client-side model download process.
[0030] Taking a specific application scenario as an example, the above solution can be clearly demonstrated when downloading large-volume edge model files hosted by HuggingFace in a domestic network environment. The caller (e.g., an application running on an AI smart POS machine) sends model preparation request data to the edge model ensure coordinator, which carries the model identifier to be prepared (step S101). The ensure coordinator reads the model configuration data corresponding to the model identifier, which contains the download addresses and regional priorities of both the official HuggingFace source and several domestic mirror sources (step S102). Subsequently, the ensure coordinator obtains the network region identifier of the current device or the regional preference parameter in the user configuration information, matches this information with the regional priority of each download source, and ranks domestic mirror sources first and official sources second according to the matching degree, forming a candidate download source queue (step S103). When checking the local official model file, if the file is found to exist but incomplete, the model cache directory is further queried to confirm the existence of local temporary files left over from the previous download interruption (steps S104, S105). Based on the number of bytes downloaded from the local temporary file, the ensure coordinator or the foreground download task sends a resume request with a Range field to the top-ranked mirror source (step S106), appends the returned file data to the local temporary file, and continuously calculates the download progress data (step S107). Finally, it pushes the download stage, progress, speed, and source to the caller in real time as a streaming status event (step S108). If the mirror source fails during the download, the ensure coordinator can automatically switch to the official source in the queue and continue downloading from the current length of the temporary file, without any manual intervention from the user.
[0031] This application's embodiments generate a candidate download source queue by sorting multiple download sources based on regional preference information and regional priority. Combined with steps such as checking local file status, querying local temporary files, and sending breakpoint resume requests, a collaborative technical closed loop is constructed. This method intelligently sorts and selects the most suitable download source, solving the problem of weak regional awareness in existing technologies. By utilizing the number of bytes already downloaded from local temporary files to construct breakpoint resume requests, efficient recovery after download task interruption is achieved, avoiding duplicate downloads. By converting real-time calculated download progress data into streaming status events and continuously pushing them, the caller can transparently and in real-time observe the download process. Therefore, the technical solution of this application comprehensively improves the stability, efficiency, and observability of the client-side model download.
[0032] The terminal model download method in this exemplary embodiment will now be further described.
[0033] In one embodiment of the present invention, the specific process of "obtaining the current device's regional preference information, sorting each download source based on the regional preference information and the regional priority, and generating a candidate download source queue" in step S103 can be further explained in conjunction with the following description.
[0034] As described in the following steps, obtain the network area identifier of the current device and / or the area preference parameter corresponding to the user configuration information of the current device; use the network area identifier and / or the area preference parameter as the area preference information; match the area preference information with the area priority to obtain the matching degree corresponding to each download source; sort each download source in descending order of matching degree to obtain the candidate download source queue.
[0035] In this embodiment, the regional preference information is not limited to a single source, but can be obtained from one or a combination of two methods: one method is a network region identifier, which characterizes the actual network environment in which the device is currently located, such as a network region identifier or language environment identifier obtained from the device's system interface; the other method is a regional preference parameter explicitly set in the user configuration information, such as the download region preference specified by the user in the settings interface. When both methods are available simultaneously, they can be used together as regional preference information for sorting. Subsequently, the regional preference information is matched one by one with the regional priority marked by each download source, and a matching degree is calculated for each download source. Then, all download sources are arranged from high to low according to the matching degree, and finally a candidate download source queue is obtained. Under this sorting mechanism, the download source that is most suitable for the current device and user environment is always at the top of the queue, thereby significantly reducing the probability of first download failure due to regional network differences. As a specific implementation, the model configuration data can carry a `download_region` field, which is used in the EdgeBox model configuration to indicate the region to which the download source applies. The download source selector in the `ensure` coordinator reads this `download_region` field and compares it with the actual network region of the current device to complete the matching and sorting process described above. In one example, this matching operation can be implemented using lightweight methods such as string comparison, prefix matching, or region code mapping, without the need for additional server-side involvement.
[0036] In one embodiment of the present invention, the specific process of "sending a resume request to the first download source in the candidate download source queue based on the number of downloaded bytes of the local temporary file" in step S106 can be further described in conjunction with the following description.
[0037] As described in the following steps, read the current file length of the local temporary file as the number of bytes already downloaded; send the breakpoint resume request to the first download source, the breakpoint resume request includes an HTTP request header, the HTTP request header carries a Range field, the starting byte position of the Range field is set to the number of bytes already downloaded, so that the first download source starts returning file data from the starting byte position.
[0038] In this embodiment, the number of bytes downloaded is determined directly from the file system metadata of the local temporary file—that is, the current file length. Taking a foreground download task as an example, the task reads the length of the local temporary file before initiating the request, assuming it is N bytes. Then, it constructs the Range: bytes=N- field in the HTTP request header, explicitly instructing the first download source to continue returning file data from the Nth byte. When the server correctly supports the HTTP Range protocol, its response will start transmitting from the Nth byte, seamlessly connecting with the existing N bytes of file data locally. This mechanism ensures that even if a model file of several gigabytes is interrupted due to network disconnection or process recycling, there is no need to re-request all the received data when resuming the download, greatly saving bandwidth and time. As a specific implementation, when the download engine in EdgeBox detects that the length of the local temporary file is N, it constructs the aforementioned Range: bytes=N- request header and sends a resume request to the current download source. The server then streams the remaining model file data starting from the Nth byte.
[0039] In one embodiment of the present invention, the specific features of the "end-side model download method" after step S104 can be further described in conjunction with the following description.
[0040] As described in the following steps, if the local official model file does not exist, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file; if the local official model file exists and is complete, the local official file is read, a corresponding status event is generated and pushed to the caller.
[0041] In this embodiment, the existence and integrity check results of the local official model file determine the subsequent process flow. When the local official model file does not exist at all, it means that the model has never been successfully downloaded. In this case, there is no need to check the local temporary file; instead, a blank temporary file is created directly, and a full download request is initiated to the first download source in the candidate download source queue. The returned file data is then written to the blank temporary file from the beginning. When the local official model file exists and the integrity check passes, it means that the model file is ready. The next step is to read the local official file and generate a status event indicating that the model is ready. This event is then pushed to the caller via a streaming channel, informing the caller that there is no need to wait for the download before proceeding to the subsequent loading or warm-up phase. Through this branching process, the ensure process can provide a definite and reasonable execution path under different local file states, avoiding meaningless network requests or missed checks. As a specific implementation method, the integrity check can use the SHA-256 hash digest algorithm to compare the hash value of the local official model file with the verification information recorded in the model configuration data to determine whether the file is complete.
[0042] In one embodiment of the present invention, the specific features of the "end-side model download method" after step S105 can be further described in conjunction with the following description.
[0043] As described in the following steps, if the local temporary file does not exist in the model cache directory, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file.
[0044] In this embodiment, when the local formal model file exists but is incomplete, and there are no local temporary files available for resuming downloads in the model cache directory, it means that no download has been performed previously, or the previous temporary files have been cleaned up. Therefore, only a full download can be initiated. At this time, a new blank temporary file is created as the receiving carrier, and a full download request is initiated to the first download source in the candidate download source queue. The returned file data is then written to the blank temporary file starting from zero. By clearly distinguishing between the two scenarios of "the existence of a resumable temporary file" and "the absence of a resumable temporary file," and corresponding to the two processing methods of breakpoint resume and full download respectively, the state machine logic of the model file preparation process is ensured to be complete.
[0045] In one embodiment of the present invention, the specific features of the "end-side model download method" prior to step S107 can be further described in conjunction with the following description.
[0046] As described in the following steps, if the download from the first download source fails, the reason for the failure is recorded, the next download source after the first download source is selected from the candidate download source queue as the target download source, and the breakpoint resume request is resent to the target download source.
[0047] In this embodiment, the initial download source may fail at any stage, such as connection establishment, data transmission, or response verification. When a download failure is detected, the ensure coordinator first records the reason for the failure, which can be presented to the caller as an error information field in subsequent streaming status events. Then, it searches the candidate download source queue for the direct successor to the initial download source, selects this successor as the target download source, and resends the resume request to it. Since the previous temporary file writing was an append-only operation, the current length of the local temporary file represents the amount of data that has been reliably received. Therefore, the switched target download source can resume the download based on this length without having to revert to a full download. This mechanism of automatically switching to a backup source and maintaining resume functionality effectively ensures the continuity of the download process when a single source is unavailable. As a specific implementation, when a download fails, after the foreground download task records the reason for the failure, the ensure coordinator switches to the next item in the candidate download source queue and decides, based on the temporary file status, whether to continue the download or, if the temporary file itself is corrupted, clean it up and re-download. Optionally, if all download sources in the candidate download source queue fail, the ensure coordinator can return an error message to the caller via a status event, allowing the caller to decide whether to retry later or for the system scheduling mechanism to automatically retry after the conditions are restored.
[0048] In one embodiment of the present invention, the specific process of "converting the download progress data into a streaming status event and continuously pushing it to the caller" in step S108 can be further described in conjunction with the following description.
[0049] As described in the following steps, the download progress data is encapsulated into the streaming status event; the streaming status event is pushed to the caller in real time through a long connection channel associated with the model's preparation request data.
[0050] In this embodiment, download progress data is not simply stored in memory or a file, but is actively encapsulated as structured event objects. A long-lived connection channel exists between the caller and the model preparing the request data. This channel is allocated and associated with the current request when it is initiated. The ensure coordinator pushes continuously generated streaming status events to the caller in real time through this long-lived connection channel. The timing of the push can closely follow each progress data update, ensuring that there is only a minimal delay between the progress information seen by the caller and the actual download status. Because of the long-lived connection channel, the caller does not need to repeatedly query the progress using polling, which reduces device resource consumption and improves the timeliness of status updates. As a specific implementation, this long-lived connection channel can be implemented using the SSE protocol. The ensure coordinator converts the download progress data into SSE format status events and continuously pushes them to the caller through this SSE connection. The streaming status events include at least fields such as download source, number of bytes downloaded, total number of bytes, and download speed. When an error occurs, error information can also be carried in the event. In one example, the download task is submitted to the mobile terminal's foreground task scheduling mechanism (such as Android's WorkManager foreground task) with a unique WorkName, and a foreground notification is set to declare that the important long-running task is being executed, thereby reducing the probability that the download task will be reclaimed by the system when it is running in the background; the foreground download task continuously reports progress fields such as bytes_downloaded, total_bytes, and bytes_per_second internally, and the ensure coordinator subscribes to or reads these fields and converts them into SSE status events to bridge to the caller.
[0051] Through the above embodiments, the client-side model download method provided in this application achieves the following beneficial effects overall. First, improved stability: Since the model download request is not directly bound to a single, volatile network source or system capability, but rather undergoes coordinated processing through multi-source sorting, status judgment, and automatic switching, the failure of a single download source, network area differences, or process restart will not directly disrupt the normal workflow of the user interface. Second, improved observability: The caller continuously receives streaming status events through a long connection channel, enabling real-time identification of the current download stage, the number of bytes downloaded, the download speed, the current download source, and the specific reason for failure in case of failure, significantly improving the transparency of the model preparation process to the caller. Third, improved resource efficiency: Through the breakpoint resume mechanism of local temporary files, only the unfinished part needs to be transmitted when resuming download, effectively saving network traffic and download time; through multi-source sorting, the download source with better network region is selected first, reducing invalid requests caused by region unreachability; through the foreground task scheduling mechanism, the probability of long download tasks being re-downloaded in full after being reclaimed by the system is reduced, making the consumption of CPU, memory and network resources more controllable.
[0052] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0053] Reference Figure 2 This illustration shows an end-side model downloading apparatus 200 provided in an embodiment of this application, used to implement the end-side model downloading method provided in the embodiments of this application. The apparatus specifically includes: The request receiving module 201 is used to receive model preparation request data sent by the caller, wherein the model preparation request data includes a model identifier; The data reading module 202 is used to read model configuration data according to the model identifier, wherein the model configuration data includes multiple download sources and the regional priority of each download source; The queue generation module 203 is used to obtain the current device's regional preference information, sort each download source based on the regional preference information and the regional priority, and generate a candidate download source queue; The file inspection module 204 is used to check whether the local formal model file corresponding to the model preparation request data exists and is complete. The directory query module 205 is used to query whether a local temporary file corresponding to the local formal model file exists in the model cache directory if the local formal model file exists but is incomplete. The request sending module 206 is used to send a breakpoint resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded of the local temporary file if the local temporary file exists in the model cache directory. The data calculation module 207 is used to append the file data returned by the first download source to the local temporary file, and calculate the download progress data based on the number of bytes written to the local temporary file and the total number of bytes in the file; The event push module 208 is used to convert the download progress data into streaming status events and continuously push them to the caller.
[0054] In one embodiment of the present invention, the queue generation module 203 is further configured to: Obtain the network region identifier of the current device, and / or the region preference parameters corresponding to the user configuration information of the current device; The network region identifier and / or the region preference parameter shall be used as the region preference information; The region preference information is matched with the region priority to obtain the matching degree corresponding to each download source; The download sources are sorted in descending order of matching degree to obtain the candidate download source queue.
[0055] In one embodiment of the present invention, the request sending module 206 is further configured to: Read the current file length of the local temporary file as the number of bytes downloaded; The interrupted resume request is sent to the first download source. The interrupted resume request includes an HTTP request header, which carries a Range field. The starting byte position of the Range field is set to the number of bytes already downloaded, so that the first download source starts returning file data from the starting byte position.
[0056] In one embodiment of the present invention, the end-side model downloading device 200 is further configured to: If the local official model file does not exist, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file; If the local official model file exists and is complete, then the local official file is read, the corresponding status event is generated, and pushed to the caller.
[0057] In one embodiment of the present invention, the end-side model downloading device 200 is further configured to: If the local temporary file does not exist in the model cache directory, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file.
[0058] In one embodiment of the present invention, the end-side model downloading device 200 is further configured to: If the download from the first download source fails, the reason for the failure is recorded, the next download source after the first download source is selected from the candidate download source queue as the target download source, and the breakpoint resume request is resent to the target download source.
[0059] In one embodiment of the present invention, the event push module 208 is further configured to: The download progress data is encapsulated into the streaming status event; The streaming status events are pushed to the caller in real time through a long connection channel that associates the caller with the model's prepared request data.
[0060] Reference Figure 3 The illustration shows a computer electronic device 1 for implementing the end-side model download method of the present invention, which may specifically include: The computer electronic device 1 is manifested in the form of a general computing device, including: one or more processors or processing units 3, memory 8, and a bus 4 connecting different system components (including memory 8 and processing unit 3).
[0061] Bus 4 represents one or more of several bus architectures, including memory buses or memory controllers, peripheral buses, graphics acceleration ports, processors, or local buses using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Audio / Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0062] Computer electronic device 1 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by computer electronic device 1, including volatile and non-volatile media, removable and non-removable media.
[0063] Memory 8 may include computer system readable media in the form of volatile memory, such as random access memory 9 and / or cache memory 10. A computer electronic device 1 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 11 may be used to read and write non-removable, non-volatile magnetic media (commonly referred to as a "hard disk drive"). Although Figure 3 As not shown, a disk drive for reading and writing to a removable non-volatile disk (such as a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (such as a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 4 via one or more data media interfaces. The memory may include at least one program product having a set (e.g., at least one) of program modules 13 configured to perform the functions of the embodiments of this application.
[0064] A program / utility 12 having a set (at least one) of program modules 13 may be stored, for example, in memory. Such program modules 13 include—but are not limited to—an operating system, one or more application programs, other program modules 13, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 13 typically perform the functions and / or methods described in the embodiments of this application.
[0065] The computer electronic device 1 can also communicate with one or more external devices 2 (e.g., keyboard, pointing device, display 7, camera, etc.), and with one or more devices that enable an operator to interact with the computer electronic device 1, and / or with any device that enables the computer electronic device 1 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed through the I / O interface 6. Furthermore, the computer electronic device 1 can also communicate with one or more networks (e.g., local area network (LAN)), wide area network (WAN), and / or public networks (e.g., the Internet) through the network adapter 5. Figure 3 As shown, network adapter 5 communicates with other modules of computer electronic device 1 via bus 4. It should be understood that, although... Figure 3 Not shown, it may be combined with other hardware and / or software modules, including but not limited to: microcode, device drivers, redundant processing unit 3, external disk drive array, RAID system, tape drive and data backup storage system 11, etc.
[0066] The processing unit 3 executes various functional applications and data processing by running programs stored in memory 8, such as implementing the end-side model download method provided in the embodiments of this application.
[0067] That is, when the processing unit 3 executes the above program, it performs the following: receiving model preparation request data sent by the caller, the model preparation request data including a model identifier; reading model configuration data according to the model identifier, the model configuration data including multiple download sources and the regional priority of each download source; obtaining the regional preference information of the current device, sorting each download source based on the regional preference information and the regional priority, and generating a candidate download source queue; checking whether the local official model file corresponding to the model preparation request data exists and is complete; if the local official model file exists but is incomplete, querying whether the local temporary file corresponding to the local official model file exists in the model cache directory; if the local temporary file exists in the model cache directory, sending a breakpoint resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded in the local temporary file; appending the file data returned by the first download source to the local temporary file, and calculating the download progress data based on the number of bytes already written in the local temporary file and the total number of bytes in the file; converting the download progress data into a streaming status event and continuously pushing it to the caller.
[0068] In this application embodiment, the application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the end-side model download method provided in all embodiments of the application.
[0069] That is, when the program is executed by the processor, it implements the following: receiving model preparation request data sent by the caller, the model preparation request data including a model identifier; reading model configuration data according to the model identifier, the model configuration data including multiple download sources and the regional priority of each download source; obtaining the current device's regional preference information, sorting each download source based on the regional preference information and the regional priority, and generating a candidate download source queue; checking whether the local official model file corresponding to the model preparation request data exists and is complete; if the local official model file exists but is incomplete, querying whether a local temporary file corresponding to the local official model file exists in the model cache directory; if the local temporary file exists in the model cache directory, sending a breakpoint resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded in the local temporary file; appending the file data returned by the first download source to the local temporary file, and calculating the download progress data based on the number of bytes already written in the local temporary file and the total number of bytes in the file; converting the download progress data into a streaming status event and continuously pushing it to the caller.
[0070] Any combination of one or more computer-readable media may be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device.
[0071] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including—but not limited to—electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of transmitting, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0072] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof. These programming languages include object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the operator's computer, partially on the operator's computer, as a standalone software package, partially on the operator's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the operator's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider). The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably.
[0073] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0074] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0075] The foregoing has provided a detailed description of the terminal model download method, apparatus, electronic device, and storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for downloading a terminal-side model, characterized in that, include: Receive model preparation request data sent by the caller, wherein the model preparation request data includes a model identifier; Read model configuration data based on the model identifier. The model configuration data includes multiple download sources and the regional priority of each download source. Obtain the current device's region preference information, sort each download source based on the region preference information and the region priority, and generate a candidate download source queue; Check if the local official model file corresponding to the model preparation request data exists and is complete; If the local official model file exists but is incomplete, then check if a local temporary file corresponding to the local official model file exists in the model cache directory; If the local temporary file exists in the model cache directory, a resume request is sent to the first download source in the candidate download source queue based on the number of bytes already downloaded from the local temporary file. The file data returned by the first download source is appended to the local temporary file, and the download progress data is calculated based on the number of bytes written to the local temporary file and the total number of bytes in the file. The download progress data is converted into streaming status events and continuously pushed to the caller.
2. The method according to claim 1, characterized in that, The step of obtaining the current device's region preference information, and sorting each download source based on the region preference information and the region priority to generate a candidate download source queue includes: Obtain the network region identifier of the current device, and / or the region preference parameters corresponding to the user configuration information of the current device; The network region identifier and / or the region preference parameter shall be used as the region preference information; The region preference information is matched with the region priority to obtain the matching degree corresponding to each download source; The download sources are sorted in descending order of matching degree to obtain the candidate download source queue.
3. The method according to claim 1, characterized in that, The step of sending a resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded from the local temporary file includes: Read the current file length of the local temporary file as the number of bytes downloaded; The interrupted resume request is sent to the first download source. The interrupted resume request includes an HTTP request header, which carries a Range field. The starting byte position of the Range field is set to the number of bytes already downloaded, so that the first download source starts returning file data from the starting byte position.
4. The method according to claim 1, characterized in that, After checking whether the local official model file corresponding to the model preparation request data exists and is complete, the process further includes: If the local official model file does not exist, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file; If the local official model file exists and is complete, then the local official file is read, the corresponding status event is generated, and pushed to the caller.
5. The method according to claim 1, characterized in that, After checking whether a local temporary file corresponding to the local official model file exists in the query model cache directory, the process further includes: If the local temporary file does not exist in the model cache directory, a new blank temporary file is created, a full download request is sent to the first download source in the candidate download source queue, and the file data returned by the first download source is written into the blank temporary file.
6. The method according to claim 1, characterized in that, Before appending the file data returned by the first download source to the local temporary file and calculating the download progress data based on the number of bytes written to the local temporary file and the total number of bytes in the file, the method further includes: If the download from the first download source fails, the reason for the failure is recorded, the next download source after the first download source is selected from the candidate download source queue as the target download source, and the breakpoint resume request is resent to the target download source.
7. The method according to any one of claims 1 to 6, characterized in that, The step of converting the download progress data into streaming status events and continuously pushing them to the caller includes: The download progress data is encapsulated into the streaming status event; The streaming status events are pushed to the caller in real time through a long connection channel that associates the caller with the model's prepared request data.
8. An end-side model downloading device, characterized in that, include: The request receiving module is used to receive model preparation request data sent by the caller, wherein the model preparation request data includes a model identifier; The data reading module is used to read model configuration data according to the model identifier, wherein the model configuration data includes multiple download sources and the regional priority of each download source; The queue generation module is used to obtain the current device's regional preference information, sort each download source based on the regional preference information and the regional priority, and generate a candidate download source queue. The file inspection module is used to check whether the local formal model file corresponding to the model preparation request data exists and is complete. The directory query module is used to query whether a local temporary file corresponding to the local official model file exists in the model cache directory if the local official model file exists but is incomplete. The request sending module is used to send a breakpoint resume request to the first download source in the candidate download source queue based on the number of bytes already downloaded of the local temporary file if the local temporary file exists in the model cache directory. The data calculation module is used to append the file data returned by the first download source to the local temporary file, and calculate the download progress data based on the number of bytes written to the local temporary file and the total number of bytes in the file; The event push module is used to convert the download progress data into streaming status events and continuously push them to the caller.
9. A computer electronic device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the end-side model download method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the steps of the end-side model download method as described in any one of claims 1 to 7.
