Large model efficient fine tuning and adaptive quantification method for traffic scene

Through adaptive quantization and efficient fine-tuning methods, the problem of difficult deployment of large models in traffic scenarios is solved, and the model volume compression and inference speed are improved, while maintaining the accuracy of traffic instruction generation.

CN120597968APending Publication Date: 2025-09-05湖南工商大学
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510704076.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-29
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

The existing pre-trained large models are difficult to deploy in traffic scenarios, the inference resource demand is high, and the existing fine-tuning methods are prone to catastrophic forgetting and lack of adaptability in quantitative solutions, resulting in a decrease in model accuracy.

Method used

Adaptive quantization method is adopted, and the weight of the pre-trained model is frozen through loRA fine-tuning training, and rank decomposition and quantization are performed. Combined with INT4, FP4, and NF4 quantization methods, outliers are eliminated and the optimal quantization method is selected to reduce the calculation load and resource requirements.

Benefits of technology

It effectively compresses the model size, reduces computational complexity, improves the feasibility of model deployment on edge devices, maintains the accuracy of traffic instruction generation, and significantly improves inference speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120597968A_ABST
    Figure CN120597968A_ABST
Patent Text Reader

Abstract

The invention provides a traffic scene-oriented large model high-efficiency fine tuning and adaptive quantification method, which belongs to the technical field of intelligent traffic, and comprises the following steps of: firstly, freezing a trunk weight of a pre-trained large model by adopting a LoRA method, and performing low-rank decomposition on an attention module weight of the pre-trained large model; performing multi-strategy quantization processing on the weight matrix and the decomposition matrix thereof, wherein the multi-strategy quantization processing comprises quantization methods of INT4, FP4, NF4 and the like; abnormal large values are eliminated through a dynamic energy model, and a block probability density distribution function is constructed to improve quantization precision; and finally, adaptively selecting a most matched quantification scheme based on a KL divergence minimization criterion, and realizing 4-bit compression of the model. The method can be widely applied to a model optimization task in a text generation code traffic control system, the calculation load is remarkably reduced while the instruction generation accuracy is guaranteed, and good real-time performance, portability and system practical value are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence model compression and deployment optimization, specifically a method for efficient fine-tuning and adaptive quantization of large models for traffic scenarios. This method is applicable to traffic control command generation systems based on pre-trained large models, aiming to improve the model's inference efficiency and response speed in edge devices. Background Art

[0002] With the rapid development of intelligent transportation and artificial intelligence generation (AIGC) technology, large models are demonstrating significant application value in areas such as traffic scene understanding, command generation, and scenario simulation. In particular, text-to-code generation systems, which automatically generate executable traffic control code from natural language or voice commands, have become a crucial component of smart cities and vehicle-road collaborative systems.

