Computation graph description method, computer equipment and storage medium
Defining the computational graph structure and constructing the generative language syntax rules through a declarative programming language solves the problem of difficulty in quickly building and adjusting deep learning networks with existing technologies, enabling efficient network model development and use, which is suitable for the needs of industry and research fields.
Patent Information
- Application Number
- CN202410776826.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-10-01
AI Technical Summary
It is difficult to quickly build and adjust the network structure of existing deep learning frameworks, especially for neural networks with non-feedforward structures, such as RNN or LSTM, which are neither easy to describe nor suitable for beginners to use.
Use a declarative programming language to define the calculation graph structure, build the syntax rules of the calculation graph generation language, and translate the writing examples into intermediate code or target code through the compilation method. Design a structured language to abstract the calculation graph structure and separate structural design and concreteness. use.
It significantly reduces the development and adjustment time of deep learning network models, improves the creation and utilization efficiency of users at all levels, and simplifies the description and learning process of network structure.
Smart Images

Figure CN118733048A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of combining computer programming language and deep learning technology, and specifically, to a computational graph description method, a computer device, and a storage medium. Background Art
[0002] With the rise of deep learning technology, many deep learning frameworks have gradually increased support for multiple languages and multiple platforms. For example, PyTorch and TensorFlow support the use of Java, C++, and Python to build deep learning networks. Generally speaking, current deep learning frameworks describe network structures in two ways: one is to use a configuration file to linearly list all feedforward layers. This method is simple and clear, but it cannot describe non-feedforward neural networks, such as RNN or LSTM. The other method only uses the API to construct the entire neural network structure. This method is flexible and changeable, but it is difficult for beginners to use, and it is also difficult to formally describe the entire structure of the entire network.
[0003] At present, the field of deep learning frameworks is in urgent need of a technical method that can not only meet the needs of the industrial field to quickly build mature networks from scratch, but also meet the needs of the research field to try to improve the network from the details, and can easily describe the network structure and be simple to get started and learn quickly. Summary of the invention
[0004] In view of the defects in the prior art, the purpose of the present invention is to provide a computational graph description method, a computer device and a storage medium. The method of the present invention can greatly reduce the time for developing a deep learning network model and adjusting the network structure, and improve the efficiency of users at all levels in creating and using deep learning network models.
[0005] To solve the above problems, the technical solution of the present invention is:
[0006] A computational graph description method includes the following steps:
[0007] Define the computational graph structure based on a declarative programming language, build the grammar rules for the computational graph generation language, and write examples that describe the computational graph structure;
[0008] The compilation method is used to parse the written instance and translate the written instance into the required intermediate code, target code or computational graph structure instance.
[0009] Preferably, the steps of defining the computational graph structure based on a declarative programming language, constructing the computational graph generation language grammar rules, and writing a writing instance describing the computational graph structure specifically include:
[0010] Determine the symbol domain of the lexical unit according to a preset language model;
[0011] Determine the language grammar that describes the computational graph structure based on the preset language model;
[0012] Determine ambiguity rules based on established language grammar;
[0013] Determine the language semantics that describe the computational graph structure based on the preset language model;
[0014] The processing steps for determining grammatical errors based on the grammar;
[0015] Semantic errors are determined based on a preset language model.
[0016] Furthermore, the present invention also provides a computer device, comprising a processor and a memory for storing executable instructions of the processor, wherein the processor is configured to execute the computational graph description method as described above by executing the executable instructions.
[0017] Furthermore, the present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store program code, and the program code is used to execute the calculation graph description method as described above.
[0018] Compared with the prior art, the computational graph description method described in the present invention, by abstracting the computational graph, designs a structured language that can describe the structure of the computational graph and is independent of general programming languages, thereby separating the structural design of the computational graph from its specific use. This can greatly reduce the time for developing deep learning network models and adjusting the network structure, and improve the efficiency of users at all levels in creating and using deep learning network models. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0020] Figure 1 It is a flowchart of a method for describing a computational graph in an embodiment of the present invention;
[0021] Figure 2 A flow chart of a method for constructing a declarative programming language in an embodiment of the present invention;
[0022] Figure 3 is a flow chart of an execution method of a compiler in an embodiment of the present invention;
[0023] Figure 4 FIG. 4 is a flowchart of the process of determining a grammatical error in an embodiment of the present invention. DETAILED DESCRIPTION
[0024] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0025] The present invention provides a computational graph description method, which is applied to a computer device, which may be a terminal or a server. The terminal may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server may be an independent server or a server cluster composed of multiple servers. Specifically, Figure 1 As shown, the method comprises the following steps:
[0026] S101: Define the computational graph structure based on the declarative programming language, build the computational graph generation language grammar rules, and write examples to describe the computational graph structure;
[0027] Among them, the computational graph is a graph that describes mathematical calculations, in which nodes represent variables and operations, and edges represent the dependencies between nodes, forming a directed acyclic graph. This graph can use a series of node calculations and data transfer to complete the entire calculation process.
[0028] Programming language refers to a formal language used to define computer programs, used to issue instructions to computers, a computer language that allows programmers to accurately define the data that the computer needs to use, and accurately define the actions that should be taken in different situations. The declarative programming language used in the present invention belongs to a branch of programming languages. It adopts a declarative programming paradigm, that is, it only describes the structure of the target, rather than defining the running process. In this embodiment, the computer device will write a writing instance describing the calculation graph structure based on the declarative programming language.
[0029] Specifically, Figure 2 As shown, in step S101, the calculation graph structure is defined based on the declarative programming language, and the calculation graph generation language grammar rules are constructed, including the following steps:
[0030] S201: Determine the symbol domain of a lexical unit according to a preset language model;
[0031] The language model includes a part for describing the structure of a computational graph and a part for modifying the structure of the computational graph. The part for describing the structure of the computational graph includes one or more nodes and subgraphs; the nodes include operators, variables, and literals.
[0032] The operator is a node declared by an identifier that accepts one or more inputs and provides one or more outputs; a variable is a node that provides one input, one output, and stores modifiable data; a literal is a node that provides zero inputs, one output, and stores data that cannot be modified.
[0033] Furthermore, the operator includes a system default operator and a user-defined operator;
[0034] The user-defined operator is composed of one or more system default operators or operations that support default operations, and the combination refers to the combination of procedures, functions, methods or statements in the computer.
[0035] Furthermore, the variable includes a declarator, a name and an accompanying operation, wherein the declarator describes the specific role of the variable in the subgraph, the accompanying operation describes the operation that needs to be embedded in the computational graph during the implementation of the computation, and the name uses but is not limited to a string or a number.
[0036] Furthermore, the literal type may be one of a positive integer, a real number, an array, a tensor, and a string.
[0037] The subgraph includes declared subgraphs, generated subgraphs and introduced subgraphs, wherein the declared subgraph is formed by connecting multiple subgraphs or nodes by connecting symbols, and the number of connected subgraphs and nodes is one or more. The declared subgraph can be named or copied, and the named subgraph keeps the instance unchanged; the copied subgraph creates a new instance of the same structure as the subgraph.
[0038] The subgraph is generated by logic symbols according to operation conditions, wherein the logic symbols include loop symbols and judgment symbols, and the generation method comprises:
[0039] Generate a given number of subgraphs by loop unrolling;
[0040] Generate a fixed number of subgraphs using given initial and final values in a cyclic and progressive manner;
[0041] Generate subgraph A or subgraph B through logical judgment;
[0042] Select a generation from multiple given subgraphs through logical multiple judgments.
[0043] The generated body is a composite expression of a subgraph and a label, wherein the label is an embedded structure for outputting a process-oriented expression result and can appear at any position in the generated body. The process-oriented expression is an expression similar to the C language structure, wherein the syntax, variables, operator precedence, operator associativity and calculation rules are similar to those of the C language; wherein the variable source is the variable declared in the generated subgraph syntax or the variable provided by the general programming language runtime that compiles this language instance. General programming languages include but are not limited to python, java or C / C++.
[0044] Furthermore, the introduced subgraph includes introducing a system computation graph and introducing a user-defined computation graph, wherein the system computation graph is a built-in computation graph structure provided by an instance of a language implementation; and the user computation graph is an external computation graph structure obtained by a user creating a new computation graph or modifying an existing computation graph through this instance.
[0045] Furthermore, the modification of the computation graph structure includes one or more modifications to the computation graph structure, and the modification methods include:
[0046] Modify the node itself through assignment statements;
[0047] Use companion statements to modify the behavior of a node during calculation.
[0048] The lexical unit is a basic symbol that constitutes the grammar, which is composed of at least one printable symbol and is the smallest grammatical unit that cannot be divided in language processing. The setting method of the symbol domain where the lexical unit is located includes description rules based on regular expression language, description rules based on Backus-Naur form, description rules based on a certain finite automaton or other description rules. In one embodiment, the setting method of the symbol domain where the lexical unit is located is based on regular expression language and logical judgment mode, and the specific rules set based on regular expression include:
[0049] (1) Null character: (null character | tab character | newline character) +
[0050] (2) String: "Any character +"
[0051] (3) Identifiers and keywords: characters (characters | numbers) *
[0052] (4) Positive integer: number +
[0053] (5) Real number: [+-]? number+(.number+)? ([Ee][+-]?number)?
[0054] (6) Logical comparison: >|>=|<|<=|==|! =
[0055] (7) Connector: ->|=>
[0056] (8) Array: [(null character) real number (null character)(,(null character) real number (null character))*]
[0057] (9) Four arithmetic operations: +|-|*| /
[0058] (10) Sub-image area: (any character +)
[0059] (11) Template area: <any character+>
[0060] (12) Subgraph properties:.
[0061] (13)Declaration operator: @|$
[0062] (14) Accompaniment:
[0063] (15) Separator: vertical bar |,
[0064] The above character may be one of uppercase English letters, lowercase English letters and underscores; the above number may be one of Arabic numerals.
[0065] The specific rules set based on the logical judgment method include:
[0066] (1) Tensor: A valid tensor is a multidimensional data set with the same number of data in each component of each dimension.
[0067] The above data can be real numbers, complex numbers, or tensors.
[0068] S202: Determine a language grammar describing the computational graph structure according to a preset language model;
[0069] The language grammar is a tool that provides accurate and easy-to-understand syntax descriptions for programming languages, and is used to construct an effective syntax analyzer to determine whether a source program grammatically satisfies a preset language model.
[0070] The setting methods of language grammar include description rules based on Backus-Naur Form, description rules based on context-free grammar and description rules based on context-sensitive grammar.
[0071] In one embodiment, the setting of the language grammar is based on the description rules of the context-free grammar, and the specific rules set based on the context-free grammar include:
[0072] (1) Paragraph:
[0073] statement::=subgraph|node=subgraph
[0074] (2) Subgraph:
[0075] subgraph::=subgraph newlineprio_7_stage|prio_7_stage
[0076] prio_7_stage::=prio_7_stage connectorprio_6_stage|prio_7_stage connector|connectorprio_6_stage|prio_6_stage
[0077] prio_6_stage::=prio_6_stagenames|prio_6_stagecopynames|
[0078] prio_5_stage
[0079] prio_5_stage::=prio_5_stage+prio_4_stage|prio_5_stage–prio_4_stage|
[0080] prio_4_stage
[0081] prio_4_stage::=prio_4_stage*prio_3_stage|prio_4_stage / prio_3_stage|prio_3_stageprio_3_stage::=+prio_2_stage|-prio_2_stage|prio_2_stage
[0082] prio_2_stage::=prio_2_stage separatorprio_1_stage|prio_2_stage,prio_1_stage|
[0083] prio_1_stage
[0084] prio_1_stage::=(subgraph)|if_stmt|for_stmt|import_stmt|node
[0085] (3) Loop expression operator:
[0086] for_stmt::=for<loop_cond> loop_body
[0087] loop_body::=(subgraph)|identifier
[0088] loop_cond::=identifier=positive integer to positive integer | identifier in array | identifier in identifier
[0089] (4) Logical expression operators:
[0090] if_stmt::=if_elif|if_elif else logic_body
[0091] if_elif::=if<logic_cond> logic_body|if_elif elif<logic_cond> logic_body
[0092] logic_body::=(subgraph)|identifier
[0093] logic_cond::=logic_cond_var logic comparison logic_cond_var
[0094] logic_cond_var::=real number|identifier
[0095] (5) Reference Operator
[0096] import_stmt::=import model_path
[0097] model_path::=string|model_name
[0098] model_name::=identifier|model_name.identifier
[0099] (6) Node:
[0100] node::=operator|var|literal
[0101] operator::=identifier(params)|identifier
[0102] var::=var_with|var_with:literal
[0103] var_with::=var_name|var_with:identifier(params)
[0104] var_name::=identifier|var_name.identifier
[0105] identifier::=identifier|@identifier|$identifier|@|$
[0106] (7) Parameter group:
[0107] params::=literal|identifier=literal|literal,params|empty string
[0108] names::=identifier|identifier,names
[0109] (8) Literals:
[0110] literal::=positive integer | real number | array | tensor
[0111] S203: Determine an ambiguity rule according to the established language grammar;
[0112] The ambiguity of the language grammar means that for a certain sentence, there will be two or more results when it is expanded according to the same set of language grammar rules, that is, there are two or more legal expansion methods to choose from in a certain step of derivation.
[0113] Determining ambiguous rules includes fixedly selecting one of the ways to expand or rewrite the ambiguous grammar when encountering an ambiguous statement.
[0114] S204: Determine the language semantics describing the computational graph structure according to a preset language model;
[0115] S205: a processing step of determining a grammatical error based on the grammar;
[0116] S206: Determine semantic errors according to a preset language model.
[0117] S102: parsing the written instance using the compilation method, and translating the written instance into the required intermediate code, target code or computation graph structure instance;
[0118] Specifically, the written example describing the computational graph structure obtained in step S101 is further processed by a preset compiler to obtain the required intermediate code, target code or computational graph structure example. In this embodiment, the compiler used is created based on the interpreted language Python, that is, a compiler of the declarative programming language is implemented by Python.
[0119] In one embodiment, the generation target of the declarative programming language is set as a computational graph structure instance, which is defined as a class, object, array, variable, method, function and process stored in a fixed or variable storage of a computer to describe the physical structure, logical structure and operation logic of the computational graph. A Python-based program is used to describe the computational graph structure instance.
[0120] Specifically, Figure 3 As shown, in step S102, the compiler is executed as follows:
[0121] S301: Reading an example written using language grammar rules;
[0122] S302: According to the determined lexical unit symbol domain, a lexical unit sequence is selected from the written instance as a terminal symbol sequence;
[0123] S303: Parse the terminal symbol sequence according to the determined language grammar and semantics, and obtain the intermediate code, target code or computational graph structure instance after the parsing is correct; obtain an error list after the parsing error, and the error list includes the error cause, error location and repair suggestions.
[0124] like Figure 4 As shown, the processing step of determining the grammatical error specifically includes:
[0125] S401: record the cause of the error;
[0126] In one embodiment, the compiler checks whether there is a terminal symbol < representing the template area after the keyword if. If no symbol exists or other terminal symbols exist, the compiler will record an error including an error description related to the if syntax.
[0127] In one embodiment, the compiler checks whether the parameter group ends with a terminal comma. If it ends with a comma, the compiler logs an error including an error description related to the parameter group.
[0128] S402: Record the error location;
[0129] In one embodiment, the compiler records the line number and character number within the line where the error started in the entire written example.
[0130] In one embodiment, the compiler records the file name where the error occurs and the path to the file.
[0131] S403: Providing modification suggestions;
[0132] In one embodiment, the compiler checks whether a connection symbol is directly followed by another connection symbol. If two connection symbols are connected and there is no other character except blank characters in between, the compiler will give a suggestion to delete one of the connection symbols.
[0133] In one embodiment, the compiler checks whether a subgraph is followed by a keyword copyas identifier, and if it is followed by copy, the compiler will give suggestions to correct the keyword.
[0134] S404: Recover from error.
[0135] In one embodiment, the compiler checks whether there is a terminal symbol "<" representing the template area after the keyword for. If there is no symbol or there are other terminal symbols, the compiler will try to add the terminal symbol "<" after the keyword for and continue processing.
[0136] In one embodiment, the compiler checks whether there is an identifier, unary operator, or subgraph representing a node after the terminal symbol plus sign. If the above element does not exist, the compiler will try to discard subsequent terminal symbols until an identifier, unary operator, or subgraph is found and continue processing.
[0137] In one embodiment, the connection terminator cannot be placed at the beginning of the entire program or at the end of the entire program. After the compiler expands the entire program, it checks the head and the end. If there is a connection terminator, the compiler will handle an error according to the above error handling steps.
[0138] In one embodiment, two nodes representing variables cannot appear side by side. The compiler checks the symbol table to determine whether the types of the two nodes appearing side by side are both variables, and if so, handles an error according to the above error handling steps.
[0139] In one embodiment, the parallel connection symbol requires that the number of end points of the left subgraph is the same as the number of start points of the right subgraph. The compiler checks whether the number of end points of the left subgraph of the parallel connection symbol is the same as the number of start points of the right subgraph. If not, the compiler handles an error according to the above error handling steps.
[0140] The end point refers to a point provided by a subgraph to a subgraph using the subgraph as a starting point of a directed connection. In one embodiment, the end point is declared by an end point descriptor, and the end point can be any node.
[0141] The starting point refers to a point pointed to by a subgraph that accepts a subgraph using the subgraph as an end point of a directed connection. In one embodiment, the starting point is declared by a starting point descriptor, and the starting point can be any node.
[0142] In one embodiment, the nodes of the subgraph obtained by the subgraph attribute symbol need to have been declared, and the compiler checks whether a node of the subgraph exists. If not, an error is handled according to the above error handling steps.
[0143] According to another aspect of an embodiment of the present application, a computer device is provided, which includes a processor and a memory for storing executable instructions of the processor, and the processor is configured to execute the computational graph description method described in the embodiment of the present application by executing the executable instructions.
[0144] According to another aspect of an embodiment of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium is used to store program code, and the program code is used to execute the computational graph description method described in the embodiment of the present application.
[0145] The storage medium can be ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or it can be EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disc, optical disk, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage medium, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation here.
[0146] The execution device may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The execution device may also be a combination that implements a computing function, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0147] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A computational graph description method, characterized in that: The method comprises the following steps: Define the computational graph structure based on a declarative programming language, build the grammar rules for the computational graph generation language, and write examples that describe the computational graph structure; The compilation method is used to parse the written instance and translate the written instance into the required intermediate code, target code or computational graph structure instance.
2. The computational graph description method according to claim 1, characterized in that: The steps of defining a computational graph structure based on a declarative programming language, constructing a computational graph generation language grammar rule, and writing a writing instance describing the computational graph structure specifically include: Determine the symbol domain of the lexical unit according to a preset language model; Determine the language grammar that describes the computational graph structure based on the preset language model; Determine ambiguity rules based on established language grammar; Determine the language semantics that describe the computational graph structure based on the preset language model; The processing steps for determining grammatical errors based on the grammar; Semantic errors are determined based on a preset language model.
3. The computational graph description method according to claim 2, characterized in that: In the step of determining the symbol domain of the lexical unit according to a preset language model, the language model includes a part describing the calculation graph structure and a part modifying the calculation graph structure.
4. The computational graph description method according to claim 3, characterized in that: The portion describing the computational graph structure includes one or more nodes and subgraphs, wherein the nodes include operators, variables, and literals; The operator is a node declared by an identifier that accepts one or more inputs and provides one or more outputs; a variable is a node that provides one input, one output, and stores modifiable data; a literal is a node that provides zero inputs, one output, and stores data that cannot be modified; The operators include system default operators and user-defined operators, wherein the user-defined operators are compounded by one or more system default operators or operations supporting default operations, and the compounding refers to the compounding of procedures, functions, methods or statements in a computer; The variable includes a declarator, a name and an accompanying operation. The declarator describes the specific role of the variable in the subgraph, and the accompanying operation describes the operation that needs to be embedded in the computation graph during the computation process. The name can be, but is not limited to, a string or a number. The literal type is one of a positive integer, a real number, an array, a tensor, and a string.
5. The computational graph description method according to claim 4, characterized in that: The subgraph includes a declared subgraph, a generated subgraph and an introduced subgraph; The declaration subgraph is formed by connecting multiple subgraphs or nodes by connecting symbols, and the number of connected subgraphs and nodes is one or more; The subgraph is generated by logic symbols according to operation conditions, wherein the logic symbols include loop symbols and judgment symbols, and the generation method comprises: Generate a given number of subgraphs by loop unrolling; Generate a fixed number of subgraphs using given initial and final values in a cyclic and progressive manner; Generate subgraph A or subgraph B through logical judgment; Select a generation from multiple given subgraphs through logical multiple judgments; The introduced subgraph includes the introduction of a system computation graph and the introduction of a user-defined computation graph, wherein the system computation graph is a built-in computation graph structure provided by an instance of a language implementation; the user computation graph is an external computation graph structure obtained by the user through this instance to create a new computation graph or modify an existing computation graph.
6. The computational graph description method according to claim 3, characterized in that: The modification of the computational graph structure includes one or more modifications to the computational graph structure, and the modification methods include: Modify the node itself through assignment statements; Use companion statements to modify the behavior of a node during calculation.
7. The computational graph description method according to claim 1, characterized in that: The step of using the compilation method to parse the writing instance and translate the writing instance into the required intermediate code, target code or calculation graph structure instance specifically includes: Read examples written using the language's grammar rules; According to the determined lexical unit symbol domain, a lexical unit sequence is selected from the written instance as a terminal symbol sequence; Parse the terminal symbol sequence according to the determined language grammar and semantics, and obtain the intermediate code, target code or computational graph structure instance after correct parsing; obtain an error list after parsing errors, which includes the cause of the error, the error location and repair suggestions.
8. The computational graph description method according to claim 7, characterized in that: The processing step of determining the grammatical error specifically includes: Record the cause of the error; Record the error location; Provide suggestions for changes; Recover from errors.
9. A computer device, characterized in that: The computer device includes a processor and a memory for storing executable instructions of the processor, and the processor is configured to perform the computational graph description method according to any one of claims 1 to 8 by executing the executable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store program code, and the program code is used to execute the computational graph description method described in any one of claims 1 to 8.
