-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
CustomReader #10872
CustomReader #10872
Conversation
… dev_CustomReader
… dev_CustomReader
} | ||
PADDLE_ENFORCE( | ||
source_var_names_.size() == underlying_outs.size() && | ||
sink_var_names_.size() == underlying_outs.size(), |
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.
sink_var_names maybe not equal with source_var_names.size()
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.
Fixed. Thanks!
// The scope for CustomReader's sub-block should be independent and shouldn't | ||
// be any other computation scope's child. Otherwise, data preprocessing and | ||
// compution cannot be concurrent. | ||
auto* scope = new framework::Scope(); |
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.
Well, it is no need to new Scope()
. Just
Scope scope;
is cool
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.
Good idea.
out->resize(sink_var_names_.size()); | ||
for (size_t i = 0; i < sink_var_names_.size(); ++i) { | ||
framework::Variable* var = scope->FindVar(sink_var_names_[i]); | ||
PADDLE_ENFORCE_NOT_NULL(var); |
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.
Maybe fluid/operator/detail/safe_ref.h
is good?
auto& tensor = detail::Ref(scope->FindVar(sink_var_names_[i])).Get<framework::LoDTensor>()
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.
Cool!
python/paddle/fluid/layers/io.py
Outdated
source_lod_levels = self.underlying_reader.desc.lod_levels() | ||
self.source_var_names = [] | ||
source_vars = [] | ||
for idx in xrange(len(source_shapes)): |
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.
Maybe more pythonic way
source_var_names = (unique_name("preprocessor_source") for _ in xrange(len(source_shapes)))
for var_name, shape, dtype, lod_level in zip(source_var_names, source_shapes, source_dtypes, source_lod_levels):
pass
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.
Amazing!
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.
Excellent
fixes #10873