An impulse neural network end-to-end training method based on alternative gradient, a computing device and a storage medium

CN122528984APending Publication Date: 2026-08-07FOSHAN TONGGUANG TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-03-05
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

第一种为基于脉冲时序的局部学习规则(如脉冲时序依赖可塑性),该方法仅利用局部信息更新权重,无法利用全局误差信号优化网络

Benefits of technology

[0020](1)深层脉冲神经网络端到端训练。行为级仿真验证(基于 PyTorch 2.0,训练设备为单张 NVIDIA RTX 4090D 图形处理器)表明,本发明可稳定训练包含12层脉冲处理层的深层脉冲神经网络,训练损失从初始值8.59在5000步内收敛至2.59(困惑度(Perplexity,PPL)为13.3),无训练发散。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122528984A_ABST
    Figure CN122528984A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of artificial intelligence and neural network training, and provides a pulse neural network end-to-end training method based on a substitute gradient, a computing device and a storage medium. The method is aimed at the technical problem that a non-differentiable step activation function in a pulse neural network cannot use a standard back propagation algorithm, a hard threshold pulse generation mechanism is retained in a forward propagation stage to maintain the sparsity of binary pulses, and the derivative of the step function is replaced by a differentiable smooth substitute function in a back propagation stage to approximate a gradient flow. The method combines a parameter grouping weight decay strategy, mixed precision training, gradient accumulation, cosine annealing learning rate scheduling and layer-by-layer auxiliary loss weighting training, and realizes stable end-to-end training of a deep pulse neural network containing a leaky integration and a discharge neuron.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of artificial intelligence and neural network training technology, and in particular to an end-to-end training method, computing device and storage medium for spiking neural networks based on alternative gradients. Background Technology

[0002] Spiking neural networks use binary pulses for information transmission, unlike traditional artificial neural networks which use continuous floating-point values ​​for calculations. The core component of a spiking neural network is the leak-integration-discharge neuron, which generates discrete 0 / 1 pulse outputs through membrane potential accumulation and threshold comparison.

[0003] However, the pulse generation process is essentially a step function, whose derivative is zero everywhere except at the threshold point, where it becomes infinite. This non-differentiable property makes it impossible for the standard backpropagation algorithm to directly calculate the gradient of the loss function with respect to the parameters of the spiking neural network.

[0004] Several methods exist for training spiking neural networks. The first is based on local learning rules of impulse timing (such as impulse timing-dependent plasticity). This method only uses local information to update weights and cannot optimize the network using global error signals. The second is a conversion method from artificial neural networks to spiking neural networks, first training a traditional artificial neural network and then converting it to a spiking neural network. However, this conversion process introduces significant accuracy loss and is limited by the structure of the original network. The third is an alternative gradient method, using a smoothing function to approximate the derivative of the step function during the backpropagation phase.

[0005] Existing alternative gradient methods are mainly applied to shallow spiking neural networks (less than 10 layers). When applied to deep networks with more than 10 spiking layers, they face the following technical challenges: (1) The gradient decays layer by layer between multiple spiking functions, causing the amount of deep parameter updates to approach zero; (2) The spiking sparsity collapses during training, that is, the model loses the sparsity of spiking after training and degenerates into a dense continuous network; (3) The numerical stability is insufficient during training, causing the loss function to diverge.

[0006] Therefore, there is a need for an end-to-end training method that can stably train deep spiking neural networks with more than 12 spiking layers. This method should maintain the spiking sparsity without collapse throughout the training process and support language modeling tasks with large-scale vocabularies and long sequences. Summary of the Invention

[0007] To address the aforementioned technical problems, this application provides an end-to-end training method, computing device, and computer-readable storage medium for spiking neural networks based on alternative gradients.

[0008] In a first aspect, this application provides an end-to-end training method for a spiking neural network based on alternative gradients, characterized by comprising the following steps: A computing device including a processor and a memory performs the following operations: Step 1, constructing a spiking neural network model containing multiple pulse processing layers, each pulse processing layer containing at least one leak-integral-discharge neuron layer, wherein the leak-integral-discharge neuron layer generates sparse binary pulse signals through membrane potential accumulation and hard threshold comparison during forward computation; Step 2, performing forward propagation on the spiking neural network model, inputting training samples into the model and calculating the output, wherein in the leak-integral-discharge neuron layer, the forward propagation... The propagation process employs a non-differentiable step function to generate discrete pulse outputs; step three involves calculating the loss value between the model output and the training objective; step four involves performing backpropagation on the loss value, wherein when backpropagation passes through the leaky integral-firing neuron layer, the derivative of the step function is replaced with the derivative of a differentiable smooth substitution function. This smooth substitution function has a concentrated non-zero gradient interval near the pulse threshold, and the gradient approaches zero far from the threshold, allowing the gradient signal to pass through the pulse generation stage and be transmitted to the preceding parameters; step five involves updating all learnable parameters of the model using the gradient obtained from the backpropagation, completing one training iteration.

[0009] In a second aspect, this application provides a computing device including a processor and a memory, wherein the memory stores a program, and the processor executes the program to implement the method described in the first aspect.

[0010] Thirdly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.

[0011] In one possible implementation, the smoothing substitution function in step four is a scaled form of the derivative of the sigmoid (S-type activation function): g(x) = σ × sigmoid(σ × x) × (1 − sigmoid(σ × x)), where x is the difference between the membrane potential and the discharge threshold, and σ is the steepness hyperparameter. The technical effect of this substitution function is that when σ increases, the gradient of the substitution function is more concentrated near the threshold, closer to the true step function derivative; when σ decreases, the gradient coverage is wider, resulting in higher training stability. In another possible implementation, the smoothing substitution function in step four can also be a scaled form of the arctangent function derivative, specifically: g(x) = α / (2 × (1 + (π / 2 × α × x)²)), where x is the difference between the membrane potential and the discharge threshold, and α is an adjustable hyperparameter controlling the gradient width. The gradient distribution of this arctangent substitution function is inherently bounded. When the membrane potential is exactly equal to the threshold, the substitution gradient value is α / 2 and does not depend on the exponential operation of hyperparameters. This solves the problem of unstable gradient in the time direction caused by the time dimension gradient factor leak × (1 − spike ×threshold) being calculated as leak × (1 − σ × sigmoid × (1-sigmoid) ×threshold) instead of being constant zero in multilayer spiking neural networks.

[0012] In one possible implementation, step five employs a parameter grouping weight decay strategy. The model parameters are divided into two groups: the first group consists of weight matrix parameters (such as the projection matrix and embedding matrix), which are subject to weight decay; the second group consists of bias parameters, layer normalization parameters, and Bayesian prior probability parameters, which are not subject to weight decay. The technical effects of this grouping strategy are: preventing the Bayesian prior probability parameters from being regularized to zero (this parameter represents the word frequency distribution, and approaching zero will result in the loss of prior information); and preventing the layer normalization parameters from being regularized, which would cause the normalization function to fail.

[0013] In one possible implementation, the method employs a linear preheating plus cosine annealing learning rate scheduling strategy. Specifically, during the first W steps of training (preheating phase), the learning rate linearly increases from zero to a peak value η_max; after preheating and until training is complete, the learning rate decreases from η_max to η_min in a cosine function shape: η(t) = η_min + 0.5 ×(η_max − η_min) × (1 + cos(π × (t − W) / (T − W))), where t is the current training step number and T is the total training step number. The technical effect of the preheating phase is to prevent inaccurate gradient signals generated by the substitute gradient in the early stages of training from causing excessively large parameter updates under a large learning rate.

[0014] In one possible implementation, the method employs a mixed-precision training strategy. Matrix multiplication and convolution operations are performed using 16-bit half-precision floating-point (FP16) format during forward and backward propagation, while 32-bit full-precision floating-point (FP32) format is used for loss scaling and parameter updates. Before backpropagation, the loss value is multiplied by a scaling factor using a dynamic loss scaler to prevent small gradient values ​​from underflowing to zero in FP16 format. After parameter updates, the scaler dynamically adjusts the scaling factor based on whether gradient overflow (e.g., non-numerical or infinity) is detected. The technical advantage of this strategy is that it reduces the graphics processing unit (GPU) memory required for training by approximately 50%, enabling the training of a spiking neural network with approximately 168 million parameters on a single GPU with only 24 gigabytes of GPU memory.

