# US 2025/0165785 A1 · Method for training neural network, and related device

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2025/0165785 A1
- Document ID: US20250165785A1
- Status: Published application
- Kind: A1
- Application number: 19/030,849
- Filed: 2025-01-17
- Published: 2025-05-22
- Earliest claimed: 2022-07-22
- Assignees: Huawei Cloud Computing Technologies Co., Ltd.
- Applicants: Huawei Cloud Computing Technologies Co., Ltd.
- Inventors: Guoping Long; Yuanfeng Zhong; Liying Li
- Web page: https://patentgrep.com/patent/US20250165785A1

## CPC

- G06N 3/063: using electronic means
- G06N 3/08: Learning methods
- G06F 8/41: Compilation
- G06N 3/04: Architecture, e.g. interconnection topology
- G06N 3/045: Combinations of networks
- G06N 3/082: modifying the architecture, e.g. adding, deleting or silencing nodes or connections
- G06N 3/084: Backpropagation, e.g. using gradient descent
- G06N 3/105: {Shells for specifying net layout}
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method for training a neural network, and a related device are provided. The method may be applied to a scenario in which a neural network is trained in the field of artificial intelligence. When an Nth round of training of the neural network is being performed, a first computational graph may be obtained; and after it is determined that a first compiled code corresponding to the first computational graph has been stored in a system, the first compiled code may be directly executed, where the first compiled code is generated during execution of an Mth round of training of the neural network, and M is less than N. Because there is no need to perform an operation of converting the first computational graph into an intermediate representation, and obtaining a compiled code based on the intermediate representation, overheads of computer resources are reduced.

## Claims

### Claim 1

A method for training a neural network, wherein when an Nth round of training of the neural network is being performed, the method comprises:
obtaining a first computational graph, wherein the first computational graph is one of one or more computational graphs corresponding to the Nth round of training of the neural network, and N is a positive integer;
determining that a first compiled code corresponding to the first computational graph has been stored in a storage device, wherein the first compiled code is generated during execution of an Mth round of training of the neural network, M is a positive integer, and M is less than N; and
executing the first compiled code.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the executing the first compiled code comprises:
obtaining a first mapping relationship from the storage device, wherein the first mapping relationship indicates an obtaining location of an input parameter of the first computational graph;
determining, based on the first mapping relationship, a value of the input parameter of the first computational graph corresponding to the Nth round of training; and
executing the first compiled code based on the value of the input parameter.

### Claim 3 (depends on 2)

The method according to claim 2, wherein before the obtaining the first mapping relationship, the method comprises:
establishing the first mapping relationship based on the first mapping relationship being absent in the storage device.

### Claim 4 (depends on 1)

The method according to claim 1, wherein the first computational graph is a reusable computational graph.

### Claim 5 (depends on 1)

The method according to claim 1, wherein the determining that the first compiled code corresponding to the first computational graph has been stored in the storage device comprises:
performing representation conversion on the first computational graph, to obtain an intermediate representation (IR) corresponding to the first computational graph; and
determining, based on the IR, that the first compiled code has been stored in the storage device.

### Claim 6 (depends on 1)

The method according to claim 1, wherein when the Mth round of training of the neural network is being performed, the method further comprises:
obtaining the first computational graph, and generating the first compiled code based on the first computational graph; and
storing the first compiled code in the storage device.

### Claim 7 (depends on 1)

The method according to claim 1, wherein the determining that the first compiled code corresponding to the first computational graph has been stored in the storage device comprises:
based on the first mapping relationship being stored in the storage device, determining that the first compiled code has been stored in the storage device, wherein the first mapping relationship indicates an obtaining location of an input parameter of the first computational graph.

### Claim 8 (depends on 1)

The method according to claim 1,
wherein the first computational graph corresponds to a first step in the Nth round of training of the neural network; and
wherein after the executing the first compiled code, the method further comprises:
generating first output data, wherein the first output data is of a first data structure, the first output data comprises at least one piece of input data of a second step in an operation of training the neural network, the first data structure is a data structure used for performing the second step in the operation of training the neural network, and the operation of training the neural network comprises the Nth round of training of the neural network;
and/or
obtaining at least one piece of input data of the first computational graph based on a format of a second data structure, wherein the at least one piece of input data of the first computational graph exists in second output data of a third step in the operation of training the neural network, and the second data structure is a data structure used for performing the third step in the operation of training the neural network.

