Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
9672e503
Commit
9672e503
authored
Oct 31, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use too many prediction_incorrect
parent
86c9df35
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
21 deletions
+21
-21
docs/tutorial/performance-tuning.md
docs/tutorial/performance-tuning.md
+5
-2
examples/cifar-convnet.py
examples/cifar-convnet.py
+4
-3
examples/mnist-convnet.py
examples/mnist-convnet.py
+1
-4
examples/mnist-keras.py
examples/mnist-keras.py
+4
-4
examples/mnist-tfslim.py
examples/mnist-tfslim.py
+4
-4
tensorpack/callbacks/inference.py
tensorpack/callbacks/inference.py
+3
-4
No files found.
docs/tutorial/performance-tuning.md
View file @
9672e503
...
@@ -10,7 +10,7 @@ Here's a list of things you can do when your training is slow:
...
@@ -10,7 +10,7 @@ Here's a list of things you can do when your training is slow:
2.
If you use queue-based input + dataflow, you can look for the queue size statistics in
2.
If you use queue-based input + dataflow, you can look for the queue size statistics in
training log. Ideally the queue should be near-full (default size is 50).
training log. Ideally the queue should be near-full (default size is 50).
If the size is near-zero, data is the bottleneck.
If the size is near-zero, data is the bottleneck.
3.
If the GPU utilization is low, it may be because of slow data, or some ops are
on CPU
. Also make sure GPUs are not locked in P8 state.
3.
If the GPU utilization is low, it may be because of slow data, or some ops are
inefficient
. Also make sure GPUs are not locked in P8 state.
## Benchmark the components
## Benchmark the components
1.
Use
`DummyConstantInput(shapes)`
as the
`InputSource`
.
1.
Use
`DummyConstantInput(shapes)`
as the
`InputSource`
.
...
@@ -67,7 +67,10 @@ But there may be something cheap you can try:
...
@@ -67,7 +67,10 @@ But there may be something cheap you can try:
### Cannot scale to multi-GPU
### Cannot scale to multi-GPU
If you're unable to scale to multiple GPUs almost linearly:
If you're unable to scale to multiple GPUs almost linearly:
1.
First make sure that the ResNet example can scale. Run it with
`--fake`
to use fake data.
1.
First make sure that the ResNet example can scale. Run it with
`--fake`
to use fake data.
2.
Then note that your model may have a different communication-computation pattern.
If not, it's a bug or an environment setup problem.
2.
Then note that your model may have a different communication-computation pattern or other
characteristics that affects efficiency.
There isn't a simple answer to this.
Changing different multi-GPU trainers may affect the speed significantly sometimes.
Changing different multi-GPU trainers may affect the speed significantly sometimes.
Note that scalibility measurement always trains with the same "batch size per GPU", not the same total equivalent batch size.
Note that scalibility measurement always trains with the same "batch size per GPU", not the same total equivalent batch size.
examples/cifar-convnet.py
View file @
9672e503
...
@@ -67,9 +67,9 @@ class Model(ModelDesc):
...
@@ -67,9 +67,9 @@ class Model(ModelDesc):
cost
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
=
logits
,
labels
=
label
)
cost
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
=
logits
,
labels
=
label
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
wrong
=
symbf
.
prediction_incorrect
(
logits
,
label
)
correct
=
tf
.
to_float
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
1
),
name
=
'correct'
)
# monitor training error
# monitor training error
add_moving_summary
(
tf
.
reduce_mean
(
wrong
,
name
=
'train_error
'
))
add_moving_summary
(
tf
.
reduce_mean
(
correct
,
name
=
'accuracy
'
))
# weight decay on all W of fc layers
# weight decay on all W of fc layers
wd_cost
=
regularize_cost
(
'fc.*/W'
,
l2_regularizer
(
4e-4
),
name
=
'regularize_loss'
)
wd_cost
=
regularize_cost
(
'fc.*/W'
,
l2_regularizer
(
4e-4
),
name
=
'regularize_loss'
)
...
@@ -127,7 +127,8 @@ def get_config(cifar_classnum):
...
@@ -127,7 +127,8 @@ def get_config(cifar_classnum):
dataflow
=
dataset_train
,
dataflow
=
dataset_train
,
callbacks
=
[
callbacks
=
[
ModelSaver
(),
ModelSaver
(),
InferenceRunner
(
dataset_test
,
ClassificationError
()),
InferenceRunner
(
dataset_test
,
ScalarStats
([
'accuracy'
,
'cost'
])),
StatMonitorParamSetter
(
'learning_rate'
,
'val_error'
,
lr_func
,
StatMonitorParamSetter
(
'learning_rate'
,
'val_error'
,
lr_func
,
threshold
=
0.001
,
last_k
=
10
),
threshold
=
0.001
,
last_k
=
10
),
],
],
...
...
examples/mnist-convnet.py
View file @
9672e503
...
@@ -63,7 +63,6 @@ class Model(ModelDesc):
...
@@ -63,7 +63,6 @@ class Model(ModelDesc):
cost
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
=
logits
,
labels
=
label
)
cost
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
=
logits
,
labels
=
label
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
# the average cross-entropy loss
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
# the average cross-entropy loss
# compute the "correct vector", for the callback ClassificationError to use at validation time
correct
=
tf
.
cast
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
1
),
tf
.
float32
,
name
=
'correct'
)
correct
=
tf
.
cast
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
1
),
tf
.
float32
,
name
=
'correct'
)
accuracy
=
tf
.
reduce_mean
(
correct
,
name
=
'accuracy'
)
accuracy
=
tf
.
reduce_mean
(
correct
,
name
=
'accuracy'
)
...
@@ -118,9 +117,7 @@ def get_config():
...
@@ -118,9 +117,7 @@ def get_config():
MaxSaver
(
'validation_accuracy'
),
# save the model with highest accuracy (prefix 'validation_')
MaxSaver
(
'validation_accuracy'
),
# save the model with highest accuracy (prefix 'validation_')
InferenceRunner
(
# run inference(for validation) after every epoch
InferenceRunner
(
# run inference(for validation) after every epoch
dataset_test
,
# the DataFlow instance used for validation
dataset_test
,
# the DataFlow instance used for validation
# Calculate both the cost and the accuracy for this DataFlow
ScalarStats
([
'cross_entropy_loss'
,
'accuracy'
])),
[
ScalarStats
(
'cross_entropy_loss'
),
ClassificationError
(
'correct'
,
'validation_accuracy'
)]),
],
],
steps_per_epoch
=
steps_per_epoch
,
steps_per_epoch
=
steps_per_epoch
,
max_epoch
=
100
,
max_epoch
=
100
,
...
...
examples/mnist-keras.py
View file @
9672e503
...
@@ -61,9 +61,9 @@ class Model(ModelDesc):
...
@@ -61,9 +61,9 @@ class Model(ModelDesc):
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
# the average cross-entropy loss
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
# the average cross-entropy loss
# for tensorpack validation
# for tensorpack validation
wrong
=
symbolic_functions
.
prediction_incorrect
(
logits
,
label
,
name
=
'incorrect'
)
acc
=
tf
.
to_float
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
1
)
)
train_error
=
tf
.
reduce_mean
(
wrong
,
name
=
'train_error
'
)
acc
=
tf
.
reduce_mean
(
acc
,
name
=
'accuracy
'
)
summary
.
add_moving_summary
(
train_error
)
summary
.
add_moving_summary
(
acc
)
wd_cost
=
tf
.
add_n
(
M
.
losses
,
name
=
'regularize_loss'
)
# this is how Keras manage regularizers
wd_cost
=
tf
.
add_n
(
M
.
losses
,
name
=
'regularize_loss'
)
# this is how Keras manage regularizers
self
.
cost
=
tf
.
add_n
([
wd_cost
,
cost
],
name
=
'total_cost'
)
self
.
cost
=
tf
.
add_n
([
wd_cost
,
cost
],
name
=
'total_cost'
)
...
@@ -97,7 +97,7 @@ if __name__ == '__main__':
...
@@ -97,7 +97,7 @@ if __name__ == '__main__':
ModelSaver
(),
ModelSaver
(),
InferenceRunner
(
InferenceRunner
(
dataset_test
,
dataset_test
,
[
ScalarStats
(
'cross_entropy_loss'
),
ClassificationError
(
'incorrect'
)]
),
ScalarStats
([
'cross_entropy_loss'
,
'accuracy'
])
),
],
],
max_epoch
=
100
,
max_epoch
=
100
,
)
)
...
...
examples/mnist-tfslim.py
View file @
9672e503
...
@@ -53,10 +53,10 @@ class Model(ModelDesc):
...
@@ -53,10 +53,10 @@ class Model(ModelDesc):
cost
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
=
logits
,
labels
=
label
)
cost
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
=
logits
,
labels
=
label
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
cost
=
tf
.
reduce_mean
(
cost
,
name
=
'cross_entropy_loss'
)
wrong
=
symbolic_functions
.
prediction_incorrect
(
logits
,
label
,
name
=
'incorrect'
)
acc
=
tf
.
to_float
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
1
)
)
train_error
=
tf
.
reduce_mean
(
wrong
,
name
=
'train_error
'
)
acc
=
tf
.
reduce_mean
(
acc
,
name
=
'accuracy
'
)
summary
.
add_moving_summary
(
train_error
)
summary
.
add_moving_summary
(
acc
)
self
.
cost
=
cost
self
.
cost
=
cost
summary
.
add_moving_summary
(
cost
)
summary
.
add_moving_summary
(
cost
)
...
@@ -88,7 +88,7 @@ def get_config():
...
@@ -88,7 +88,7 @@ def get_config():
ModelSaver
(),
ModelSaver
(),
InferenceRunner
(
InferenceRunner
(
dataset_test
,
dataset_test
,
[
ScalarStats
(
'cross_entropy_loss'
),
ClassificationError
(
'incorrect'
)]
),
ScalarStats
([
'cross_entropy_loss'
,
'accuracy'
])
),
],
],
max_epoch
=
100
,
max_epoch
=
100
,
)
)
...
...
tensorpack/callbacks/inference.py
View file @
9672e503
...
@@ -139,8 +139,9 @@ class ClassificationError(Inferencer):
...
@@ -139,8 +139,9 @@ class ClassificationError(Inferencer):
whether each sample in the batch is *incorrectly* classified.
whether each sample in the batch is *incorrectly* classified.
You can use ``tf.nn.in_top_k`` to produce this vector.
You can use ``tf.nn.in_top_k`` to produce this vector.
This Inferencer produces the "true" error,
This Inferencer produces the "true" error, which could be different from
taking account of the fact that batches might not have the same size in
`ScalarStats('error_rate')`.
It takes account of the fact that batches might not have the same size in
testing (because the size of test set might not be a multiple of batch size).
testing (because the size of test set might not be a multiple of batch size).
Therefore the result can be different from averaging the error rate of each batch.
Therefore the result can be different from averaging the error rate of each batch.
...
@@ -152,8 +153,6 @@ class ClassificationError(Inferencer):
...
@@ -152,8 +153,6 @@ class ClassificationError(Inferencer):
"""
"""
Args:
Args:
wrong_tensor_name(str): name of the ``wrong`` tensor.
wrong_tensor_name(str): name of the ``wrong`` tensor.
The default is the same as the default output name of
:meth:`prediction_incorrect`.
summary_name(str): the name to log the error with.
summary_name(str): the name to log the error with.
"""
"""
self
.
wrong_tensor_name
=
wrong_tensor_name
self
.
wrong_tensor_name
=
wrong_tensor_name
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment