|
| 1 | +# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import paddle |
| 16 | + |
| 17 | + |
| 18 | +def apply_partition_pass(program): |
| 19 | + new_program = program.clone() |
| 20 | + with paddle.static.program_guard(new_program): |
| 21 | + for op in new_program.global_block().ops: |
| 22 | + # assert len(op.operands()) == len(op.dist_attr().operand_dist_attrs()), f'The number of operand and operand_dist_attrs are not equal in op: {op}' |
| 23 | + for var, operand_dist_attr in zip( |
| 24 | + op.operands(), op.dist_attr().operand_dist_attrs() |
| 25 | + ): |
| 26 | + if ( |
| 27 | + var.source().is_dist_dense_tensor_type() |
| 28 | + and var.source().dist_attr() != operand_dist_attr |
| 29 | + ): |
| 30 | + paddle.pir.set_insertion_point(op) |
| 31 | + # insert reshard |
| 32 | + reshard_var = paddle._pir_ops.reshard_v2( |
| 33 | + var.source(), operand_dist_attr |
| 34 | + ) |
| 35 | + var.set_source(reshard_var) |
| 36 | + return new_program |
| 37 | + |
| 38 | + |
| 39 | +def apply_reshard_pass(program): |
| 40 | + pass |
0 commit comments