[0015] In one possible implementation, the method employs a gradient accumulation strategy. The loss value at each step is divided by a preset number of accumulation steps, A, and A forward and backward propagation steps are performed consecutively to accumulate gradients. After each A-step accumulation, gradient clipping, parameter updates, and gradient zeroing are performed uniformly. The equivalent batch size of this strategy is the single-step batch size B × the number of accumulation steps A. The technical advantage is that it simulates large-scale training under limited GPU memory, improving training stability.

[0016] In one possible implementation, step five involves performing global gradient norm clipping before parameter updates. The global 2-norm of the gradients for all model parameters, ||g||², is calculated. When ||g||² exceeds a preset clipping threshold, all gradients are proportionally reduced: g' = g × threshold / ||g||². The effect is to prevent substituted gradients from generating abnormally large gradient values ​​at time steps where the membrane potential is close to the threshold.

[0017] In one possible implementation, the loss value in step three includes a weighted sum of the main loss and auxiliary losses. At each pulse processing layer, the candidate prediction probability distribution is calculated using a shared output mapping head, and the auxiliary cross-entropy loss for that layer is calculated with the training target. The auxiliary losses of each layer are weighted and summed using a power of a preset decay factor and then normalized. The auxiliary cross-entropy loss is calculated using a gradient checkpointing mechanism to avoid memory overflow caused by storing backpropagation graphs of multiple auxiliary losses simultaneously. The technical effect of this strategy is that it forces the shallow output of each pulse processing layer to also have a certain predictive ability, providing a supervisory signal for the information entropy-based early exit mechanism.

[0018] In one possible implementation, the method supports a distributed data-parallel training mode. The training dataset is equally divided according to the number of computing devices participating in the computation. Each computing device independently performs forward and backward propagation. Before parameter updates, gradient information across all computing devices is synchronized through a global gradient reduction operation, ensuring consistent model parameters across all devices. The equivalent batch size is calculated as: single-device batch size × cumulative steps × number of computing devices.

[0019] Compared with the prior art, the beneficial effects of the present invention include:

[0020] (1) End-to-end training of deep spiking neural networks. Behavioral simulation verification (based on PyTorch 2.0, training device is a single NVIDIA RTX 4090D graphics processor) shows that the present invention can stably train a deep spiking neural network containing 12 spiking processing layers. The training loss converges from the initial value of 8.59 to 2.59 within 5000 steps (perplexity (PPL) is 13.3), with no training divergence.

[0021] Initial (step 0) 8.59 5390 91.4% Preheat end (step 500) 3.61 36.8 91.0% Mid (step 2500) 2.85 17.2 90.1% Convergence (step 5000) 2.59 13.3 90.2%

[0022] (2) Sparsity stability. Throughout the training process, the pulse sparsity remained within the range of 89.5%-91.4%, with fluctuations of less than 2 percentage points, and no sparsity collapse phenomenon was observed. This result indicates that the combination of the alternative gradient method and the hard threshold pulse generation mechanism does not destroy the sparsity of the pulses during training.

[0023] (3) Memory efficiency. By combining mixed precision training and gradient accumulation, training of a spiking neural network with approximately 168 million parameters can be completed on a single graphics processor with 24 gigabytes of memory.

[0024] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0025] The following descriptions of the embodiments are for the purpose of helping to understand this application and do not limit the scope of protection of this application in any way. Attached Figure Description

[0026] Figure 1 The overall flowchart of the spiking neural network training method based on alternative gradients provided in the embodiments of this application is shown.

[0027] Figure 2 A schematic diagram comparing the derivatives of the alternative gradient function and the real step function provided in the embodiments of this application.

[0028] Figure 3 This is a schematic diagram of the parameter grouping weight decay strategy provided in the embodiments of this application.

