# US 10,956,500 B2 · Dynamic-length stateful tensor array

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

- Number: US 10,956,500 B2
- Document ID: US10956500B2
- Status: Granted
- Kind: B2
- Application number: 15/410,643
- Filed: 2017-01-19
- Published: 2018-07-19
- Granted: 2021-03-23
- Earliest claimed: 2017-01-19
- Assignees: Google Inc.
- Applicants: Google LLC
- Inventors: Eugene Brevdo
- Web page: https://patentgrep.com/patent/US10956500B2

## CPC

- G06F 16/9024: {Graphs; Linked lists (G06F16/9027 takes precedence)}
- G06F 17/16: Matrix or vector computation {, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization (matrix transposition G06F7/78)}
- G06N 3/044: Recurrent networks, e.g. Hopfield networks
- G06N 3/0442: characterised by memory or gating, e.g. long short-term memory [LSTM] or gated recurrent units [GRU]
- G06N 3/084: Backpropagation, e.g. using gradient descent
- G06N 3/09: Supervised learning
- G06N 3/105: {Shells for specifying net layout}
- G06N 20/00: Machine learning
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

Methods, systems, and apparatus, including computer programs encoded on computer storage media, for efficiently processing dynamic length tensors of a machine learning model represented by a computational graph. A program is received that specifies a dynamic, iterative computation that can be performed on input data for processing by a machine learning model. A directed computational graph representing the machine learning model is generated that specifies the dynamic, iterative computation as one or more operations using a tensor array object. Input is received for processing by the machine learning model and the directed computational graph representation of the machine learning model is executed with the received input to obtain output.

## Claims

### Claim 1

A computer-implemented method comprising:
receiving a program specifying a dynamic, iterative computation that can be performed on input data for processing by a machine learning model;
generating a directed computational graph representing the machine learning model that specifies the dynamic, iterative computation as a plurality of operations using a tensor array object, wherein:
the tensor array object is a data structure that comprises a dynamically-sized array of a plurality of immutable tensors as a result of executing the plurality of operations of the dynamic, iterative computation, and
each of the plurality of immutable tensors of the tensor array object represent i) a respective hidden flow control dependency of an input immutable tensor if the input immutable tensor had been modified in response to executing a corresponding subset of the plurality of operations and ii) use the respective hidden flow control dependency of the input immutable tensor to ensure that control flow dependency is maintained;
receiving an input for processing by the machine learning model; and
executing the directed computational graph of the machine learning model with the received input to obtain output using the plurality of immutable tensors that each ensure, using the respective hidden flow control dependency of an input immutable tensor, that control flow dependency is maintained.

### Claim 2 (depends on 1)

The computer-implemented method of claim 1, wherein the plurality of operations specified by the tensor array object comprise one or more of: read, write, concat, split, grad, close, pack, unpack, gather, and scatter operations.

### Claim 3 (depends on 1)

The computer-implemented method of claim 1, wherein executing the directed computational graph comprises performing a forward propagation of the received input to the machine learning model, comprising:
performing no more than one write operation for each immutable tensor of the plurality of immutable tensors of the tensor array object to write data to the immutable tensor; and
performing one or more read operations to read data from any immutable tensor of the plurality of immutable tensors of the tensor array object.

### Claim 4 (depends on 1)

The computer-implemented method of claim 1,
wherein the plurality of operations define a directed sequence, and
wherein the plurality of operations comprise a write operation that writes a respective immutable tensor only after every write operation in the plurality of operations occurring before the write operation in the directed sequence has executed prior to executing the write operation.

### Claim 5 (depends on 1)

The computer-implemented method of claim 1,
wherein the plurality of operations define a sequence, and
wherein the plurality of operations comprise a read operation that reads a respective immutable tensor only after any write operation occurring before the read operation in the defined sequence has executed.

### Claim 6 (depends on 1)

The computer-implemented method of claim 1, further comprising:
augmenting the directed computational graph to generate a training computational graph for training neural network using a machine learning training algorithm that includes computing a gradient of an objective function with respect to each of the parameters of the neural network, comprising:
inserting a plurality of gradient nodes and training edges into the directed computational graph to generate a backward path through the directed computational graph that represents operations for computing the gradients of the objective function with respect to the parameters of the neural network, wherein each gradient node represents a gradient function that computes a gradient of the objective function with respect to parameters flowing along a respective parameter-directed edge in the directed computational graph; and
training the neural network using the machine learning training algorithm by executing the training computational graph.

### Claim 7 (depends on 6)

The method of claim 6, wherein augmenting the directed computational graph further comprises:
identifying one or more tensor array operation nodes in the directed computational graph; and
inserting, for each identified tensor array operation node, a corresponding backward path tensor array operation node along the backward path through the directed computational graph, wherein each backward path tensor array operation node forms part of a backward path tensor array object along the backward path corresponding to the tensor array object of the forward path.

### Claim 8 (depends on 7)

The method of claim 7, wherein the one or more tensor array operation nodes include a write operation, and wherein the backward path tensor array operation corresponding to the write operation is a tensor array read operation.

### Claim 9 (depends on 7)

The method of claim 7, wherein the one or more tensor array operation nodes include a read operation, and wherein the backward path tensor array operation corresponding to the read operation is a tensor array write operation.

### Claim 10 (depends on 8)

The method of claim 8, wherein multiple tensor array write operations of the backward path that write to the same index of the backward path tensor array object are accumulated prior to execution.

### Claim 11 (depends on 1)

The method of claim 1, wherein the machine learning model is a recurrent neural network.

### Claim 12 (depends on 1)

The method of claim 1, wherein the dynamic, iterative computation that can be performed on input data for processing by a machine learning model is specified within a higher-order operator.

### Claim 13

A system comprising:
one or more computers; and
one or more storage devices storing instructions that are operable, when executed by one or more computers, to cause the one or more computers to perform operations comprising:
receiving a program specifying a dynamic, iterative computation that can be performed on input data for processing by a machine learning model;
generating a directed computational graph representing the machine learning model that specifies the dynamic, iterative computation as a plurality of operations using a tensor array object, wherein:
the tensor array object is a data structure that comprises a dynamically-sized array of a plurality of immutable tensors as a result of executing the plurality of operations of the dynamic, iterative computation, and
each of the plurality of immutable tensors of the tensor array object represent i) a respective hidden flow control dependency of an input immutable tensor if the input immutable tensor had been modified in response to executing a corresponding subset of the plurality of operations and ii) use the respective hidden flow control dependency of the input immutable tensor to ensure that control flow dependency is maintained;
receiving an input for processing by the machine learning model; and
executing the directed computational graph of the machine learning model with the received input to obtain output using the plurality of immutable tensors that each ensure, using the respective hidden flow control dependency of an input immutable tensor, that control flow dependency is maintained.

### Claim 14 (depends on 13)

The system of claim 13, wherein the plurality of operations comprise one or more of read, write, concat, split, grad, close, pack, unpack, gather, and scatter operations.

### Claim 15 (depends on 13)

The system of claim 13, wherein executing the directed computational graph comprises performing a forward propagation of the received input to the machine learning model, comprising:
performing no more than one write operation for each immutable tensor of the plurality of immutable tensors of the tensor array object to write data to the immutable tensor; and
performing one or more read operations to read data from any immutable tensor of the plurality of immutable tensors of the tensor array object.

### Claim 16 (depends on 13)

The system of claim 13,
wherein the plurality of operations define a directed sequence,
wherein the plurality of operations comprise a write operation that writes a respective immutable tensor only after every write operation in the plurality of operations occurring before the write operation in the directed sequence has executed prior to executing the write operation.

### Claim 17 (depends on 13)

The system of claim 13,
wherein the plurality of operations define a sequence, and
wherein the plurality of operations comprise a read operation that reads a respective immutable tensor only after any write operation occurring before the read operation in the defined sequence has executed.

### Claim 18 (depends on 13)

The system of claim 13, wherein the operations further comprise:
augmenting the directed computational graph to generate a training computational graph for training neural network using a machine learning training algorithm that includes computing a gradient of an objective function with respect to each of the parameters of the neural network, comprising:
inserting a plurality of gradient nodes and training edges into the directed computational graph to generate a backward path through the directed computational graph that represents operations for computing the gradients of the objective function with respect to the parameters of the neural network, wherein each gradient node represents a gradient function that computes a gradient of the objective function with respect to parameters flowing along a respective parameter-directed edge in the directed computational graph; and
training the neural network using the machine learning training algorithm by executing the training computational graph.

### Claim 19

One or more non-transitory computer-readable storage mediums comprising instructions stored thereon that are executable by a processing device and upon such execution cause the processing device to perform operations comprising:
receiving a program specifying a dynamic, iterative computation that can be performed on input data for processing by a machine learning model;
generating a directed computational graph representing the machine learning model that specifies the dynamic, iterative computation as a plurality of operations using a tensor array object, wherein:
the tensor array object is a data structure that comprises a dynamically-sized array of a plurality of immutable tensors as a result of executing the plurality of operations of the dynamic, iterative computation, and
each of the plurality of immutable tensors of the tensor array object represent i) a respective hidden flow control dependency of an input immutable tensor if the input immutable tensor had been modified in response to executing a corresponding subset of the plurality of operations and ii) use the respective hidden flow control dependency of the input immutable tensor to ensure that control flow dependency is maintained;
receiving an input for processing by the machine learning model; and
executing the directed computational graph of the machine learning model with the received input to obtain output using the plurality of immutable tensors that each ensure, using the respective hidden flow control dependency of an input immutable tensor, that control flow dependency is maintained.

### Claim 20 (depends on 19)

The one or more computer-readable storage mediums of claim 19, wherein executing the directed computational graph comprises performing a forward propagation of the received input to the machine learning model, comprising:
performing no more than one write operation for each immutable tensor of the plurality of immutable tensors of the tensor array object to write data to the immutable tensor; and
performing one or more read operations to read data from any immutable tensor of the plurality of immutable tensors of the tensor array object.