### Claim 9 (depends on 8)

The method according to claim 8,
wherein a storage location of the first output data is consistent with a read location of the at least one piece of input data of the second step; and/or
wherein a read location of the at least one piece of input data of the first computational graph is consistent with a storage location of the second output data.

### Claim 10

An apparatus for training a neural network, comprising:
a processor; and
a memory, wherein the memory is configured to store instructions, wherein when an Nth round of training of the neural network is being performed, the processor is configured to invoke the instructions in the memory to:
obtain a first computational graph, wherein the first computational graph is one of one or more computational graphs corresponding to the Nth round of training of the neural network, and N is a positive integer;
determine that a first compiled code corresponding to the first computational graph has been stored in a storage device, wherein the first compiled code is generated during execution of an Mth round of training of the neural network, M is a positive integer, and M is less than N; and
execute the first compiled code.

### Claim 11 (depends on 10)

The apparatus according to claim 10, wherein the processor is further configured to invoke the instructions in the memory to:
obtain a first mapping relationship from the storage device, wherein the first mapping relationship indicates an obtaining location of an input parameter of the first computational graph;
determine, based on the first mapping relationship, a value of the input parameter of the first computational graph in the Nth round; and
execute the first compiled code based on the value of the input parameter.

### Claim 12 (depends on 11)

The apparatus according to claim 11, wherein the processor is further configured to invoke the instructions in the memory to:
establish the first mapping relationship based on the first mapping relationship being absent in the storage device.

### Claim 13 (depends on 10)

The apparatus according to claim 10, wherein the first computational graph is a reusable computational graph.

### Claim 14 (depends on 10)

The apparatus according to claim 10, wherein the processor is further configured to invoke the instructions in the memory to:
perform representation conversion on the first computational graph, to obtain an intermediate representation (IR) corresponding to the first computational graph; and
determine, based on the IR, that the first compiled code has been stored in the storage device.

### Claim 15 (depends on 10)

The apparatus according to claim 10, wherein when the Mth round of training of the neural network is being performed, the processor is further configured to invoke the instructions in the memory to:
obtain the first computational graph, and generate the first compiled code based on the first computational graph; and
store the first compiled code in the storage device.

### Claim 16 (depends on 10)

The apparatus according to claim 10, wherein the processor is further configured to invoke the instructions in the memory to:
based on the first mapping relationship being stored in the storage device, determine that the first compiled code has been stored in the storage device, wherein the first mapping relationship indicates an obtaining location of an input parameter of the first computational graph.

### Claim 17 (depends on 10)

The apparatus according to claim 10,
wherein the first computational graph corresponds to a first step in the Nth round of training of the neural network; and
wherein after the executing the first compiled code, the processor is further configured to invoke the instructions in the memory to:
generate first output data, wherein the first output data is of a first data structure, the first output data comprises at least one piece of input data of a second step in an operation of training the neural network, the first data structure is a data structure used for performing the second step in the operation of training the neural network, and the operation of training the neural network comprises the Nth round of training of the neural network;
and/or
obtain at least one piece of input data of the first computational graph based on a format of a second data structure, wherein the at least one piece of input data of the first computational graph exists in second output data of a third step in the operation of training the neural network, and the second data structure is a data structure used for performing the third step in the operation of training the neural network.

### Claim 18 (depends on 17)

The apparatus according to claim 17,
wherein a storage location of the first output data is consistent with a read location of the at least one piece of input data of the second step; and/or
wherein a read location of the at least one piece of input data of the first computational graph is consistent with a storage location of the second output data.

### Claim 19 (depends on 17)

The apparatus according to claim 17, wherein the processor is further configured to invoke the instructions in the memory to:
send the first output data by invoking a preset interface, wherein the second step in the operation of training the neural network comprises sending the first output data, and the first data structure is a data structure used for performing an operation of sending the first output data.

### Claim 20

A non-transitory computer-readable storage medium, wherein the computer-readable storage medium stores a program, and when the program is run on a computer, the computer is enabled to:
obtain a first computational graph, wherein the first computational graph is one of one or more computational graphs corresponding to the Nth round of training of the neural network, and N is a positive integer;
determine that a first compiled code corresponding to the first computational graph has been stored in a storage device, wherein the first compiled code is generated during execution of an Mth round of training of the neural network, M is a positive integer, and M is less than N; and
execute the first compiled code.