[0003] However, existing large pre-trained models (such as GPT-4, LLaMA, and CodeGen) already have tens or even hundreds of billions of parameters, requiring extremely high GPU memory requirements for inference, making them unsuitable for direct deployment on computing-constrained edge devices (such as vehicle terminals and roadside units (RSUs). Furthermore, large, general-purpose models are difficult to directly adapt to specific instruction sets or control APIs used in the transportation sector, requiring additional fine-tuning and compression.

[0004] Existing fine-tuning methods, such as full-parameter fine-tuning, are costly and prone to catastrophic forgetting. Existing quantization solutions often rely on static, uniform, low-precision transformations that lack the ability to adapt to differences in data distribution, often leading to significant degradation in model accuracy. In traffic code generation scenarios, in particular, some model weights may be perturbed by outliers, further amplifying quantization errors and reducing the reliability of control code generation.

[0005] Therefore, there is an urgent need for a joint optimization method that combines efficient parameter fine-tuning and adaptive quantization, which can not only retain the ability of large models in understanding and generating traffic instructions, but also effectively compress the model size, reduce inference resource requirements, and be adapted for deployment in actual traffic scenario code generation systems. Summary of the Invention

[0006] The present invention is made in view of the above problems, and its purpose is to provide a large-scale model efficient fine-tuning and adaptive quantization method for traffic scenarios. According to the actual distribution of the data to be quantized, adaptive decision-making is adopted to select the appropriate quantization method to perform 4-bit quantization on the model. In addition, abnormal large values ​​can be eliminated on the basis of data blocking to reduce their interference. It can effectively reduce the quantization error and hardware resource requirements of the pre-trained large model during the quantization fine-tuning process. It can be widely used in model optimization tasks in text generation code traffic control systems, and significantly reduce the computational load while ensuring the accuracy of instruction generation.

[0007] Specifically, a first aspect of the present invention provides a large-scale model efficient fine-tuning and adaptive quantization method for traffic scenarios, comprising the following steps: Step 1: Use the loRA fine-tuning training method to freeze the weight values ​​of the pre-trained large model, and inject the weight matrix of the large model into the trainable rank decomposition matrix and perform rank decomposition; Freeze all weight parameters of the pre-trained model (excluding them from gradient updates), retaining the general semantics and knowledge capabilities learned by the pre-trained model through massive data, and avoiding the high computational cost and catastrophic forgetting problems caused by full parameter fine-tuning.

[0008] Step 2: Quantize the weight matrix and rank decomposition matrix, and calculate the quantiles of several quantization methods and their quantization probability density distribution functions respectively; The data in each weight matrix is ​​divided into blocks, and the dynamic energy equation method is used to eliminate abnormal and large values, obtain the cleaned data, and calculate its block probability density distribution function; INT4 quantizes weights and activation values ​​into 4-bit integers, compressing the model size to 1 / 8 of the original FP32, significantly reducing memory usage and computational complexity; FP4 retains the exponent bit design of floating-point numbers and can more flexibly represent values ​​of different orders of magnitude than INT4, reducing over-clipping and bit waste problems; NF4 is based on quantile quantization, ensuring that each quantization interval contains the same number of weight values. It is particularly suitable for large model weights with zero-centered normal distribution, and its accuracy is significantly higher than INT4 and FP4.

[0009] Divide the data in each weight matrix into blocks. Specifically, divide the matrix into H blocks. The size of each block is determined according to the size of the matrix M×N. Assuming that the number of rows in the matrix is ​​M and the number of columns is N, the size of each block is m×n. , .

[0010] Step 3: Use KL divergence to calculate the similarity between the block probability density distribution function and each quantized probability density distribution function, and adaptively select the corresponding quantization method to quantize the weight matrix of the pre-trained large model.

[0011] Step 4: The quantified large model generates structured executable code based on the user's traffic semantic instructions, and generates the corresponding traffic scene through real-time rendering on the traffic simulation platform.

[0012] Furthermore, the step 1 specifically includes: using the loRA fine-tuning training method to freeze the weight value of the pre-trained large model, and the weight matrix of the multi-head attention module of the Transformer architecture in the pre-trained large model Both inject trainable rank decomposition matrices , and perform rank decomposition, decomposing into .

[0013] The multi-head attention module is composed of multiple self-attention modules. Each self-attention head has its own weight matrix, forming the weight matrix of the entire multi-head attention module. In the weight matrix of a single self-attention module is the query projection matrix in the self-attention module, is the key projection matrix in the self-attention module, is the value projection matrix in the self-attention module, is the output projection matrix in the self-attention module.

[0014] Rank decomposition matrix , , where R is the field of real numbers, is the matrix dimension, after decomposition , , For order, Much smaller than the matrix dimension At this time, the number of parameters of the pre-trained large model fine-tuning is reduced from the original The decomposed matrix , and there are .

[0015] Since the weight matrix of the Transformer attention layer is high in dimension and highly redundant, low-rank decomposition can specifically reduce training costs (such as reducing the number of parameters by about 90%) while maintaining model performance.

[0016] Furthermore, the weight matrix and the rank decomposition matrix are quantized, specifically by quantizing the data format stored in the matrix from 16-bit to 4-bit, so as to reduce the demand for video memory and speed up the training process.

[0017] Furthermore, the several quantization methods specifically include at least one of the INT4 quantization method, the FP4 quantization method and the NF4 quantization method.

[0018] Furthermore, the INT4 quantization method is specifically based on the distribution range The probability density function of the mean square distribution between them is equally divided to obtain the quantized quantile, and then the quantile probability density distribution function of the INT4 quantization method is obtained based on the quantile and probability value. , the formula is as follows: Mean square distribution probability density function: ; in: , according to the distribution range in The probability density function of the mean square distribution between the two is divided equally to obtain the quantitative quantile , whose interval is: .

[0019] For the quantile probability density distribution function Calculation of each quantile Represents an interval whose range is defined as the midpoint of the adjacent quantiles on the left and right. and , the intervals are respectively from Extending to the right, and from Extending to the left, the quantile probability density distribution function of other quantization methods is calculated in the same way as the INT4 quantization method. The calculation formula is as follows: ; in: is the quantile probability density distribution function of the INT4 quantization method; The first quantization quantile of the INT4 quantization method; The second quantization quantile of the INT4 quantization method; is the i-th quantization quantile of the INT4 quantization method; is the i+2th quantization quantile of the INT4 quantization method; It is the 15th quantization quantile of the INT4 quantization method; It is the 16th quantization quantile of the INT4 quantization method; Furthermore, the FP4 quantization method is specifically to calculate the quantized quantile according to the quantile calculation formula and normalize it to Interval, and then according to the quantile and probability value, the quantile probability density distribution function of the FP4 quantization method is obtained. , the formula is as follows: Quantile calculation formula: ; in: , the sign bit of the i+1th FP4 quantized quantile, indicating positive or negative; , the exponent bit of the i+1th FP4 quantized quantile, representing the exponent part of the floating point number; , the mantissa of the i+1th FP4 quantized quantile, representing the mantissa part of the floating-point number; Calculate the quantitative quantile according to the quantile calculation formula , , and normalized to The interval is: .

[0020] The calculation formula is: ; in: is the quantile probability density distribution function of the FP4 quantization method; It is the first quantized quantile of the FP4 quantization method; It is the second quantized quantile of the FP4 quantization method; is the i-th quantization quantile of the FP4 quantization method; is the i+2th quantized quantile of the FP4 quantization method; It is the 15th quantized quantile of the FP4 quantization method; It is the 16th quantized quantile of the FP4 quantization method; Furthermore, the NF4 quantization method specifically obtains the quantized quantile according to the quantile calculation formula, and then obtains the quantile probability density distribution function of the NF4 quantization method according to the quantile and probability value. , the formula is as follows: Quantile calculation formula: ; in: Conforms to the standard normal distribution ; ; The present invention is 4-bit quantization, so k=4, and the quantization quantile can be obtained according to the calculation formula , ,for: .

[0021] The calculation formula is: ; in: is the quantile probability density distribution function of the NF4 quantization method; It is the first quantized quantile of the NF4 quantization method; It is the second quantization quantile of the NF4 quantization method; is the i-th quantization quantile of the NF4 quantization method; is the i+2th quantized quantile of the NF4 quantization method; It is the 15th quantized quantile of the NF4 quantization method; It is the 16th quantized quantile of the NF4 quantization method; Furthermore, the block probability density distribution function is calculated by dividing the weight matrix to be quantized into blocks and removing abnormal large values ​​to reduce the quantization error, and then normalizing the data to interval, and statistically calculate the probability density distribution of the data in the weight matrix to be quantized to obtain the block probability density distribution function .

[0022] Furthermore, the elimination of abnormally large values ​​specifically includes: Step 1.1: Based on the input data , calculate the initial weight and initial dynamic energy, the formula is as follows: ; ; in: is the initial weight; is the square value of the j-th data; is the square value of the i-th data; is the total number of input data; is the initial dynamic energy; Step 1.2: Calculate the dynamic energy in the kth iteration separately and the dynamic energy threshold in the kth iteration , the formula is as follows: ; ; in: is the dynamic energy in the kth iteration; is the weight of the i-th data in the k-th iteration; is the square value of the i-th data; is the total number of input data; is the dynamic energy threshold in the kth iteration; is the parameter used to adjust the threshold; Step 1.3: By comparison , mark the abnormally large values, and update the weight value and dynamic energy according to the exponential decay formula. The formula is as follows: ; in: is the weight of the i-th data in the k+1-th iteration; is the weight of the i-th data in the k-th iteration; is the natural exponential function; is the weight decay rate factor; is the dynamic energy threshold in the kth iteration; is the i-th data; Step 1.4: Iterate repeatedly until convergence condition , The convergence threshold is used to output data that excludes abnormally large values.

[0023] Furthermore, the step three specifically includes: calculating Quantile probability density distribution function with INT4 quantization method , FP4 quantization method quantile probability density distribution function , NF4 quantization method quantile probability density distribution function The KL divergence value between them, and then based on the minimum KL divergence among the three, select the corresponding quantization method to quantize the weight matrix parameters. The formula is as follows: ; ; ; in: for and The KL divergence value between ; for and The KL divergence value between ; for and The KL divergence value between ; is the probability density distribution function of the weight distribution on the i+1th INT4 quantization method quantile; is the probability density distribution function of the weight distribution on the i+1th NF4 quantile; is the probability density distribution function of the weight distribution on the i+1th FP4 quantile; is the quantile probability density distribution function of the INT4 quantization method; is the quantile probability density distribution function of the NF4 quantization method; is the quantile probability density distribution function of the FP4 quantization method; Furthermore, the step four specifically includes: the quantized large model generates structured executable code according to the user's traffic semantic instructions, which is used to call the predefined microservice API in the traffic control system, and the system generates the corresponding traffic scene in real time through traffic simulation platforms such as CARLA.

[0024] In step 4, the structured executable code refers to the control command generated by the model based on traffic semantic instructions and conforming to a predefined format. The command can be directly used to call the microservice API in the traffic control system to trigger dynamic changes in traffic scene elements.

[0025] Furthermore, to achieve accurate mapping of semantic instructions to structured code, an instruction tuning dataset was constructed during the training phase. User natural language traffic instructions were mapped to standard prompt templates to form a training sample set of "user instruction - prompt template - output code" triplets. Each type of instruction contained at least 20 groups of samples to improve the model's generalization ability for different expressions.

[0026] Furthermore, the Prompt is a standardized function call format, which is used to guide the model to output structured code that complies with the system interface.

[0027] The fine-tuned and quantized model receives traffic instructions input by users and stably generates API call codes that meet system specifications based on the prompt matching logic learned during training. It also supports the generation of multiple API instruction combinations. For example, for the input "add 3 vehicles and turn on rainy mode", the model can output the combined code sequence AddVehicles(3);SetWeather(\"Rainy\") to complete the compound execution of multiple instructions. Furthermore, the generated control instructions are transmitted to the CARLA platform backend through the interface protocol WebSocket. The CARLA system will call the corresponding microservice module to render the changes of elements such as vehicles, roads, weather, and traffic lights in real time in the three-dimensional traffic simulation environment, forming a visual, controllable, and interactive traffic scene.

[0028] In the second aspect, the present invention further provides a computing device having the function of implementing the method described in the first aspect above. The beneficial effects can be found in the description of the first aspect and will not be described in detail here. The functions can be implemented by hardware or by executing corresponding software through hardware. The hardware or software includes one or more modules corresponding to the above functions. In one possible design, the structure of the device includes an acquisition module, a training module, and optionally, a construction module. These modules can implement the functions of the training node in the method example of the first aspect above. For details, please refer to the detailed description in the method example and will not be described here.

[0029] In a third aspect, the present invention further provides a computing device for implementing the functions of the method described in the first aspect above. The beneficial effects can be found in the description of the first aspect and will not be repeated here. The structure of the computing device includes a processor and a memory, and the memory is used to store instructions and / or data. The memory is coupled to the processor, and when the processor executes the program instructions stored in the memory, the function of the training node in the example of the first aspect above can be implemented. The structure of the computing device also includes a communication interface for communicating with other devices.

[0030] In a fourth aspect, the present invention further provides a computer-readable storage medium, in which instructions are stored, which, when executed on a computer, enable the computer to execute the method in the above-mentioned first aspect and various possible designs of the first aspect.

[0031] In a fifth aspect, the present invention further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method in the first aspect and various possible designs of the first aspect.

[0032] In a sixth aspect, the present invention further provides a computing chip, which is connected to a memory and is used to read and execute a software program stored in the memory, and to execute the methods in the above-mentioned first aspect and various possible implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the embodiments of the present drawings or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present drawings. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.

[0034] Figure 1 is a flow chart of the steps of the present invention; Figure 2 A comparison chart of the execution accuracy of the embodiment of the present invention and the original model in different tasks; Figure 3 Schematic diagram of scene rendering and interaction effects of generating control instructions in the CARLA simulation platform in an embodiment of the present invention.

[0035] The purpose, features and advantages of this drawing will be further described with reference to the accompanying drawings in conjunction with the embodiments. DETAILED DESCRIPTION

[0036] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely for explaining the present invention and are not intended to limit the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work are within the scope of protection of the present invention.

[0037] Obviously, the drawings described below are merely examples or embodiments of the present invention. Those skilled in the art can apply the present invention to other similar scenarios based on these drawings without inventive effort. Furthermore, it is understood that while the effort involved in such a development process may be complex and lengthy, for those skilled in the art related to the disclosure of the present invention, any design, manufacturing, or production changes based on the technical content disclosed in the present invention are merely conventional technical means and should not be construed as an inadequacy of the disclosure of the present invention.

[0038] Unless otherwise specified, all embodiments and optional embodiments of the present invention can be combined with each other to form new technical solutions.

[0039] Unless otherwise specified, all technical features and optional technical features of the present invention can be combined with each other to form a new technical solution.

[0040] Unless otherwise specified, all steps of the present invention may be performed sequentially or randomly, preferably sequentially. For example, the method includes steps (a) and (b), which means that the method may include steps (a) and (b) performed sequentially, or may include steps (b) and (a) performed sequentially. For example, the method may further include step (c), which means that step (c) may be added to the method in any order, for example, the method may include steps (a), (b) and (c), or may include steps (a), (c) and (b), or may include steps (c), (a) and (b), etc.

[0041] Unless otherwise specified, the terms "include" and "comprising" used in the present invention may be open-ended or closed-ended. For example, "include" and "comprising" may mean that other components not listed may also be included or that only the listed components are included.

[0042] Unless otherwise specified, the term "or" is inclusive in this disclosure. For example, the phrase "A or B" means "A, B, or both A and B." More specifically, the condition "A or B" is satisfied if any of the following conditions are met: A is true (or exists) and B is false (or does not exist); A is false (or does not exist) and B is true (or exists); or both A and B are true (or exist).

[0043] In order to better understand the solutions of the embodiments of the present invention, some relevant terms and concepts that may be involved in the embodiments of the present invention are first introduced below.

[0044] (1) Large Models: Large models refer to pre-trained language models (such as GPT and LLaMA) with a large number of parameters (typically in the billions to hundreds of billions). They learn general language representations using massive amounts of data. These models have powerful generation and understanding capabilities, such as in tasks like dialogue generation and text summarization. During training, large models capture statistical patterns in the data through self-supervised learning (such as masked language modeling), forming a deep understanding of language structure.

[0045] (2) Fine-tuning: Fine-tuning is to further adjust the parameters of a pre-trained large model using data from a specific domain or task to adapt it to downstream tasks (such as question answering and classification). Its core goal is to improve the performance of specific tasks while retaining general capabilities. Parameter Efficient Fine-Tuning (PEFT): Only some parameters (such as the adapter module) are updated to reduce computational and memory consumption. Regularization constraints: The KL divergence is used to limit the distribution difference between the fine-tuned model and the original model to prevent performance degradation. For example, InstructGPT uses the KL penalty term to control the model update amplitude in reinforcement learning fine-tuning (RLHF).

[0046] (3) Quantization. Quantization is a technique that converts high-precision (e.g., FP32) model parameters to low-precision (e.g., INT8) representations. This technique aims to reduce model size and accelerate inference. Symmetric / asymmetric quantization: The quantization range is selected based on the data distribution. KL divergence is often used to evaluate the difference in distribution before and after quantization to select the optimal parameters. Optimization goal: Minimize quantization error. For example, KL divergence is used to find the truncation threshold (amax) that minimizes the difference between the quantized distribution and the original distribution. Practical effect: Quantization may lead to precision loss, but this problem can be significantly alleviated by combining it with KL divergence optimization.

[0047] (4) KL divergence (Kullback-Leibler Divergence). KL divergence is an asymmetric indicator that measures the difference between two probability distributions. Its core application scenarios are: Model fine-tuning: As a regularization term, it prevents the fine-tuned model from deviating too far from the reference model. For example, in RLHF, KL divergence is used to constrain policy updates to balance generation quality and stability. Quantitative evaluation: By comparing the KL divergence of the distribution before and after quantization, the optimal quantization parameter is selected to reduce information loss. Generation task optimization: In text generation, the KL divergence between the generated results and the target distribution is minimized to improve quality. Model alignment: In reinforcement learning, KL divergence is used to constrain the difference between the output of the policy model and the reference model to prevent the generated content from deviating from human preferences.

[0048] In this embodiment, Figure 1 As shown in FIG, a method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios includes the following steps: Step 1: Use the loRA fine-tuning training method to freeze the weight values ​​of the pre-trained large model, and inject the weight matrix of the large model into the trainable rank decomposition matrix and perform rank decomposition; Freeze all weight parameters of the pre-trained model (excluding them from gradient updates), retaining the general semantics and knowledge capabilities learned by the pre-trained model through massive data, and avoiding the high computational cost and catastrophic forgetting problems caused by full parameter fine-tuning.

[0049] Step 2: Quantize the weight matrix and rank decomposition matrix, and calculate the quantiles of several quantization methods and their quantization probability density distribution functions respectively; The data in each weight matrix is ​​divided into blocks, and the dynamic energy equation method is used to eliminate abnormal and large values, obtain the cleaned data, and calculate its block probability density distribution function; INT4 quantizes weights and activation values ​​into 4-bit integers, compressing the model size to 1 / 8 of the original FP32, significantly reducing memory usage and computational complexity; FP4 retains the exponent bit design of floating-point numbers and can more flexibly represent values ​​of different orders of magnitude than INT4, reducing over-clipping and bit waste problems; NF4 is based on quantile quantization, ensuring that each quantization interval contains the same number of weight values. It is particularly suitable for large model weights with zero-centered normal distribution, and its accuracy is significantly higher than INT4 and FP4.

[0050] Divide the data in each weight matrix into blocks. Specifically, divide the matrix into H blocks. The size of each block is determined according to the size of the matrix M×N. Assuming that the number of rows in the matrix is ​​M and the number of columns is N, the size of each block is m×n. , .

[0051] In this embodiment, the values ​​of m and n are both 64, so the size of each matrix block is 64×64 data.

[0052] Step 3: Use KL divergence to calculate the similarity between the block probability density distribution function and each quantized probability density distribution function, and adaptively select the corresponding quantization method to quantize the weight matrix of the pre-trained large model.

[0053] Step 4: The quantified large model generates structured executable code based on the user's traffic semantic instructions, and generates the corresponding traffic scene through real-time rendering on the traffic simulation platform.

[0054] Furthermore, step one specifically includes: using the loRA fine-tuning training method to freeze the weight values ​​of the pre-trained large model, and the weight matrix of the multi-head attention module of the Transformer architecture in the pre-trained large model Both inject trainable rank decomposition matrices , and perform rank decomposition, decomposing into .

[0055] The multi-head attention module is composed of multiple self-attention modules. Each self-attention head has its own weight matrix, forming the weight matrix of the entire multi-head attention module. In the weight matrix of a single self-attention module is the query projection matrix in the self-attention module, is the key projection matrix in the self-attention module, is the value projection matrix in the self-attention module, is the output projection matrix in the self-attention module.

[0056] Rank decomposition matrix , ,in is the field of real numbers, is the matrix dimension, after decomposition , , For order, Much smaller than the matrix dimension At this time, the number of parameters of the pre-trained large model fine-tuning is reduced from the original The decomposed matrix , and there are .

[0057] Since the weight matrix of the Transformer attention layer is high in dimension and highly redundant, low-rank decomposition can specifically reduce training costs (such as reducing the number of parameters by about 90%) while maintaining model performance.

[0058] Furthermore, the weight matrix and rank decomposition matrix are quantized. Specifically, the data format stored in the matrix is ​​quantized from 16-bit to 4-bit to reduce the demand for video memory and speed up the training process.

[0059] Furthermore, several quantization methods specifically include at least one of the INT4 quantization method, the FP4 quantization method and the NF4 quantization method.

[0060] Furthermore, the INT4 quantization method is specifically based on the distribution range The probability density function of the mean square distribution between them is equally divided to obtain the quantized quantile, and then the quantile probability density distribution function of the INT4 quantization method is obtained based on the quantile and probability value. , the formula is as follows: Mean square distribution probability density function: ; in: , according to the distribution range in The probability density function of the mean square distribution between the two is divided equally to obtain the quantitative quantile , whose interval is: .

[0061] For the quantile probability density distribution function Calculation of each quantile Represents an interval whose range is defined as the midpoint of the adjacent quantiles on the left and right. and , the intervals are respectively from Extending to the right, and from Extending to the left, the quantile probability density distribution function of other quantization methods is calculated in the same way as the INT4 quantization method. The calculation formula is as follows: ; Furthermore, the FP4 quantization method is to calculate the quantile according to the quantile calculation formula and normalize it to Interval, and then according to the quantile and probability value, the quantile probability density distribution function of the FP4 quantization method is obtained. , the formula is as follows: Quantile calculation formula: ; Calculate the quantitative quantile according to the quantile calculation formula , , and normalized to The interval is: .

[0062] The calculation formula is: ; Furthermore, the NF4 quantization method specifically obtains the quantized quantile according to the quantile calculation formula, and then obtains the quantile probability density distribution function of the NF4 quantization method based on the quantile and probability value. , the formula is as follows: Quantile calculation formula: ; in: Conforms to the standard normal distribution ; ; The present invention is 4-bit quantization, so k=4, and the quantization quantile can be obtained according to the calculation formula , ,for: .

[0063] The calculation formula is: ; Furthermore, the block probability density distribution function is calculated by dividing the weight matrix to be quantized into blocks and removing abnormal large values ​​to reduce the quantization error, and then normalizing the data to interval, and statistically calculate the probability density distribution of the data in the weight matrix to be quantized to obtain the block probability density distribution function .

[0064] Furthermore, abnormally large values ​​are eliminated, including: Step 1.1: Based on the input data , calculate the initial weight and initial dynamic energy, the formula is as follows: ; ; Step 1.2: Calculate the dynamic energy in the kth iteration separately and the dynamic energy threshold in the kth iteration , the formula is as follows: ; ; Step 1.3: By comparison , mark the abnormally large values, and update the weight value and dynamic energy according to the exponential decay formula. The formula is as follows: ; Step 1.4: Iterate repeatedly until convergence condition , The convergence threshold is used to output data that excludes abnormally large values.

[0065] Furthermore, the step three specifically includes: calculating Quantile probability density distribution function with INT4 quantization method , FP4 quantization method quantile probability density distribution function , NF4 quantization method quantile probability density distribution function The KL divergence value between them, and then based on the minimum KL divergence among the three, select the corresponding quantization method to quantize the weight matrix parameters. The formula is as follows: ; ; ; Furthermore, step four specifically includes: the quantified large model generates structured executable code based on the user's traffic semantic instructions, which is used to call the predefined microservice API in the traffic control system. The system generates the corresponding traffic scene in real time through traffic simulation platforms such as CARLA.

[0066] In step 4, the structured executable code refers to the control command generated by the model based on traffic semantic instructions and conforming to a predefined format. The command can be directly used to call the microservice API in the traffic control system to trigger dynamic changes in traffic scene elements.

[0067] Furthermore, to achieve accurate mapping of semantic instructions to structured code, an instruction tuning dataset was constructed during the training phase. User natural language traffic instructions were mapped to standard prompt templates to form a training sample set of "user instruction - prompt template - output code" triplets. Each type of instruction contained at least 20 groups of samples to improve the model's generalization ability for different expressions.

[0068] In this embodiment, the publicly released WizardCoder model is selected as the pre-training basic model. WizardCoder is an open source large language model optimized based on the CodeGen architecture. It has good natural language understanding and code generation capabilities and is suitable for the text code generation task of traffic control instructions.

[0069] Furthermore, Prompt is a standardized function call format used to guide the model to output structured code that conforms to the system interface. An example is shown in Table 1:

[0070] Table 1 shows the conversion results of the user's input commands "add 3 cars" and "turn to sunny" in the prompt mapping and structured code output.

[0071] The fine-tuned and quantized model receives traffic instructions input by users and stably generates API call codes that meet system specifications based on the prompt matching logic learned during training. It also supports the generation of multiple API instruction combinations. For example, for the input "add 3 vehicles and turn on rainy mode", the model can output the combined code sequence AddVehicles(3);SetWeather(\"Rainy\") to complete the compound execution of multiple instructions. Furthermore, the generated control instructions are transmitted to the CARLA platform backend through the interface protocol WebSocket. The CARLA system will call the corresponding microservice module to render the changes of vehicles, roads, weather, traffic lights and other elements in real time in the 3D traffic simulation environment, forming a visual, controllable and interactive traffic scene. The results are as follows: Figure 3 As shown; In this embodiment, in order to verify the actual effect of the LoRA fine-tuning and adaptive quantization mechanism on the text-to-structured code generation model, a data set containing 500 standardized traffic semantic instructions was used to perform accuracy and inference efficiency comparison tests on the original WizardCoder model and the fine-tuned quantization model optimized by the method of the present invention. The test results are shown in Table 2:

[0072] As shown in Table 2, after processing using the method provided by this invention, the model's Top-1 accuracy in the structured traffic instruction generation task increased to 96.9%, a 2.2% improvement over the original, unoptimized model. Furthermore, the model size was compressed by over 90%; the model size was reduced from 3240MB to approximately 292MB, a compression rate of 90%. The inference response time was shortened from an average of 1210ms to 510ms, a 2.4x increase in inference speed, significantly improving the model's feasibility for deployment on edge devices or in-vehicle terminals.

[0073] Further, if Figure 2 As shown in the figure, a fine-grained performance comparison analysis was conducted on four typical traffic scene semantic instruction tasks. Figure 2 ART stands for Add Road Traffic, which adds traffic behavior; RN stands for Route Navigation, which is route navigation; TSC stands for Traffic Signal Control, which is signal light control; WCH stands for Weather Change, which is environmental weather change; WizardCoder-Base is the original WizardCoder model; WizardCoder-Ours is the optimized model of the embodiment of the present invention; and Execution Accuracy is the execution accuracy of the model.

[0074] Depend on Figure 2 It can be seen that the model optimized by the method of the present invention maintains a high execution accuracy in the above four types of tasks, especially in RN and TSC tasks, which is more significantly improved than the traditional unoptimized model, verifying the execution stability and practical value of the structured control code output by the model under the microservice structure in the traffic simulation system.

[0075] The schematic diagram of scene rendering and interaction effect of the generation control instruction in the CARLA simulation platform in the embodiment of the present invention is as follows: Figure 3 shown.

[0076] It should be noted that the present invention is not limited to the above-mentioned embodiments. The above-mentioned embodiments are merely examples, and any embodiments having substantially the same structure and effect as the technical concept within the scope of the technical solution of the present invention are all included in the technical scope of the present invention. In addition, without departing from the scope of the present invention, other embodiments that can be conceived by those skilled in the art and that combine some of the constituent elements in the embodiments are also included in the scope of the present invention.

Claims

1. A large-scale model efficient fine-tuning and adaptive quantization method for traffic scenarios, characterized by: The following steps are involved: Step 1: Use the loRA fine-tuning training method to freeze the weight values ​​of the pre-trained large model, and inject the weight matrix of the large model into the trainable rank decomposition matrix and perform rank decomposition; Step 2: Quantize the weight matrix and rank decomposition matrix, and calculate the quantiles of several quantization methods and their quantization probability density distribution functions respectively; The data in each weight matrix is ​​divided into blocks, and the dynamic energy equation method is used to eliminate abnormal and large values, obtain the cleaned data, and calculate the block probability density distribution function; Step 3: Use KL divergence to calculate the similarity between the block probability density distribution function and each quantized probability density distribution function, adaptively select the corresponding quantization method to quantize the weight matrix of the pre-trained large model, and finally obtain the fine-tuned quantized model; Step 4: The quantified large model generates structured executable code based on the user's traffic semantic instructions, and generates the corresponding traffic scene through real-time rendering on the traffic simulation platform.

2. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 1 is characterized in that: The first step specifically includes: using the loRA fine-tuning training method to freeze the weight values ​​of the pre-trained large model, and injecting the weight matrix of the multi-head attention module of the Transformer architecture in the pre-trained large model into the trainable rank decomposition matrix , and perform rank decomposition, decomposing into .

3. The method for efficient fine-tuning and adaptive quantization of large models for traffic scenarios according to claim 1 is characterized in that: The quantization of the weight matrix and the rank decomposition matrix specifically involves reducing the number of bytes in the data format stored in the matrix.

4. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 1 is characterized in that: The several quantization methods specifically include at least one of the INT4 quantization method, the FP4 quantization method and the NF4 quantization method.

5. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 4 is characterized in that: The INT4 quantization method is specifically to calculate the probability density distribution function of the quantile according to the quantized quantile and probability value. .

6. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 4 is characterized in that: The FP4 quantization method is specifically to calculate the probability density distribution function of the quantile according to the quantized quantile and probability value. .

7. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 4 is characterized in that: The NF4 quantization method is specifically to obtain the quantile probability density distribution function of the NF4 quantization method based on the quantized quantile and probability value. .

8. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 1 is characterized in that: The block probability density distribution function is calculated by dividing the weight matrix to be quantized into blocks and removing abnormal large values ​​and then normalizing the blocks, and then statistically calculating the probability density distribution of the data in the weight matrix to be quantized after normalization to obtain the block probability density distribution function. .

9. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 8, characterized in that: The elimination of abnormally large values ​​specifically includes: Step 1.1: Based on the input data , calculate the initial weight and initial dynamic energy; Step 1.2: Calculate the dynamic energy in the kth iteration separately and the dynamic energy threshold in the kth iteration ; Step 1.3: By comparison , mark abnormally large values, and update the weight value and dynamic energy according to the exponential decay formula; Step 1.4: Repeat the iteration until the convergence condition is met, and output the data without abnormally large values.

10. The method for efficient fine-tuning and adaptive quantization of a large model for traffic scenarios according to claim 1, characterized in that: The adaptive selection includes selecting a corresponding quantization method to quantize the weight matrix parameters based on the minimum KL divergence.