[0029] Figure 4 The linear preheating plus cosine annealing learning rate scheduling curve provided for the embodiments of this application.

[0030] Figure 5 A flowchart illustrating mixed-precision training and dynamic loss scaling provided in an embodiment of this application.

[0031] Figure 6 This is a schematic diagram of the gradient accumulation process provided in an embodiment of this application.

[0032] Figure 7 The graphs showing the changes in training loss and impulse sparsity with the number of training steps provided in the embodiments of this application. Detailed Implementation

[0033] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0034] Example 1: Overall Training Method Flow

[0035] Reference Figure 1 This embodiment provides an end-to-end training method for a spiking neural network based on alternative gradients. The target network being trained is a pulse time-domain encoded sequence processing model containing 12 pulse processing layers, with approximately 100 million parameters.

[0036] Training employs a standard input-output pair supervised learning paradigm: from the same word sequence, the 1st to Tth words are taken as the input sequence, and the 2nd to (T+1th)th words are taken as the training target sequence corresponding to the input sequence. Both the input and training target sequences contain T words, where the training target corresponding to the i-th word in the input sequence is the (i+1th)-th word, where i is an integer from 1 to T. The loss function is cross-entropy loss, used to measure the deviation between the model's predicted probability distribution of the next word and the true word.

[0037] Each training iteration includes the following stages: (1) Forward propagation: The input word sequence is fed into the spiking neural network, and after pulse coding, 12 layers of sparse processing and Bayesian output, the log probability distribution on the vocabulary is obtained; (2) Loss calculation: The weighted sum of the main cross-entropy loss and the auxiliary loss of each layer is calculated and then divided by the number of gradient accumulation steps; (3) Backward propagation: Backward propagation is performed on the scaled loss value, and the alternative gradient is used in the threshold comparison of each leak integral-discharge neuron layer; (4) Gradient accumulation: Repeat (1)-(3) for a total of A steps; (5) Gradient clipping: The global gradient norm is calculated and clipped; (6) Parameter update: The parameters are updated using the Adaptive Moment Estimation with Weight Decay (AdamW) optimizer.

[0038] Example 2: Detailed Implementation of the Alternative Gradient Function

[0039] Reference Figure 2 This embodiment provides a detailed explanation of the forward and backward propagation mechanism of the alternative gradient.

[0040] In forward propagation, the alternative gradient module receives the membrane potential tensor V ∈ R^{B×S×D} and the scalar discharge threshold V_th = 1.0, and outputs a binary pulse tensor S = Θ(V − V_th), where Θ is the unit step function. Elements with a value of 1 in the output tensor indicate that the membrane potential in that dimension exceeds the threshold and generates a pulse, while elements with a value of 0 indicate that the membrane potential in that dimension does not reach the threshold. The forward propagation also saves the membrane potential tensor V and the threshold V_th to the computational graph context for use in backpropagation.

[0041] During backpropagation, the substitution gradient module retrieves the stored membrane potential tensor V and threshold V_th from the computation graph context. The substitution gradient is calculated as follows: first, the scaling offset u = σ × (V − V_th) is calculated, where σ = 10.0; then, the sigmoid activation function value s = sigmoid(u) is calculated; finally, the substitution gradient g = σ × s × (1 − s) is calculated. The upstream gradient ∂L / ∂S is multiplied element-wise with the substitution gradient g to obtain the gradient ∂L / ∂V = (∂L / ∂S)⊙g with respect to the membrane potential, and this gradient is then propagated downstream.

