-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Eager] fix set_value logic when input's dtype is different #48519
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments
paddle/fluid/pybind/eager_method.cc
Outdated
@@ -1243,6 +1242,10 @@ static PyObject* tensor_method__setitem_eager_tensor(TensorObject* self, | |||
value_tensor = egr::EagerAmpAutoCast( | |||
value_tensor.name(), value_tensor, amp_dtype, "set_value"); | |||
} | |||
if (value_tensor.initialized() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not merge this into branch above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge this into branch above now.
paddle/fluid/pybind/eager_method.cc
Outdated
@@ -1243,6 +1242,10 @@ static PyObject* tensor_method__setitem_eager_tensor(TensorObject* self, | |||
value_tensor = egr::EagerAmpAutoCast( | |||
value_tensor.name(), value_tensor, amp_dtype, "set_value"); | |||
} | |||
if (value_tensor.initialized() && | |||
self->tensor.dtype() != value_tensor.dtype()) { | |||
value_tensor = cast_ad_func(value_tensor, self->tensor.dtype()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a safe operants, check dtype first maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkout the EagerAmpAutoCast && GetAmpDestDtype system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后续的set_value__dygraph_function
的两个输入必须相同dtype, 而先前的 EagerAmpAutoCast
并不能保证两个输入相同 dtype, 比如tensor A float16, tensor B float64, 经过 EagerAmpAutoCast
处理,tensor A 为 float32, 而 tensor B 依然 float64,调用 set_value__dygraph_function 会报错的。所以需要调用 cast_ad_func
进行对齐。
self->tensor = set_value__dygraph_function(
self->tensor, value_tensor, {}, {}, {}, attrs);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ddle#48519) * [Eager] fix set_value logic when input's dtype is different * value_tensor * fix set_value logic when input's dtype is different
PR types
Bug fixes
PR changes
Others
Describe
fix set_value logic when input's dtype is different