-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Update c++ readers doc #9352
Merged
JiayiFeng
merged 5 commits into
PaddlePaddle:develop
from
JiayiFeng:doc_update_reader_doc
Mar 29, 2018
Merged
Update c++ readers doc #9352
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
85404d4
update cpp reader doc
JiayiFeng 76fbe42
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
JiayiFeng dd532e2
refine MultiPassReader's doc string
JiayiFeng ce84af6
update
JiayiFeng c488658
follow comments
JiayiFeng 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 |
---|---|---|
|
@@ -113,7 +113,7 @@ To solve this problem, we introduce `ReaderHolder` as a wrapper. It acts as an e | |
|
||
To create and invoke readers, some new ops are introduced: | ||
|
||
### CreateReaderOp | ||
### Operators That Create Readers | ||
|
||
Each reader has its creation op. File readers' creation ops have no input and yield the created file reader as its output. Decorated readers' creation ops take the underlying readers as inputs and then yield new decorated readers. | ||
|
||
|
@@ -153,19 +153,52 @@ double_buffer_reader = create_double_buffer_op(batch_reader) | |
The forwarding ops of the corresponding `main_program` would be like this: | ||
|
||
``` | ||
while_op { | ||
not_completed = true | ||
pass_count = 0 | ||
while_op(not_completed) { | ||
has_next = has_next_op(double_buffer_reader) | ||
if_else_op(has_next) { | ||
batch_data = read_op(double_buffer_reader) | ||
... (subsequent training ops) | ||
} else { | ||
reset_op(double_buffer_reader) | ||
increase_op(pass_count) | ||
not_completed = less_than_op(pass_count, reqiured_pass_num) | ||
} | ||
} | ||
``` | ||
|
||
Two important considerations for these programs are as follows: | ||
A few important considerations for these programs are as follows: | ||
|
||
1. The multiple\_reader is the batch\_reader's underlying reader, and the batch\_reader is the double\_buffer\_reader's underlying reader. `read_op`, `has_next_op` and other reader related ops will only invoke the top-most reader. In this case, it's the double\_buffer\_reader. | ||
1. `not_completed`, `pass_count` and other variables shown above are all Fluid Variables. | ||
|
||
2. All readers exist in both `startup_program` and `main_program`. And they are persistable. | ||
2. The multiple\_reader is the batch\_reader's underlying reader, and the batch\_reader is the double\_buffer\_reader's underlying reader. `read_op`, `has_next_op` and other reader related ops will only invoke the top-most reader. In this case, it's the double\_buffer\_reader. | ||
|
||
3. All readers exist in both `startup_program` and `main_program`. And they are persistable. | ||
|
||
### Simplify Configuration by MultiPassReader | ||
|
||
The Program configuration mentioned above is complicated. Users need to be very familiar to concepts of Program and Block to prevent making mistakes in their code. To make the usage of C++ readers more friendly to new users, we introduce `MultiPassReader`. | ||
|
||
`MultiPassReader` is a decorated reader. A multi-pass reader is used to continuously yield data for several training passes. It takes the number of passes to run as one of its attributes('pass_num') and maintains a counter to record how many passes it has completed. Each time its underlying reader reaches the EOF, the multi-pass reader checks whether it has completed the training of given number of pass. If not, the underlying reader will be re-initialized and starts a new pass automatically. Before completing the whole training, the return of MultiPassReader's `HasNext()` will always be `true`. | ||
|
||
With `MultiPassReader`, the startup program would be like this: | ||
|
||
``` | ||
multiple_reader = open_files_op(...) | ||
batch_reader = create_batch_reader_op(multiple_reader) | ||
multi_pass_reader = create_multi_pass_reader_op(batch_reader) | ||
double_buffer_reader = create_double_buffer_op(multi_pass_reader) | ||
... (other initializers) | ||
``` | ||
|
||
The forwarding part of the corresponding `main_program` would be like this: | ||
|
||
``` | ||
not_completed = true | ||
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.
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. They are Fluid Variables. See my above comment. |
||
while_op(not_completed) { | ||
batch_data = read_op(double_buffer_reader) | ||
... (subsequent training ops) | ||
not_completed = has_next_op(double_buffer_reader) | ||
} | ||
``` |
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
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.
pass_count
is a Python variable, not a ProgramDesc Var, does it work?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.
not_completed
andpass_count
are both ProgramDesc Var. Sorry I didn't make it clear.