[0042] When σ = 10.0, the substitution gradient function has a significantly non-zero value in the interval |V − V_th| < 0.3, and a gradient value below 0.1 in the interval |V − V_th| > 0.5. This means that only neurons with membrane potentials close to the threshold contribute substantially to parameter updates, consistent with the characteristic of biological neurons being most sensitive near the threshold. As an alternative to the sigmoid-based substitution gradient function, the smooth substitution function can also be a scaled form of the arctangent derivative. In this implementation, the substitution gradient is calculated as: g = α / (2 × (1 + (π / 2 × α × (V − V_th))²)), where α is an adjustable hyperparameter controlling the gradient width. In backpropagation, the upstream gradient ∂L / ∂S is multiplied element-wise with the arctangent substitution gradient g to obtain the gradient with respect to the membrane potential, which is then propagated downstream. Compared to the sigmoid substitution form, the gradient distribution of the arctangent form is inherently bounded. When the membrane potential is exactly equal to the threshold, the substitution gradient value is α / 2, and its calculation does not depend on any exponential operations. This characteristic effectively solves the technical problem of unstable time-direction gradients in backpropagation of multilayer sigmoid neural networks, where the time-dimensional gradient factor leak × (1 − spike × threshold) is calculated as leak × (1 − σ × sigmoid × (1-sigmoid) × threshold) at the time of pulse firing instead of being constantly zero.

[0043] Example 3: Parameter Grouping Weight Decay Strategy

[0044] Reference Figure 3 This embodiment provides a detailed explanation of the parameter grouping strategy.

[0045] All learnable parameters in the model are iterated and divided into two groups based on whether the parameter names contain a specific keyword:

[0046] The first group (with weight decay applied, λ = 0.1): the projection weight matrix, embedding matrix, and output projection matrix of each layer. These parameter matrices have a large number of elements and a high risk of overfitting; weight decay serves as a L2 regularization.

[0047] The second group (without weight decay, λ = 0.0): Parameters whose names contain "bias," "norm," or "log_prior" (Bayesian prior probability parameter). The reason for not applying weight decay to these parameters is that the absolute value of the bias term itself should not be penalized; the scaling and offset parameters of the normalization layer are used to adjust the distribution, and penalizing their magnitude would weaken the normalization effect; the Bayesian prior probability parameter should learn the word frequency distribution from the data, and regularization would cause it to tend towards a uniform distribution, thus losing prior information.

[0048] The two sets of parameters mentioned above are passed to different parameter groups of the AdamW optimizer for management. The global parameters of the optimizer are: first-order moment decay rate β1 = 0.9, second-order moment decay rate β2 = 0.95.

[0049] Example 4: Detailed Implementation of Learning Rate Scheduling

[0050] Reference Figure 4 This embodiment provides a detailed description of the learning rate scheduling strategy.

[0051] Learning rate scheduling is divided into two phases:

[0052] Phase 1 (Linear warm-up, steps 0 to W = 500): The learning rate increases linearly from 0 to the peak η_max = 3 × 10⁻ 4 The learning rate per step is η(t) = η_max × t / W. The effect of the warm-up technique is that, in the early stages of training when the membrane potential distribution is not yet stable, using a small learning rate avoids excessive parameter updates caused by the inaccuracy of the substitute gradient.

[0053] Phase Two (Cosine Annealing, Steps W to T): The learning rate decreases from its peak according to the cosine function to η_min = 1 × 10⁻ 5 The specific formula is: η(t) = η_min + 0.5 × (η_max − η_min) × (1 + cos(π ×(t − W) / (T − W))). The technical advantage of cosine annealing is that, compared to linear decay and step decay, cosine annealing provides a smoother learning rate change, avoiding training oscillations caused by learning rate jumps.

[0054] Example 5: Mixed Precision Training and Dynamic Loss Scaling

[0055] Reference Figure 5 This embodiment provides a detailed explanation of the mixed precision training strategy.

[0056] Mixed-precision training switches the model's matrix operations to 16-bit half-precision (FP16) while maintaining 32-bit full precision (FP32) during parameter updates, in order to achieve a balance between precision and memory.

[0057] The workflow for dynamic loss scaling is as follows:

[0058] Step 1: Before backpropagation, multiply the loss value by a dynamic scaling factor s (the initial value is usually 2¹). 6 =65536).

[0059] Step 2: Perform backpropagation, at which point all gradients are amplified by a factor of s.

[0060] Step 3: Before updating the parameters, divide the gradient by the scaling factor s to restore the true gradient value.

