Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dy2s] fix error when using same tensor as inputs in one call & fix bugs in jit.save #55963

Merged
merged 22 commits into from
Aug 21, 2023

Conversation

feifei-111
Copy link
Contributor

@feifei-111 feifei-111 commented Aug 3, 2023

PR types

Others

PR changes

Others

Description

fix error when using same tensor as inputs in one call

---- wrong program created, when case like:
t = paddle.to_tensor(1)
f(t, t)

fix bugs in jit.save, when program_cache is not empty, jit.save might save a wrong program when input_spec is given

Others

PCard-66972

@paddle-bot
Copy link

paddle-bot bot commented Aug 3, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@feifei-111 feifei-111 closed this Aug 7, 2023
@feifei-111 feifei-111 reopened this Aug 7, 2023
@@ -321,7 +346,8 @@ inline void RunProgramAPI(

VLOG(4) << "global_inner_scope:" << global_inner_scope;

auto input_names = details::GetTensorsName(x);
auto input_names =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@feifei-111 之前的方案会有什么问题?Tensor.name 不符合预期么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果两个输入是同一个tensor,组的program会不一致,这个导致sot里面没办法复用之前的program,因为sot希望能直接绕过动转静的cache拿到program。现在会对输入的tensor重命名,这样生成的program就没问题了

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来的Tensor.name无法处理同一个Tensor绑定了Program中两个名字的情况。现在是可以兼容所有的情况的。

2742195759
2742195759 previously approved these changes Aug 7, 2023
Copy link
Contributor

@2742195759 2742195759 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

jiweibo
jiweibo previously approved these changes Aug 7, 2023
@feifei-111 feifei-111 dismissed stale reviews from jiweibo and 2742195759 via 06cdb9b August 8, 2023 03:44
@feifei-111 feifei-111 changed the title [dy2s] fix error when using same tensor as inputs in one call [dy2s] fix error when using same tensor as inputs in one call & fix bugs in jit.save Aug 9, 2023
Copy link
Contributor

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for docs

Copy link
Contributor

@2742195759 2742195759 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +152 to +176
static void ShareTensorsIntoScopeWithName(
const std::vector<Tensor> &tensors,
const std::vector<std::string> &tensor_names,
paddle::framework::Scope *scope) {
for (size_t i = 0; i < tensors.size(); ++i) {
auto name = tensor_names[i];
if (name == paddle::framework::kFakeVarName) {
continue;
}
auto *var = scope->Var(name);
CheckInputVarStatus(tensors[i]);
// share tensor
auto tensor_base = tensors[i].impl();
if (phi::DenseTensor::classof(tensor_base.get())) {
auto *dst_tensor = var->GetMutable<phi::DenseTensor>();
auto t = std::dynamic_pointer_cast<phi::DenseTensor>(tensor_base);
*dst_tensor = *t;
} else if (phi::SelectedRows::classof(tensor_base.get())) {
auto *dst_tensor = var->GetMutable<phi::SelectedRows>();
auto t = std::dynamic_pointer_cast<phi::SelectedRows>(tensor_base);
*dst_tensor = *t;
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消除重复,这个可以被 ShareTensorsIntoScope 复用。

@@ -488,11 +491,12 @@ def keep_name_table(self, value):

def _parse_save_configs(configs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

让日升approve一下这里

@@ -302,6 +311,44 @@ def _replace_value_with_input_spec(args):
return args_with_spec


def _replace_to_input_spec_with_new_name(args, arg_names):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除掉没用的:_replace_value_with_input_spec

@@ -887,6 +904,8 @@ def _prepare(self, inputs):
flatten_inputs = paddle.utils.flatten(inputs)
# Convert variable into Tensor and feed in training data.
input_vars = []
input_var_names = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写成函数式:
map(lambda x: x.desct.name, self.inputs)

Copy link
Contributor

@vivienfanghuagood vivienfanghuagood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for run_program_op

@SigureMo SigureMo merged commit 51c4028 into PaddlePaddle:develop Aug 21, 2023
BeingGod pushed a commit to BeingGod/Paddle that referenced this pull request Sep 9, 2023
@feifei-111 feifei-111 deleted the fix_run_program_op branch December 15, 2023 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants