IP Library Granted Patent US 12,423,137
Granted Patent B1
US 12,423,137 · App. 18/066,632 · Granted Sep 23, 2025

Compiler managed tensor parallel execution

Inventors: Hongbin Zheng (San Jose, CA); Yuwen Jia (Sunnyvale, CA)
Assignee: Amazon Technologies, Inc.
G06F9/4881G06F9/3004G06F9/3838
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,423,137
App. No.
18/066,632
Granted
Sep 23, 2025
Kind
B1
Abstract

Techniques for implementing tensor parallel execution can include identifying a first tensor contraction operation in a compute flow, and slicing the first tensor contraction operation into a first set of multiple tensor contraction portions to have each compute engine of multiple compute engines perform a portion of the first tensor contraction operation. A set of slicing options can then be determined for a second tensor contraction operation that operates on a tensor result of the first tensor contraction operation. A cost for each slicing option is determined, and a slicing option having the lowest cost is selected. The second tensor contraction operation is sliced according to the selected slicing option to have each compute engine perform a portion of the second tensor contraction operation. Collective compute operations can be inserted in the compute flow for the first and second tensor contraction operations.

Claims (47)

1. A computer-implemented method for compiling a neural network model for execution on a neural network acceleration engine having multiple accelerators, the method comprising:

obtaining a description of the neural network model;

generating a representation of a compute flow graph of the neural network model, the compute flow graph having nodes corresponding to tensor operations and edges corresponding to data dependencies;

performing data layout assignment for tensors used in the tensor operations;

performing a compute-based slicing of the compute flow graph by:

identifying a set of tensor contraction operations in the compute flow graph;

for each of the tensor contraction operations:

selecting a slicing option having a lowest cost to slice the tensor contraction operation into multiple tensor contraction portions, wherein a cost for slicing a tensor contraction operation includes an overhead to distribute tensor data to the multiple accelerators;

slicing the tensor contraction operation according to the selected slicing option;

propagating the selected slicing option to slice other tensor operations; and

assigning the multiple tensor contraction portions and sliced tensor operations to the multiple accelerators, respectively, to have each accelerator perform a portion of the tensor contraction operation and sliced tensor operations; and

inserting collective compute operations into the representation of the neural network model to facilitate performing the tensor contraction operations in the multiple accelerators; and

generating machine instructions for execution of the neural network model on the multiple accelerators based on the compute-based slicing,

wherein the machine instructions are executed on the multiple accelerators to implement the neural network model.

2. The computer-implemented method of claim 1 , wherein the cost for slicing a tensor contraction operation that operates on a tensor result from a prior tensor contraction operation includes an overhead to resolve slicing mismatch between the tensor contraction operation and the prior tensor contraction operation.

3. The computer-implemented method of claim 1 , further including performing additional tensor slicing after the compute-based slicing to keep memory usage of each accelerator to be within a memory capacity of the corresponding accelerator.

4. A computer-implemented method comprising:

identifying a first tensor contraction operation in a compute flow;

slicing the first tensor contraction operation into a first set of multiple tensor contraction portions to have each compute engine of a plurality of compute engines perform a portion of the first tensor contraction operation;

determining a set of slicing options for a second tensor contraction operation that operates on a tensor result of the first tensor contraction operation;

determining a cost for each slicing option in the set of slicing options for the second tensor contraction operation, wherein the cost for slicing the second tensor contraction operation includes an overhead to distribute tensor data to the plurality of compute engines;

selecting a slicing option having a lowest cost;

slicing the second tensor contraction operation according to the selected slicing option to have each compute engine perform a portion of the second tensor contraction operation;

inserting collective compute operations in the compute flow for the first and second tensor contraction operations; and

generating machine instructions for the compute flow, wherein the machine instructions are executed on the plurality of compute engines to perform the compute flow.

5. The computer-implemented method of claim 4 , wherein the first tensor contraction operation is sliced along a left tensor free axis, and the collective compute operations include scattering a left tensor of the first tensor contraction operation, and duplicating a right tensor of the first tensor contraction operation.

6. The computer-implemented method of claim 4 , wherein the first tensor contraction operation is sliced along a right tensor free axis, and the collective compute operations include duplicating a left tensor of the first tensor contraction operation, and scattering a right tensor of the first tensor contraction operation.

7. The computer-implemented method of claim 4 , wherein the first tensor contraction operation is sliced along a contracted axis, and the collective compute operations include scattering a left tensor of the first tensor contraction operation, and scattering a right tensor of the first tensor contraction operation.

8. The computer-implemented method of claim 4 , wherein determining the cost for each slicing option of the second tensor contraction operation includes determining a cost to resolve slicing mismatch on the tensor result of the first tensor contraction operation.

9. The computer-implemented method of claim 8 , wherein no additional collective compute operation is used to resolve slicing mismatch when slicing both the first and second tensor contraction operations along respective left tensor free axes, or slicing the first tensor contraction operation along a right tensor free axis and the second tensor contraction operation along a contracted axis.

10. The computer-implemented method of claim 8 , wherein an all-to-all collective compute operation is added to resolve slicing mismatch when slicing the first tensor contraction operation along a left tensor free axis and the second tensor contraction operation along a contracted axis, or slicing the first tensor contraction operation along a right tensor free axis and the second tensor contraction operation along a left tensor free axis.

11. The computer-implemented method of claim 8 , wherein an all-gather collective compute operation is added to resolve slicing mismatch when slicing the first tensor contraction operation along a left tensor free axis and the second tensor contraction operation along a right tensor free axis, or slicing both the first and second tensor contraction operations along respective right tensor free axes.

12. The computer-implemented method of claim 8 , wherein an all-reduce collective compute operation is added to resolve slicing mismatch when slicing the first tensor contraction operation along a contracted axis and the second tensor contraction operation along a right tensor free axis.