[0061] Step 4: Check if the gradient contains non-numerical or infinite values. If it does, skip this parameter update and halve the scaling factor; if it does not, perform a normal update and attempt to double the scaling factor.

[0062] This strategy addresses a specific problem in training spiking neural networks: because the alternative gradient function produces extremely small gradient values ​​far from the threshold, in FP16 format (the smallest representable positive number is approximately 6 × 10⁻⁻⁻⁴), the gradient becomes extremely small. 8 These values ​​are prone to underflow to zero. Dynamic loss scaling magnifies these minimal gradient values ​​to the range that FP16 can represent by first amplifying and then restoring them.

[0063] Example 6: Gradient Accumulation Strategy

[0064] Reference Figure 6 This embodiment provides a detailed explanation of the gradient accumulation strategy.

[0065] Under conditions of limited video memory (a single graphics processor can only accommodate forward propagation with a batch size of B = 8), equivalent large-batch training can be achieved through gradient accumulation.

[0066] The specific process is as follows: Divide the loss value of each step by the cumulative number of steps A = 4 before performing backpropagation. Perform A = 4 consecutive forward and backward propagation steps, allowing the gradient to accumulate naturally in the optimizer. After accumulating A steps, perform gradient clipping and parameter updates, followed by gradient clearing. The equivalent batch size is B × A = 8 × 4 = 32.

[0067] For training spiking neural networks, large-batch training is particularly important: the binary nature of the pulse makes the gradient variance of a single sample larger (compared to continuous activation functions), and larger batches can reduce gradient noise through averaging effects.

[0068] Example 7: Training Results and Sparsity Analysis

[0069] Reference Figure 7 This embodiment performs quantitative analysis of the training results.

[0070] On a single NVIDIA RTX 4090D graphics processor (24 gigabytes of video memory), the above training method was used to train a pulse time-domain coding model containing approximately 168 million parameters and 12 pulse processing layers. The training dataset was the TinyStories collection of short English stories.

[0071] Loss convergence: The training loss decreased rapidly from the initial value of 8.59 (corresponding to perplexity 5390) to 3.61 (perplexity 36.8) after about 500 warm-up steps, and then decreased steadily during the cosine annealing stage, reaching 2.59 (perplexity 13.3) at 5000 steps.

[0072] Sparsity stability: The sparsity of the spiking neural network remained within the range of 89.5%-91.4% throughout the training process. Initially, the sparsity was approximately 91.4%, then slightly decreased to approximately 89.5% in the later stages of training before stabilizing. No sparsity collapse was observed, indicating that alternative gradient training does not destroy the sparsity properties of the spiking neural network.

[0073] Memory usage: Mixed precision training reduces peak memory usage from approximately 40 gigabytes to approximately 18 gigabytes, enabling training to be completed on a single consumer-grade graphics processor.

[0074] Example 8: Application Scenario Description

[0075] Application Scenario 1: Pre-training of large-scale spurious language models. This method can be directly used to train spurious language models containing billions of parameters. The trained model can be deployed to a general-purpose graphics processor, field-programmable gate array (FPGA), or application-specific integrated circuit (ASIC) for inference. In this scenario, the peak learning rate η_max can be scaled according to the model size using the ratio η_max ∝ 1 / √(number of parameters), while the weight decay λ remains constant at 0.1.

[0076] Application Scenario 2: Fine-tuning of Spiking Neural Networks. This involves fine-tuning a pre-trained spiking neural network on domain-specific data. In this scenario, the peak learning rate is reduced by an order of magnitude to 3 × 10⁻⁻. 5 The number of warm-up steps is reduced to 100, and the number of training steps is adjusted according to the amount of domain data. The steepness parameter σ, which replaces the gradient, can be increased from 10.0 to 20.0, making the gradient more concentrated near the threshold and reducing interference with the learned parameters.

