-
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
Dynamically bind dtype #62508
Merged
Merged
Dynamically bind dtype #62508
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
10501fc
🧹 chore: update Python and C++ files for eager execution properties a…
zrr1999 df210be
🐛 fix: add missing imports for bind_vartype and bind_datatype
zrr1999 c8085cd
🧹 chore: remove redundant NOLINT comment in tensor_name__doc definition
zrr1999 6653f91
🧹 chore(dtype): move imports
zrr1999 93b50c5
Empty-Commit
gouzil 6003932
🐛 fix: fix dtype check in monkey_patch_math_tensor.py [optional body]…
zrr1999 4c47219
m
zrr1999 8ed0e9b
fix(opcode_translator): fix dtype abbreviation for TensorVariable
zrr1999 5f00576
chore(python/paddle/jit/sot/opcode_translator/executor/variables): re…
zrr1999 0af04f5
fix(dygraph): fix variable dtype comparison issue
zrr1999 d6196a7
fix(paddle): fix dtype comparison logic in framework.py and dtype.py
zrr1999 a2ff143
fix(pir_dy2static): fix dtype assignment in ParametersRecorder
zrr1999 8bc4d35
chore: add g_data_type_pytype to PyObject_CheckLongOrToLong function
zrr1999 3107638
fix DTYPE_ATTR when use env directly
SigureMo 808d3c7
sim both vartype and datatype as TensorDtypeVariable
SigureMo 8c08793
remove dtype convert in `MetaTensor.from_tensor`, in `use_pir_api` mo…
SigureMo 79221d1
use `use_pir_api` in convert_np_dtype_to_dtype_ to avoid skip numpy d…
SigureMo 80de817
dont use use_pir_api in convert_np_dtype_to_dtype_
SigureMo 97ff3fa
refine dtype convert in tensor_patch_methods
SigureMo bb32a9c
use paddle.<dtype>, fix test_grad
SigureMo 385265f
use VarType in coalesce_tensor, fix test_lstm
SigureMo 2b11b41
move comment
SigureMo cf2b1de
convert dtype to VarType before init Tensor, fix error in Seg model
SigureMo c34ac64
adapt randint, pass CINN CI
SigureMo d89daf2
try to use `use_pir_api` in `convert_np_dtype_to_dtype_` again
SigureMo 7d68baf
fix `_create_tensor`
SigureMo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ limitations under the License. */ | |
|
||
#pragma GCC diagnostic ignored "-Wwrite-strings" | ||
|
||
COMMON_DECLARE_bool(enable_pir_api); | ||
|
||
namespace paddle { | ||
namespace pybind { | ||
|
||
|
@@ -847,25 +849,47 @@ Tensor's data type. | |
)DOC"); | ||
PyObject* tensor_properties_get_dtype(TensorObject* self, void* closure) { | ||
EAGER_TRY | ||
if (!self->tensor.defined()) { | ||
// be same to old dygraph | ||
return ToPyObject(framework::proto::VarType::FP32); | ||
} | ||
if (egr::IsVariableCompatTensor(self->tensor)) { | ||
auto* var_tensor = static_cast<const egr::VariableCompatTensor*>( | ||
self->tensor.impl().get()); | ||
if (var_tensor->IsType<paddle::framework::Vocab>()) { | ||
return ToPyObject(framework::proto::VarType::RAW); | ||
} else if (var_tensor->IsType<paddle::framework::Strings>()) { | ||
return ToPyObject(framework::proto::VarType::STRING); | ||
if (FLAGS_enable_pir_api) { | ||
if (!self->tensor.defined()) { | ||
// be same to old dygraph | ||
return ToPyObject(phi::DataType::FLOAT32); | ||
} | ||
if (egr::IsVariableCompatTensor(self->tensor)) { | ||
auto* var_tensor = static_cast<const egr::VariableCompatTensor*>( | ||
self->tensor.impl().get()); | ||
if (var_tensor->IsType<paddle::framework::Vocab>()) { | ||
return ToPyObject(phi::DataType::UNDEFINED); | ||
} else if (var_tensor->IsType<paddle::framework::Strings>()) { | ||
return ToPyObject(phi::DataType::PSTRING); | ||
Comment on lines
+860
to
+863
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR的修改对当前的代码执行应该是没有影响,不过当前pir下的DataType里并没有RAW和STRING类型,需要讨论确认在动态图模式下,此修改对相关模型执行的影响 |
||
} else { | ||
PADDLE_THROW(paddle::platform::errors::Unavailable( | ||
"VariableCompatTensor only support get shape from Vocab or " | ||
"Strings.")); | ||
} | ||
} else { | ||
PADDLE_THROW(paddle::platform::errors::Unavailable( | ||
"VariableCompatTensor only support get shape from Vocab or " | ||
"Strings.")); | ||
return ToPyObject(self->tensor.type()); | ||
} | ||
} else { | ||
return ToPyObject( | ||
paddle::framework::TransToProtoVarType(self->tensor.type())); | ||
if (!self->tensor.defined()) { | ||
// be same to old dygraph | ||
return ToPyObject(framework::proto::VarType::FP32); | ||
} | ||
if (egr::IsVariableCompatTensor(self->tensor)) { | ||
auto* var_tensor = static_cast<const egr::VariableCompatTensor*>( | ||
self->tensor.impl().get()); | ||
if (var_tensor->IsType<paddle::framework::Vocab>()) { | ||
return ToPyObject(framework::proto::VarType::RAW); | ||
} else if (var_tensor->IsType<paddle::framework::Strings>()) { | ||
return ToPyObject(framework::proto::VarType::STRING); | ||
} else { | ||
PADDLE_THROW(paddle::platform::errors::Unavailable( | ||
"VariableCompatTensor only support get shape from Vocab or " | ||
"Strings.")); | ||
} | ||
} else { | ||
return ToPyObject( | ||
paddle::framework::TransToProtoVarType(self->tensor.type())); | ||
} | ||
} | ||
EAGER_CATCH_AND_THROW_RETURN_NULL | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
下面这个分支里的逻辑,后续可以考虑抽离成一个函数,避免if-for的多层嵌套