13. The computer-implemented method of claim 8 , wherein a reduce-scatter collective compute operation is added to resolve slicing mismatch when slicing the first tensor contraction operation along a contracted axis and the second tensor contraction operation along a left tensor free axis, or slicing both the first and second tensor contraction operation along respective contracted axes.

14. The computer-implemented method of claim 4 , wherein the first and second tensor contraction operations are represented as affine loopnests.

15. The computer-implemented method of claim 14 , wherein slicing each of the first and second tensor contraction operations includes setting an axis being sliced to be an outermost loop of the respective affine loopnests, and parallelizing the outermost loop into multiple threads for the plurality of compute engines.

16. A non-transitory computer readable medium having stored therein instructions that, when executed by one or more processors, cause the one or more processors to execute a compiler, the compiler performing operations including: identifying a first tensor contraction operation in a compute flow;

slicing the first tensor contraction operation into a first set of multiple tensor contraction portions to have each compute engine of a plurality of compute engines perform a portion of the first tensor contraction operation;

determining a set of slicing options for a second tensor contraction operation that operates on a tensor result of the first tensor contraction operation;

determining a cost for each slicing option in the set of slicing options for the second tensor contraction operation, wherein the cost for slicing the second tensor contraction operation includes an overhead to distribute tensor data to the plurality of compute engines;

selecting a slicing option having a lowest cost;

slicing the second tensor contraction operation according to the selected slicing option to have each compute engine perform a portion of the second tensor contraction operation;

inserting collective compute operations in the compute flow for the first and second tensor contraction operations; and

generating machine instructions for the compute flow, wherein the machine instructions are executed on the plurality of compute engines to perform the compute flow.

17. The non-transitory computer readable medium of claim 16 , wherein determining the cost for each slicing option of the second tensor contraction operation includes determining a cost to resolve slicing mismatch on the tensor result of the first tensor contraction operation.

18. The non-transitory computer readable medium of claim 16 , wherein the first and second tensor contraction operations are represented as affine loopnests.

19. The non-transitory computer readable medium of claim 18 , wherein slicing each of the first and second tensor contraction operations includes setting an axis being sliced to be an outermost loop of the respective affine loopnests, and parallelizing the outermost loop into multiple threads for the plurality of compute engines.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 27, 2022
From: ZHENG, HONGBIN; JIA, YUWEN
To: AMAZON TECHNOLOGIES, INC.
Reel/Frame 062209/0029 →
References Cited (30)
US 10073816B1 · Lu · 2018 [cited by examiner]
US 10216704B1 · Lu · 2019 [cited by examiner]
US 10884707B1 · Li · 2021 [cited by examiner]
US 11645358B2 · Chatterjee · 2023 [cited by examiner]
US 11803360B2 · Wu · 2023 [cited by examiner]
US 20170060811A1 · Yang · 2017 [cited by examiner]
US 20190227750A1 · Srinivasan · 2019 [cited by examiner]
US 20190228809A1 · Srinivasan · 2019 [cited by examiner]
US 20200042875A1 · Shazeer · 2020 [cited by examiner]
US 20200117999A1 · Yoon · 2020 [cited by examiner]
US 20200133531A1 · Subramaniam · 2020 [cited by examiner]
US 20210056389A1 · Yang · 2021 [cited by examiner]
US 20210064987A1 · Springer · 2021 [cited by examiner]
US 20210117806A1 · Liu · 2021 [cited by examiner]
US 20210209270A1 · Huang · 2021 [cited by examiner]
US 20220012573A1 · Nagendran · 2022 [cited by examiner]
US 20220108156A1 · Hunter · 2022 [cited by examiner]
US 20220121959A1 · Kolhe · 2022 [cited by examiner]
US 20220391571A1 · Dhand · 2022 [cited by examiner]
US 20230177120A1 · Papandreou · 2023 [cited by examiner]
US 20230229916A1 · Chechik · 2023 [cited by examiner]
US 20230385077A1 · Wang · 2023 [cited by examiner]
US 20230409520A1 · Wang · 2023 [cited by examiner]
US 20230419145A1 · Panteleev · 2023 [cited by examiner]
US 20240168915A1 · Du · 2024 [cited by examiner]
Abdelfattah et al.; “High-Performance Tensor Contractions for GPUs”, Published by Elsevier B.V., ICCS 2016; doi: 10.1016/j.procs.2016.05.302; (Abdelfattah_2016.pdf; pp. 108-118) (Year: 2016). [cited by examiner]
Poya et al.; “A high performance data parallel tensor contraction framework: Application to coupled electro-mechanics”; © 2017 Elsevier B.V; http://dx.doi.org/10.1016/j.cpc.2017.02.016; (Poya_2017.pdf; pp. 35-52) (Year:… [cited by examiner]
Ma et al.; “Optimizing tensor contraction expressions for hybrid CPU-GPU execution”; © Springer Science + Business Media, LLC 2011; DOI 10. 1007/s10586-011-0179-2; (Ma_2011.pdf; pp. 131-155) (Year: 2011). [cited by examiner]
Rajbhandari et al.; “A Communication-Optimal Framework for Contracting Distributed Tensors”; © 2014 IEEE; DOI 10.1109/SC.2014.36; (Rajbhandari_2014.pdf; pp. 375-386) (Year: 2014). [cited by examiner]
“Collective Operations,” NVIDIA Collective Communication Library (NCCL) Documentation, NCCL 2.16.2, Dec. 9, 2022, 3 pages, URL: https://docs.nvidia.com/deeplearning/nccl/archives/nccl_2162/user-guide/docs/usage/collecti… [cited by applicant]