[0077] Application Scenario 3: Multi-stage Progressive Training. When the model size is large, a multi-stage training strategy is adopted: the first stage uses short sequences (e.g., 128 words) to train until convergence; the second stage switches to medium-length sequences (e.g., 512 words) to continue training; the third stage uses the target length sequence (e.g., 2048 words) to complete the final training. Seamless transitions between stages are achieved through loading checkpoints. This strategy leverages the rapid iteration of the short sequence stage to help the model build basic representations, and then learns long-range dependencies through the long sequence stage.

[0078] Example 9: Detailed Implementation of Auxiliary Loss Weighted Training

[0079] This embodiment provides a detailed description of the auxiliary loss weighted training strategy.

[0080] After the forward propagation of each impulse processing layer is completed, the candidate prediction probability distribution of the layer is calculated using the continuous representation output of that layer through a shared output mapping head (using the same Bayesian output layer as the final layer), and the auxiliary cross-entropy loss of that layer is calculated with the training objective. The auxiliary loss of each layer is weighted as follows: w_i = β^(N−1−i), where N is the total number of impulse processing layers (N = 12 in this embodiment), i is the index of the current layer (starting from 0), and β is a preset decay factor (β = 0.5 in this embodiment). This weight allocation results in lower auxiliary loss weights for shallower layers and higher auxiliary loss weights for deeper layers, reflecting that the output of deeper layers contributes more to the final prediction.

[0081] The final training loss is: L_total = L_main + α × (1 / N) × Σᵢ w_i × L_aux_i, where L_main is the final layer main cross-entropy loss and α is the auxiliary loss weighting coefficient (α = 0.3 in this embodiment).

[0082] To prevent memory overflow caused by storing the backpropagation graphs of all 12 auxiliary loss layers simultaneously, the calculation of each auxiliary loss layer is performed using a gradient checkpointing mechanism. This mechanism does not save intermediate activation values ​​during forward propagation and recalculates them as needed during backpropagation, reducing the additional memory overhead caused by auxiliary losses from approximately 72 gigabytes to approximately 6 gigabytes.

[0083] The technical effect of this strategy is that it forces the output of each pulse processing layer to have a certain degree of independent predictive ability, providing necessary supervision signals for the early exit mechanism based on information entropy in the inference stage. Models trained without auxiliary loss only have predictive ability in the final layer output, and the early exit prediction quality of shallow layers is extremely poor.

[0084] Example 10: Computing Devices and Storage Media

[0085] This method can be executed on various computing devices, including but not limited to: general-purpose central processing units, graphics processing units, tensor processors, field-programmable gate arrays, application-specific integrated circuits (ASICs), cloud server clusters, and distributed training clusters equipped with multiple graphics processing units. The computing device includes a processor and a memory, wherein the memory stores a computer program implementing the method described above.

[0086] When using distributed training across multiple computing devices, gradient synchronization is achieved between these devices via a high-speed interconnect network. The training script automatically detects the number of computing devices and the network topology through a distributed initiator, creating independent training processes on each device. Each training process loads different slices of training data, independently performs forward and backward propagation, and synchronizes gradients through a global reduction operation before parameter updates. The communication backend prioritizes high-performance communication libraries, automatically falling back to a general-purpose communication library in case of failure.

[0087] Those skilled in the art should understand that the above embodiments are merely illustrative of the technical solutions of the present invention and not intended to limit it. Modifications and equivalent substitutions to the above embodiments without departing from the spirit and scope of the present invention should fall within the protection scope of the present invention.

Claims

1. An end-to-end training method for spiking neural networks based on alternative gradients, characterized in that, Includes the following steps: The following operations are performed by a computing device including a processor and memory: Step 1: Construct a spiking neural network model containing multiple pulse processing layers. Each pulse processing layer contains at least one leak integration-discharge neuron layer. The leak integration-discharge neuron layer generates sparse binary pulse signals in the forward calculation by accumulating membrane potential and comparing hard thresholds. Step 2: Perform forward propagation on the spiking neural network model, input the training samples into the model and calculate the output, wherein in the leak-integration-discharge neuron layer, forward propagation uses a non-differentiable step function to generate discrete pulse output; Step 3: Calculate the loss value between the model output and the training target; Step four, perform backpropagation on the loss value, wherein when backpropagation passes through the leak-integration-discharge neuron layer, the derivative of the step function is replaced with the derivative of a differentiable smooth substitution function. The smooth substitution function has a concentrated non-zero gradient interval near the pulse threshold and the gradient approaches zero far from the threshold, so that the gradient signal can pass through the pulse generation stage to the previous stage parameters. Step 5: Update all learnable parameters of the model using the gradients obtained from backpropagation to complete one training iteration.

