Spiking Neural Network Online Learning Automatic Compilation System
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-22
- Publication Date
- 2026-08-14
AI Technical Summary
[0003]然而,脉冲神经网络在线学习的工程化实现面临显著技术瓶颈,不同神经元模型(漏积分发放、适应性、电导型等)与突触模型(Delta、指数型、短时程可塑性等)对应的资格迹数学形式差异显著,必须逐个人工推导与编码实现,开发流程繁琐、复用性差、周期长,严重制约在线学习技术的规模化应用
在本发明中,通过统一建模原语与自动编译流程,使用户无需手工推导资格迹、雅可比矩阵及梯度更新规则,仅通过简洁接口即可完成任意神经元与突触模型的在线学习定义,模型代码量减少,开发周期从数天缩短至一小时内,大幅降低脉冲神经网络在线学习的技术门槛,使非专业开发者也能快速实现复杂在线学习应用。
Smart Images

Figure CN122569943A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence and neural network compilation system technology, specifically relating to an online learning automatic compilation system for spiking neural networks. Background Technology
[0002] Spiking Neural Networks (SNNs), as third-generation neural networks, transmit information through discrete pulse events. They possess advantages such as high biological rationality, excellent energy efficiency, and strong temporal information processing capabilities. Their online learning algorithms can achieve real-time incremental training, making them irreplaceable in edge computing and low-power real-time systems. Current mainstream online learning focuses on qualification trace updates and is compatible with various algorithms such as real-time recursive learning and qualification trace propagation, meeting the needs of continuous adaptive optimization of models in dynamic environments.
[0003] However, the engineering implementation of online learning using spiking neural networks faces significant technical bottlenecks. The mathematical forms of qualification traces corresponding to different neuron models (such as leaky integral firing, adaptive, and conductance-type) and synaptic models (such as Delta, exponential, and short-term plasticity) differ significantly. Each model must be manually derived and coded, resulting in a cumbersome development process, poor reusability, and long development cycle, which severely restricts the large-scale application of online learning technology.
[0004] While existing deep learning frameworks possess mature automatic differentiation capabilities, their design is geared towards offline backpropagation algorithms, making them incompatible with the forward gradient accumulation mode of online learning and unable to support online updates of eligibility traces. Furthermore, their computational graph storage and backward gradient mechanisms cannot meet the real-time requirements of online learning, necessitating manual implementation of gradient and eligibility trace logic by users. Simultaneously, existing frameworks lack a unified modeling abstraction for spur events, synaptic topology, and multi-state neurons, resulting in high programming complexity, poor code reusability, and difficulties in cross-hardware platform portability, hindering the full utilization of computational efficiency across different hardware. Summary of the Invention
[0005] The purpose of this invention is to provide an online learning automatic compilation system for spiking neural networks to solve the problems mentioned in the background art.
[0006] To achieve the above objectives, the present invention provides the following technical solution: an online learning automatic compilation system for spiking neural networks, comprising a unified modeling layer for model construction, an intermediate representation analysis layer, an automatic code generation layer, and a just-in-time compilation optimization layer; The unified modeling layer has three core modeling primitives built-in: hidden state primitives, parameter primitives, and connection primitives, as well as a synapse alignment modeling strategy. It is used to receive the neuron model, synapse model, and network topology definition of the spiking neural network input by the user. Based on the three core modeling primitives, it completes the standardized decomposition and description of the dynamic structure of the spiking neural network and outputs model definition code that conforms to the preset specifications. The intermediate representation analysis layer is used to receive the model definition code, perform intermediate representation tracing and computation graph analysis on the model definition code, extract the computational dependencies between hidden states, parameters, and connection variables in the model, complete the structural validity verification, and output the intermediate representation analysis results containing complete dependencies. The automatic code generation layer is used to receive the intermediate representation analysis results and automatically generate executable code for the entire online learning process according to the online learning algorithm selected by the user. The executable code includes Jacobian matrix calculation code, qualification trace recursive update code, parameter gradient calculation code, and neuron dynamics forward propagation code. The just-in-time compilation and optimization layer is used to receive the executable code, perform just-in-time compilation and optimization on the executable code for the target hardware platform, generate efficient executable machine code for the target hardware platform, and complete the cross-platform deployment of the spiking neural network online learning model.
[0007] As a preferred implementation, the three core modeling primitives of the unified modeling layer are defined as follows:
[0008] in, h t For the hidden state variables at the current moment, h t-1 Let t be the hidden state variable from the previous time step. I t Let f be the synaptic input current at the current moment, and f be the state update function; Parameter primitives are used to declare the weight parameters that need to be optimized through online learning, where each parameter variable θ∈R. m It is configured with dimension m, initialization method, and value constraints; Connection primitives are used to declare synaptic input variables and synaptic connection topology, describing the influence of presynaptic neuron activity on the input of postsynaptic neurons after weighted modulation. Each connection variable x∈R k The corresponding synaptic current calculation rule is as follows ; in, x t For the current connection variable, θ is the preset interaction operator, and θ is the corresponding weight parameter.
[0009] As a preferred embodiment, the synaptic alignment modeling strategy of the unified modeling layer includes a postsynaptic alignment mode and a presynaptic alignment mode; the postsynaptic alignment mode aligns synaptic variables along the postsynaptic neuron dimension, connecting variables... x tIt is a binary pulse vector, with all elements being non-negative, and is suitable for spiking neural network models of exponential synapses; The presynaptic alignment pattern aligns synaptic variables along the presynaptic neuron dimension, connecting variables. x t This represents the synaptic conductance value, and its elements are always non-negative. It is applicable to spiking neural network models of short-term plastic synapses with synaptic states.
[0010] In a preferred embodiment, the intermediate representation analysis layer incorporates a symbol tracing module, a primitive recognition module, a dependency analysis module, and a structure verification module. The steps for performing intermediate representation tracing and computation graph analysis are as follows: Step S1, Symbolic Tracing: The model definition code is executed by replacing actual numerical values with symbolic variables, all computational operations and data flow are recorded, and the model definition code is converted into a standardized intermediate representation of the computation graph; Step S2, Primitive Recognition: In the intermediate representation of the computation graph, identify the hidden state variables declared by the hidden state primitives, the weight parameter variables declared by the parameter primitives, and the connection variables declared by the connection primitives; Step S3, Dependency Analysis: Analyze the computational dependencies of each variable in the computation graph, and extract the hidden state self-dependencies, hidden state-parameter dependencies, and hidden state-connection dependencies; Wherein, the self-dependency of the hidden state is the hidden state h at the current time. t The hidden state h from the previous time step t-1 The dependency is used to calculate the hidden state Jacobian matrix; the hidden state-parameter dependency is the hidden state h at the current time step. t The dependence on the weight parameter θ is used to calculate the weight Jacobian matrix; Hidden state - the connection dependency is the hidden state h at the current time. t For the connection variable x t The dependency is used to compute the connectivity Jacobian matrix; Step S4, Structure Verification: Verify whether the extracted dependencies meet the preset requirements of the online learning algorithm. If the verification is successful, output the intermediate representation analysis results.
[0011] In a preferred embodiment, the specific rules for code generation performed by the automatic code generation layer are as follows: For the Jacobian matrix calculation code, automatic differentiation is performed based on the intermediate representation of the computation graph to generate the hidden state Jacobian. Compared to the weight of Jacobi The computational code automatically performs diagonal simplification on neuron models that meet the diagonal approximation conditions; For the recursive update code of the qualification trace, based on the recursive rules of the online learning algorithm selected by the user and combined with the Jacobian matrix calculation logic, the corresponding online recursive update code of the qualification trace is generated. For the parameter gradient calculation code, generate code that couples the external input learning signal with the qualification trace to obtain the weight parameters and update the gradient in real time; For the forward propagation code, optimized neuron dynamics update code, spike generation code, and state reset code are generated.
[0012] As a preferred implementation, the online learning algorithms supported by the automatic code generation layer include the diagonal approximation real-time recursive learning algorithm D-RTRL and the pre- and post-synaptic qualification trace propagation algorithm pp-prop; When the pp-prop algorithm is selected, the automatic code generation layer automatically generates the presynaptic qualification trace ε. x With postsynaptic qualification trace ε f The separate recursive update code; when the D-RTRL algorithm is selected, the automatic code generation layer automatically generates integrated recursive update code for the full qualification trace.
[0013] In a preferred embodiment, the just-in-time compilation optimization layer has a built-in CPU backend, GPU backend and TPU backend, and the compilation optimization includes operator fusion, memory layout optimization, loop unrolling and constant folding; The CPU backend generates optimized executable code that supports SIMD vectorized instructions and multi-threaded parallelism; the GPU backend generates GPU kernel code compatible with the CUDA / OpenCL standard, adapting to the GPU massively parallel computing architecture; the TPU backend generates intermediate representations compatible with the XLA standard, adapting to the tensor computing architecture of the tensor processing unit.
[0014] In a preferred embodiment, when the unified modeling layer receives the spiking neural network definition input by the user, it performs the following operations: declares the internal state variables of neurons and synapses based on hidden state primitives, declares the weight parameters that need to be optimized through online learning based on parameter primitives, and declares the synaptic input variables and synaptic connection topology based on connection primitives. Receive the synaptic alignment mode selected by the user, the synaptic alignment mode including postsynaptic alignment mode and presynaptic alignment mode; The postsynaptic alignment mode aligns synaptic variables along the postsynaptic neuron dimension, and the connection variables are binary pulse vectors with elements that are always non-negative. The presynaptic alignment pattern aligns synaptic variables along the presynaptic neuron dimension, and the connection variables are synaptic conductance values with elements that are always non-negative. Based on the declared variables and the selected synaptic alignment pattern, the standardized decomposition of the spiking neural network dynamics structure is completed, generating model definition code that conforms to the preset specifications.
[0015] In a preferred embodiment, the intermediate representation analysis layer incorporates four sequentially linked functional modules: symbol tracking, primitive recognition, dependency analysis, and structural verification. The symbol tracing module converts the received model definition code into a standardized intermediate representation of the computation graph. The primitive recognition module identifies the variables corresponding to the three types of core modeling primitives in the computation graph. The dependency analysis module parses the computation flow of variables in the computation graph and extracts the core dependencies. The structure verification module performs compliance verification on the dependencies and outputs the intermediate representation analysis results.
[0016] In a preferred embodiment, after receiving the intermediate representation analysis results, the automatic code generation layer adapts to the online learning rules selected by the user and automatically generates executable code for the entire online learning process of the spiking neural network. The executable code includes the execution code corresponding to neuron dynamics update, state recursive update, parameter update calculation and forward propagation.
[0017] Compared with the prior art, the beneficial effects of the present invention are: In this invention, by unifying modeling primitives and automatically compiling processes, users can complete the online learning definition of any neuron and synapse model without manually deriving qualification traces, Jacobian matrices, and gradient update rules, simply through a concise interface. This reduces the amount of model code and shortens the development cycle from several days to one hour, significantly lowering the technical threshold for online learning of spiking neural networks and enabling non-professional developers to quickly implement complex online learning applications.
[0018] In this invention, the system automatically generates code through intermediate representation analysis and formal verification, avoiding errors introduced by manual derivation and coding. The generated gradient calculation results are highly consistent with the accurate reference gradient, effectively ensuring the stability and convergence of online learning and significantly reducing debugging costs.
[0019] In this invention, the automatically generated code is deeply optimized through just-in-time compilation, and its running efficiency is comparable to that of manually optimized code, with no significant performance loss. At the same time, it supports efficient online learning rules, which can significantly reduce memory usage and is more suitable for resource-constrained scenarios such as edge computing and embedded systems.
[0020] In this invention, the system is compatible with various neuron models, including single-state and multi-state models, as well as multiple synapse models such as conventional synapses and short-term plastic synapses. Adding new neurons or synapse models requires no modification to the compilation core; they can be integrated simply through unified primitives. It possesses strong generalization ability and expansion space. Through three standardized primitives—hidden states, parameters, and connections—the dynamic structure of spiking neural networks is uniformly described. Combining presynaptic and postsynaptic alignment strategies, the system can standardize the data organization methods of different synapse models, ensuring modeling consistency and algorithm compatibility.
[0021] In this invention, the system supports real-time compilation and specialized optimization of multiple hardware backends such as CPU, GPU, and TPU, enabling one-time modeling, automatic adaptation, and efficient deployment across multiple platforms. It can be flexibly applied to various hardware environments such as cloud servers, edge devices, and neuromorphic chips. Attached Figure Description
[0022] Figure 1 This is a schematic diagram of the overall architecture of the compilation system of this invention; Figure 2 This is a schematic diagram of the three modeling primitives of the present invention; Figure 3 This is a flowchart illustrating the intermediate representation analysis process of the present invention; Figure 4 This is a flowchart of the automatic code generation process of the present invention; Figure 5 This is a comparison diagram of the synaptic alignment strategies of the present invention; Figure 6 This is a flowchart of the multi-platform compilation process of the present invention; Figure 7 This is a performance comparison chart of the present invention. Detailed Implementation
[0023] The present invention will be further described below with reference to embodiments.
[0024] The following embodiments are used to illustrate the present invention, but should not be used to limit the scope of protection of the present invention. The conditions in the embodiments can be further adjusted according to specific conditions, and simple improvements to the method of the present invention under the premise of the concept of the present invention are all within the scope of protection claimed by the present invention.
[0025] Please see Figures 1-7 This invention provides an online learning automatic compilation system for spiking neural networks, including a unified modeling layer for model building, an intermediate representation analysis layer, an automatic code generation layer, and a just-in-time compilation optimization layer; The unified modeling layer contains three core modeling primitives: hidden state primitives, parameter primitives, and connection primitives, as well as a synapse alignment modeling strategy. It is used to receive the neuron model, synapse model, and network topology definition of the spiking neural network from user input. Based on the three core modeling primitives, it completes the standardized decomposition and description of the dynamic structure of the spiking neural network and outputs model definition code that conforms to the preset specifications. The intermediate representation analysis layer is used to receive the model definition code, perform intermediate representation tracing and computation graph analysis on the model definition code, extract the computational dependencies between hidden states, parameters, and connection variables in the model, complete the structural validity verification, and output the intermediate representation analysis results containing complete dependencies. The automatic code generation layer receives intermediate representation analysis results and automatically generates executable code for the entire online learning process based on the user-selected online learning algorithm. The executable code includes Jacobian matrix calculation code, qualification trace recursive update code, parameter gradient calculation code, and neuron dynamics forward propagation code. The just-in-time compilation and optimization layer receives executable code, performs just-in-time compilation and optimization on the executable code for the target hardware platform, generates efficient executable machine code for the target hardware platform, and completes the cross-platform deployment of the spiking neural network online learning model.
[0026] The definitions of the three core modeling primitives of the unified modeling layer are as follows:
[0027] in, h t For the hidden state variables at the current moment, h t-1 Let t be the hidden state variable from the previous time step. I t Let f be the synaptic input current at the current moment, and f be the state update function; Parameter primitives are used to declare the weight parameters that need to be optimized through online learning, where each parameter variable θ∈R. m It is configured with dimension m, initialization method, and value constraints; Connection primitives are used to declare synaptic input variables and synaptic connection topology, describing the influence of presynaptic neuron activity on the input of postsynaptic neurons after weighted modulation. Each connection variable x∈R k The corresponding synaptic current calculation rule is as follows ; in, x t For the current connection variable, θ is the preset interaction operator, and θ is the corresponding weight parameter.
[0028] The unified modeling layer's synaptic alignment modeling strategy includes postsynaptic alignment and presynaptic alignment. The postsynaptic alignment mode aligns synaptic variables along the postsynaptic neuron dimension, connecting variables... x t It is a binary pulse vector, with all elements being non-negative, and is suitable for spiking neural network models of exponential synapses; Presynaptic alignment pattern aligns synaptic variables along the presynaptic neuron dimension, connecting variables x t This represents the synaptic conductance value, and its elements are always non-negative. It is applicable to spiking neural network models of short-term plastic synapses with synaptic states.
[0029] The intermediate representation analysis layer incorporates a symbol tracing module, a primitive recognition module, a dependency analysis module, and a structure verification module. Its steps for performing intermediate representation tracing and computation graph analysis are as follows: Step S1, Symbolic Tracing: The model definition code is executed by replacing actual numerical values with symbolic variables, all computational operations and data flow are recorded, and the model definition code is converted into a standardized intermediate representation of the computation graph; Step S2, Primitive Recognition: In the intermediate representation of the computation graph, identify the hidden state variables declared by the hidden state primitives, the weight parameter variables declared by the parameter primitives, and the connection variables declared by the connection primitives; Step S3, Dependency Analysis: Analyze the computational dependencies of each variable in the computation graph, and extract the hidden state self-dependencies, hidden state-parameter dependencies, and hidden state-connection dependencies; Wherein, the self-dependency of the hidden state is the hidden state h at the current time. t The hidden state h from the previous time step t-1 The dependency is used to calculate the hidden state Jacobian matrix; the hidden state-parameter dependency is the hidden state h at the current time step. t The dependence on the weight parameter θ is used to calculate the weight Jacobian matrix; Hidden state - the connection dependency is the hidden state h at the current time. t For the connection variable x t The dependency is used to compute the connectivity Jacobian matrix; Step S4, Structure Verification: Verify whether the extracted dependencies meet the preset requirements of the online learning algorithm. If the verification is successful, output the intermediate representation analysis results.
[0030] The specific rules for code generation executed by the automatic code generation layer are as follows: For the Jacobian matrix calculation code, automatic differentiation is performed based on the intermediate representation of the computation graph to generate the hidden state Jacobian. Compared to the weight of Jacobi The computational code automatically performs diagonal simplification on neuron models that meet the diagonal approximation conditions; For the recursive update code of the qualification trace, based on the recursive rules of the online learning algorithm selected by the user and combined with the Jacobian matrix calculation logic, the corresponding online recursive update code of the qualification trace is generated. For the parameter gradient calculation code, generate code that couples the external input learning signal with the qualification trace to obtain the weight parameters and update the gradient in real time; For the forward propagation code, optimized neuron dynamics update code, spike generation code, and state reset code are generated.
[0031] The online learning algorithms supported by the automatic code generation layer include the diagonal approximation real-time recursive learning algorithm D-RTRL and the pre- and post-synaptic qualification trace propagation algorithm pp-prop; When the pp-prop algorithm is selected, the automatic code generation layer automatically generates the presynaptic qualification trace ε. x With postsynaptic qualification trace ε f The separate recursive update code; when the D-RTRL algorithm is selected, the automatic code generation layer automatically generates a unified recursive update code for the full qualification trace.
[0032] The just-in-time compilation optimization layer has built-in CPU backend, GPU backend and TPU backend, and the compilation optimization includes operator fusion, memory layout optimization, loop unrolling and constant folding; The CPU backend generates optimized executable code that supports SIMD vectorized instructions and multi-threaded parallelism; the GPU backend generates GPU kernel code that is compatible with the CUDA / OpenCL standard and adapts to the GPU's massively parallel computing architecture. The TPU backend generates an intermediate representation compatible with the XLA standard, adapting to the tensor computation architecture of the tensor processing unit.
[0033] When the unified modeling layer receives the spiking neural network definition input by the user, it performs the following operations: declares the internal state variables of neurons and synapses based on hidden state primitives, declares the weight parameters that need to be optimized through online learning based on parameter primitives, and declares the synaptic input variables and synaptic connection topology based on connection primitives. Receive the synaptic alignment mode selected by the user. The synaptic alignment mode includes postsynaptic alignment mode and presynaptic alignment mode. Among them, the postsynaptic alignment mode aligns synaptic variables along the postsynaptic neuron dimension, and the connection variables are binary pulse vectors with elements that are always non-negative; The presynaptic alignment pattern aligns synaptic variables along the presynaptic neuron dimension, and the connection variables are synaptic conductance values with elements that are always non-negative. Based on the declared variables and the selected synaptic alignment pattern, the standardized decomposition of the spiking neural network dynamics structure is completed, generating model definition code that conforms to the preset specifications.
[0034] The intermediate representation analysis layer has four interconnected functional modules: symbol tracking, primitive recognition, dependency analysis, and structural verification. The symbol tracing module converts the received model definition code into a standardized intermediate representation of the computation graph. The primitive recognition module identifies the variables corresponding to the three types of core modeling primitives in the computation graph. The dependency analysis module parses the computation flow of variables in the computation graph and extracts the core dependencies. The structure verification module performs compliance verification on the dependencies and outputs the intermediate representation analysis results.
[0035] After receiving the intermediate representation analysis results, the automatic code generation layer adapts to the online learning rules selected by the user and automatically generates executable code for the entire online learning process of the spiking neural network. The executable code includes the execution code corresponding to neuron dynamics update, state recursion update, parameter update calculation and forward propagation.
[0036] Specifically, the system includes the following core components: Unified Modeling Layer: Provides three core modeling primitives—HiddenState, Parameter, and Connection—for decomposing and describing the dynamic structure of any spiking neural network.
[0037] Intermediate Representation Analysis Layer: By tracking and analyzing the intermediate representation (IR) of user-defined neuron and synapse models, the computational dependencies between hidden states, weight parameters, and connection variables are automatically extracted.
[0038] Automatic code generation layer: Based on the intermediate representation analysis results, automatically generate the Jacobian matrix calculation code, qualification trace update code, and gradient calculation code required by the online learning algorithm.
[0039] Just-in-Time (JIT) compilation optimization layer: Employs Just-in-Time (JIT) compilation technology to optimize code for the target hardware platform and generate efficient executable code.
[0040] This invention defines three core modeling primitives for a unified description of the dynamic structure of spiking neural networks: Definition 1 (HiddenState Primitive): Hiddenstate primitives are used to declare the internal state variables of neurons or synapses. Each hidden state variable h ∈ R n It has the following attributes: Dimension n: The dimension of the state variable; Initial value: The initial value of the state variable; Update function: A function that describes the evolution of state variables over time, ht = f(ht-1, ...).
[0041] Definition 2 (Parameter): The parameter primitive is used to declare the weight parameters that need to be optimized through learning. Each parameter variable θ ∈ R m It has the following attributes: Dimension m: The dimension of the parameter; Initialization method: parameter initialization strategy; Constraints: Parameter value constraints (such as non-negativity, boundedness, etc.).
[0042] Definition 3 (Connection Primitive): Connection primitives are used to declare synaptic input variables that describe the effect of presynaptic neuron activity on postsynaptic neurons after weighted modulation. Each connection variable x ∈ R k express: Synaptic current calculation: ,in For interactive operators; Connection topology: describes the connectivity between presynaptic and postsynaptic neurons.
[0043] Based on the above three primitives, the dynamics of any spiking neural network can be uniformly expressed as:
[0044] This invention provides two synaptic alignment modeling strategies to adapt to different synaptic models: Strategy 1 (AlignPost): Aligns synaptic variables along the postsynaptic neuron dimension. Suitable for simple synaptic models such as exponential synapses. In this case, the connection variable xt represents a binary impulse vector, with all elements being non-negative.
[0045] Strategy 2 (AlignPre): Aligns synaptic variables along the presynaptic neuron dimension. Suitable for complex synaptic models with synaptic states, such as short-term plasticity synapses. In this case, the connection variable x... t It represents synaptic conductance, which is always non-negative.
[0046] Both strategies share the characteristic that the connection variable x t The elements have the same sign (all are non-negative), a characteristic that is crucial for subsequent optimization of online learning algorithms.
[0047] The compilation system of this invention automatically analyzes user-defined neuron and synapse models through intermediate representation (IR) tracing technology.
[0048] The specific process is as follows: Step 1, Symbolic Tracing: Convert the user-defined update function into a computational graph representation. The system uses symbolic variables to replace actual numerical values, executes the update function, and records all computational operations and data flow.
[0049] Step 2, Primitive Identification: Identify three types of modeling primitives in the computation graph: Hidden state variables are declared using the HiddenState primitive; weight parameters are declared using the Parameter primitive; and connection variables are declared using the Connection primitive.
[0050] Step 3, Dependency Analysis: Analyze the dependencies between variables in the computation graph and extract the following key information: Hidden state self-dependency: h t For h t-1 The dependencies are used to calculate the hidden state Jacobian matrix; Hidden state - parameter dependency: h t The dependence on θ is used to calculate the weight Jacobian matrix; Hidden state - join dependency: h t For x t The dependencies are used to calculate the connection Jacobian matrix.
[0051] Step 4, Structure Verification: Verify whether the extracted dependencies meet the requirements of the online learning algorithm. For example, verify whether the hidden state Jacobian matrix has a block diagonal structure and whether the weight Jacobian matrix can be decomposed into a Kronecker product.
[0052] Based on the intermediate representation analysis results, the compilation system of this invention automatically generates the following code: Jacobian matrix calculation code: Automatically calculates derivatives based on the computation graph to generate the Jacobian matrix for calculating the hidden states. And weight Jacobi The code automatically applies diagonal simplification to models that meet the diagonal approximation criteria.
[0053] Qualification trace update code: Automatically generate recursive update code for the qualification trace based on the selected online learning algorithm (D-RTRL or pp-prop). For the pp-prop algorithm, generate the presynaptic qualification trace ε. x and postsynaptic qualification trace ε f Separate update code.
[0054] Gradient calculation code: Generates code that combines the learned signal with the qualification trace to calculate the gradient of the parameters.
[0055] Forward propagation code: Generates optimized neuron dynamics update code, including operations such as spike generation and state reset.
[0056] This invention employs Just-In-Time (JIT) compilation technology to compile the generated code into efficient executable code for the target hardware platform. CPU backend: Generates optimized code that utilizes SIMD vectorized instructions and supports multi-threaded parallelism.
[0057] GPU backend: Generates CUDA / OpenCL kernel code, leveraging the massively parallel computing capabilities of the GPU.
[0058] TPU backend: Generates TPU-compatible XLA intermediate representations, supporting tensor processing unit acceleration.
[0059] The compilation system automatically performs the following optimizations: operator fusion, memory layout optimization, loop unrolling, constant folding, etc., to maximize runtime efficiency.
[0060] Example 1: Automatic Compilation of LIF Neuron Model User model definition This embodiment demonstrates how to define and compile a Lack-of-Flight (LIF) neuron model using the compilation system of this invention. Users only need to declare variables and update rules using modeling primitives: Code example (pseudocode): class LIFNeuron: # Declare hidden state variables v = HiddenState(shape=(N,), init=0.0) # Membrane potential # Declare learnable parameters w = Parameter(shape=(N, M), init='normal') # Declare connection variables (postsynaptic alignment) x = Connection(mode='AlignPost') def update(self, spike_in): # Calculate synaptic current I = self.w @ spike_in # Membrane potential update self.v = beta * self.v * (1 - self.spike) + I # Pulse Generation self.spike = (self.v > v_th).float() return self.spike Compilation process: The compilation system executes the following processing flow: Step 1 Symbolic Tracing: The system converts the update function into a computation graph and identifies: Hidden state variable: v (membrane potential) Parameter variable: w (synaptic weight) Connection variable: spike_in (input pulse) Step 2 Dependency Analysis: Extract Dependencies: Hidden state self-dependency:
[0061] Weight dependency:
[0062] Step 3 Code Generation: Automatically generate D-RTRL / pp-prop qualification trace update code: # Automatically generated qualification trace update code (pp-prop) epsilon_x = alpha * epsilon_x + spike_in epsilon_f = alpha * D_t * epsilon_f + (1-alpha) * D_f # Where D_t = beta * (1 - spike_prev), D_f = 1
[0063] Example 2: Automated Compilation and GPU Deployment of Complex Neuron Models This example demonstrates the compiler system's support for complex neuron models with multiple state variables. The adaptive leaky integral firing (ALIF) neuron is used as an example: class ALIFNeuron: # Declaration of multi-state variables v = HiddenState(shape=(N,)) # Membrane potential g = HiddenState(shape=(N,)) # Synaptic conductance a = HiddenState(shape=(N,)) # Adaptation variable w = Parameter(shape=(N, M)) x = Connection(mode='AlignPost') def update(self, spike_in): I = self.w @ spike_in self.g = beta_g * self.g + I self.v = beta_v * self.v * (1-self.spike) + self.g - self.a self.a = beta_a * self.a + gamma * self.spike self.spike = (self.v > v_th).float() return self.spike Automatically generated block-diagonal Jacobian: The compilation system automatically identifies that the ALIF neuron has d=3 state variables (v, g, a) and generates a 3×3 block-diagonal form of the hidden state Jacobian matrix.
[0064] GPU Deployment and Performance Verification: The compilation system deploys the generated code to the GPU platform, and the experimental verification results are as follows:
[0065] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. An online learning automatic compilation system for spiking neural networks, characterized in that, It includes a unified modeling layer for model building, an intermediate representation analysis layer, an automatic code generation layer, and a just-in-time compilation optimization layer; The unified modeling layer has three core modeling primitives built-in: hidden state primitives, parameter primitives, and connection primitives, as well as a synapse alignment modeling strategy. It is used to receive the neuron model, synapse model, and network topology definition of the spiking neural network input by the user. Based on the three core modeling primitives, it completes the standardized decomposition and description of the dynamic structure of the spiking neural network and outputs model definition code that conforms to the preset specifications. The intermediate representation analysis layer is used to receive the model definition code, perform intermediate representation tracing and computation graph analysis on the model definition code, extract the computational dependencies between hidden states, parameters, and connection variables in the model, complete the structural validity verification, and output the intermediate representation analysis results containing complete dependencies. The automatic code generation layer is used to receive the intermediate representation analysis results and automatically generate executable code for the entire online learning process according to the online learning algorithm selected by the user. The executable code includes Jacobian matrix calculation code, qualification trace recursive update code, parameter gradient calculation code, and neuron dynamics forward propagation code. The just-in-time compilation and optimization layer is used to receive the executable code, perform just-in-time compilation and optimization on the executable code for the target hardware platform, generate efficient executable machine code for the target hardware platform, and complete the cross-platform deployment of the spiking neural network online learning model.
2. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: The definitions of the three core modeling primitives of the unified modeling layer are as follows: : in, h t For the hidden state variables at the current moment, Let t be the hidden state variable from the previous time step. I t Let f be the synaptic input current at the current moment, and f be the state update function; Parameter primitives are used to declare the weight parameters that need to be optimized through online learning, where each parameter variable θ∈R. m It is configured with dimension m, initialization method, and value constraints; Connection primitives are used to declare synaptic input variables and synaptic connection topology, describing the influence of presynaptic neuron activity on the input of postsynaptic neurons after weight modulation. Each connection variable x∈ℝ k The corresponding synaptic current calculation rule is as follows ; in, x t For the current connection variable, For the preset interaction operator, These are the corresponding weight parameters.
3. The online learning automatic compilation system for spiking neural networks according to claim 2, characterized in that: The synaptic alignment modeling strategy of the unified modeling layer includes a postsynaptic alignment mode and a presynaptic alignment mode; the postsynaptic alignment mode aligns synaptic variables along the postsynaptic neuron dimension, connecting variables... x t It is a binary pulse vector, with all elements being non-negative, and is suitable for spiking neural network models of exponential synapses; The presynaptic alignment pattern aligns synaptic variables along the presynaptic neuron dimension, connecting variables. x t This represents the synaptic conductance value, and its elements are always non-negative, making it suitable for spiking neural network models with synaptic states.
4. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: The intermediate representation analysis layer incorporates a symbol tracing module, a primitive recognition module, a dependency analysis module, and a structure verification module. Its steps for performing intermediate representation tracing and computation graph analysis are as follows: Step S1, Symbolic Tracing: The model definition code is executed by replacing actual numerical values with symbolic variables, all computational operations and data flow are recorded, and the model definition code is converted into a standardized intermediate representation of the computation graph; Step S2, Primitive Recognition: In the intermediate representation of the computation graph, identify the hidden state variables declared by the hidden state primitives, the weight parameter variables declared by the parameter primitives, and the connection variables declared by the connection primitives; Step S3, Dependency Analysis: Analyze the computational dependencies of each variable in the computation graph, and extract the hidden state self-dependencies, hidden state-parameter dependencies, and hidden state-connection dependencies; Wherein, the self-dependency of the hidden state is the hidden state h at the current time. t The hidden state h from the previous time step t-1 The dependency is used to calculate the hidden state Jacobian matrix; the hidden state-parameter dependency is the hidden state h at the current time step. t The dependence on the weight parameter θ is used to calculate the weight Jacobian matrix; Hidden state - the connection dependency is the hidden state h at the current time. t For the connection variable x t The dependency is used to compute the connectivity Jacobian matrix; Step S4, Structure Verification: Verify whether the extracted dependencies meet the preset requirements of the online learning algorithm. If the verification is successful, output the intermediate representation analysis results.
5. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: The specific rules for code generation executed by the automatic code generation layer are as follows: For the Jacobian matrix calculation code, automatic differentiation is performed based on the intermediate representation of the computation graph to generate the hidden state Jacobian. Compared to the weight of Jacobi The computational code automatically performs diagonal simplification on neuron models that meet the diagonal approximation conditions; For the recursive update code of the qualification trace, based on the recursive rules of the online learning algorithm selected by the user and combined with the Jacobian matrix calculation logic, the corresponding online recursive update code of the qualification trace is generated. For the parameter gradient calculation code, generate code that couples the external input learning signal with the qualification trace to obtain the weight parameters and update the gradient in real time; For the forward propagation code, optimized neuron dynamics update code, spike generation code, and state reset code are generated.
6. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: The online learning algorithms supported by the automatic code generation layer include the diagonal approximation real-time recursive learning algorithm D-RTRL and the pre- and post-synaptic qualification trace propagation algorithm pp-prop. When the pp-prop algorithm is selected, the automatic code generation layer automatically generates the presynaptic qualification trace ε. x With postsynaptic qualification trace ε f The separate recursive update code; when the D-RTRL algorithm is selected, the automatic code generation layer automatically generates integrated recursive update code for the full qualification trace.
7. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: The just-in-time compilation optimization layer has a built-in CPU backend, GPU backend and TPU backend, and the compilation optimization includes operator fusion, memory layout optimization, loop unrolling and constant folding. The CPU backend generates optimized executable code that supports SIMD vectorized instructions and multi-threaded parallelism; the GPU backend generates GPU kernel code compatible with the CUDA / OpenCL standard, adapting to the GPU massively parallel computing architecture; the TPU backend generates intermediate representations compatible with the XLA standard, adapting to the tensor computing architecture of the tensor processing unit.
8. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: When the unified modeling layer receives the spiking neural network definition input by the user, it performs the following operations: declares the internal state variables of neurons and synapses based on hidden state primitives, declares the weight parameters that need to be optimized through online learning based on parameter primitives, and declares the synaptic input variables and synaptic connection topology based on connection primitives. Receive the synaptic alignment mode selected by the user, the synaptic alignment mode including postsynaptic alignment mode and presynaptic alignment mode; The postsynaptic alignment mode aligns synaptic variables along the postsynaptic neuron dimension, and the connection variables are binary pulse vectors with elements that are always non-negative. The presynaptic alignment pattern aligns synaptic variables along the presynaptic neuron dimension, and the connection variables are synaptic conductance values with elements that are always non-negative. Based on the declared variables and the selected synaptic alignment pattern, the standardized decomposition of the spiking neural network dynamics structure is completed, generating model definition code that conforms to the preset specifications.
9. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: The intermediate representation analysis layer has four interconnected functional modules: symbol tracking, primitive recognition, dependency analysis, and structural verification. The symbol tracing module converts the received model definition code into a standardized intermediate representation of the computation graph. The primitive recognition module identifies the variables corresponding to the three types of core modeling primitives in the computation graph. The dependency analysis module parses the computation flow of variables in the computation graph and extracts the core dependencies. The structure verification module performs compliance verification on the dependencies and outputs the intermediate representation analysis results.
10. The online learning automatic compilation system for spiking neural networks according to claim 1, characterized in that: After receiving the intermediate representation analysis results, the automatic code generation layer adapts to the online learning rules selected by the user and automatically generates executable code for the entire online learning process of the spiking neural network. The executable code includes the execution code corresponding to neuron dynamics update, state recursion update, parameter update calculation and forward propagation.