2. The method as described in claim 1, characterized in that, The smoothing substitution function mentioned in step four is a scaled form of the derivative of the sigmoid activation function. The specific calculation process is as follows: multiply the difference between the membrane potential and the discharge threshold by an adjustable hyperparameter used to control the approximate steepness of the gradient to obtain an intermediate variable; calculate the output value of the sigmoid activation function of the intermediate variable, and multiply the output value by the difference between the output value and the intermediate variable; finally, multiply the obtained product by the adjustable hyperparameter to obtain the final derivative value of the smoothing substitution function.

3. The method as described in claim 1, characterized in that, The smoothing substitution function mentioned in step four is a scaled form of the derivative of the arctangent function. The specific calculation process is as follows: multiply the difference between the membrane potential and the discharge threshold by the adjustable hyperparameter used to control the gradient width and half of pi to obtain an intermediate variable; square the intermediate variable, add one, and take its reciprocal; finally, multiply the reciprocal by half of the adjustable hyperparameter to obtain the final derivative value of the smoothing substitution function.

4. The method as described in claim 1, characterized in that, Step 5 employs a parameter grouping weight decay strategy: all learnable parameters of the model are divided into two groups: the first group contains weight matrix parameters, to which a preset weight decay regularization is applied; the second group contains bias parameters, normalization layer parameters, and prior probability parameters, to which no weight decay is applied.

5. The method as described in claim 1, characterized in that, The method further includes a learning rate scheduling step: the learning rate performs linear warm-up in the initial stage of training, increasing linearly from zero to a preset peak learning rate; After the preheating is completed, cosine annealing is performed, and the learning rate decreases from the peak learning rate to the preset minimum learning rate in the shape of a cosine function.

6. The method as described in claim 1, characterized in that, The method employs a mixed-precision training strategy: matrix operations are performed using low-precision floating-point format in the main operations of forward and backward propagation, while high-precision floating-point format is used in loss scaling and parameter updates, wherein dynamic scaling is performed on the loss value before backpropagation.

7. The method as described in claim 1, characterized in that, The method employs a joint training strategy of gradient safety and auxiliary loss, including: gradient accumulation, dividing the loss value by a preset number of accumulation steps, continuously performing multiple backpropagation steps to accumulate gradients, and uniformly performing parameter updates and gradient zeroing after each accumulation reaches the preset number of steps, so that the equivalent batch size is the product of the single-step batch size and the preset number of steps; gradient norm clipping, calculating the global norm of the gradients of all model parameters before parameter updates, and when the global norm exceeds a preset clipping threshold, reducing all gradients proportionally to within the threshold; and auxiliary loss weighting, wherein the loss value in step three includes a weighted sum of the main loss and auxiliary loss, and the auxiliary loss is calculated by calculating the candidate prediction probability distribution of each impulse processing layer through a shared output mapping head, calculating the auxiliary cross-entropy loss of that layer with the training target, and normalizing the auxiliary loss of each layer after weighting and summing by a preset decay factor decreasing by the layer depth, and the auxiliary cross-entropy loss is calculated through a gradient checkpointing mechanism.

8. The method as described in claim 1, characterized in that, The method supports a distributed data parallel training mode: the training dataset is divided equally according to the number of computing devices involved in the computation, and each computing device independently executes the forward and backward propagation steps two to four. Before the parameter update in step five, the gradient information of all computing devices is synchronized through a global gradient reduction operation to keep the model parameters on each computing device consistent.

9. A computing device comprising a processor and a memory, the memory storing a program, wherein the processor executes the program to implement the method as described in any one of claims 1 to 8.

10. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any one of claims 1 to 8.