@ -0,0 +1,121 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import io, re
|
||||
import sys, os
|
||||
import subprocess
|
||||
import platform
|
||||
|
||||
COPYRIGHT = '''
|
||||
Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
'''
|
||||
|
||||
LANG_COMMENT_MARK = None
|
||||
|
||||
NEW_LINE_MARK = None
|
||||
|
||||
COPYRIGHT_HEADER = None
|
||||
|
||||
if platform.system() == "Windows":
|
||||
NEW_LINE_MARK = "\r\n"
|
||||
else:
|
||||
NEW_LINE_MARK = '\n'
|
||||
COPYRIGHT_HEADER = COPYRIGHT.split(NEW_LINE_MARK)[1]
|
||||
p = re.search('(\d{4})', COPYRIGHT_HEADER).group(0)
|
||||
process = subprocess.Popen(["date", "+%Y"], stdout=subprocess.PIPE)
|
||||
date, err = process.communicate()
|
||||
date = date.decode("utf-8").rstrip("\n")
|
||||
COPYRIGHT_HEADER = COPYRIGHT_HEADER.replace(p, date)
|
||||
|
||||
|
||||
def generate_copyright(template, lang='C'):
|
||||
if lang == 'Python':
|
||||
LANG_COMMENT_MARK = '#'
|
||||
else:
|
||||
LANG_COMMENT_MARK = "//"
|
||||
|
||||
lines = template.split(NEW_LINE_MARK)
|
||||
BLANK = " "
|
||||
ans = LANG_COMMENT_MARK + BLANK + COPYRIGHT_HEADER + NEW_LINE_MARK
|
||||
for lino, line in enumerate(lines):
|
||||
if lino == 0 or lino == 1 or lino == len(lines) - 1: continue
|
||||
if len(line) == 0:
|
||||
BLANK = ""
|
||||
else:
|
||||
BLANK = " "
|
||||
ans += LANG_COMMENT_MARK + BLANK + line + NEW_LINE_MARK
|
||||
|
||||
return ans + "\n"
|
||||
|
||||
|
||||
def lang_type(filename):
|
||||
if filename.endswith(".py"):
|
||||
return "Python"
|
||||
elif filename.endswith(".h"):
|
||||
return "C"
|
||||
elif filename.endswith(".c"):
|
||||
return "C"
|
||||
elif filename.endswith(".hpp"):
|
||||
return "C"
|
||||
elif filename.endswith(".cc"):
|
||||
return "C"
|
||||
elif filename.endswith(".cpp"):
|
||||
return "C"
|
||||
elif filename.endswith(".cu"):
|
||||
return "C"
|
||||
elif filename.endswith(".cuh"):
|
||||
return "C"
|
||||
elif filename.endswith(".go"):
|
||||
return "C"
|
||||
elif filename.endswith(".proto"):
|
||||
return "C"
|
||||
else:
|
||||
print("Unsupported filetype %s", filename)
|
||||
exit(0)
|
||||
|
||||
|
||||
PYTHON_ENCODE = re.compile("^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)")
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Checker for copyright declaration.')
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to check')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retv = 0
|
||||
for filename in args.filenames:
|
||||
fd = io.open(filename, encoding="utf-8")
|
||||
first_line = fd.readline()
|
||||
second_line = fd.readline()
|
||||
if "COPYRIGHT (C)" in first_line.upper(): continue
|
||||
if first_line.startswith("#!") or PYTHON_ENCODE.match(
|
||||
second_line) != None or PYTHON_ENCODE.match(first_line) != None:
|
||||
continue
|
||||
original_contents = io.open(filename, encoding="utf-8").read()
|
||||
new_contents = generate_copyright(
|
||||
COPYRIGHT, lang_type(filename)) + original_contents
|
||||
print('Auto Insert Copyright Header {}'.format(filename))
|
||||
retv = 1
|
||||
with io.open(filename, 'w') as output_file:
|
||||
output_file.write(new_contents)
|
||||
|
||||
return retv
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at paddle-dev@baidu.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
@ -0,0 +1,78 @@
|
||||
# Cluster Training Benchmark
|
||||
|
||||
## Setup
|
||||
|
||||
- Platform
|
||||
- Kubernetes: v1.6.2
|
||||
- Linux Kernel: v3.10.0
|
||||
|
||||
- Resource
|
||||
- CPU: 10 Cores per Pod
|
||||
- Memory: 5GB per Pod
|
||||
|
||||
- Docker Image
|
||||
|
||||
We use different base Docker Image to run the benchmark on Kubernetes:
|
||||
- PaddlePaddle v2: paddlepaddle/paddle:0.11.0
|
||||
- PaddlePaddle Fluid: paddlepaddle/paddle:[commit-id]
|
||||
- TensorFlow: tensorflow/tensorflow:1.5.0-rc0
|
||||
|
||||
- Model
|
||||
vgg16 is used in this benchmark.
|
||||
|
||||
## Cases
|
||||
|
||||
- Variable
|
||||
- Batch Size of training data.
|
||||
- PServer count of the training job.
|
||||
- The number of trainers.
|
||||
|
||||
- Invariant
|
||||
- The resource of trainer/pserver Pod.
|
||||
|
||||
### Measure the Performance for Different Batch Size
|
||||
|
||||
- PServer Count: 40
|
||||
- Trainer Count: 100
|
||||
- Metrics: mini-batch / sec
|
||||
|
||||
| Batch Size | 32 | 64 | 128 | 256 |
|
||||
| -- | -- | -- | -- | -- |
|
||||
| PaddlePaddle Fluid | - | - | - | - |
|
||||
| PaddlePaddle v2 | - | - | - | - |
|
||||
| TensorFlow | - | - | - | - |
|
||||
|
||||
### Measure the Performance for Different PServer Count
|
||||
|
||||
- Trainer Count: 100
|
||||
- Batch Size: 64
|
||||
- Metrics: mini-batch / sec
|
||||
|
||||
| PServer Count | 10 | 20 | 40 | 60 |
|
||||
| -- | -- | -- | -- | -- |
|
||||
| PaddlePaddle Fluid | - | - | - | - |
|
||||
| PaddlePaddle v2 | - | - | - | - |
|
||||
| TensorFlow | - | - | - | - |
|
||||
|
||||
### Measure Parallel Efficiency By Increasing Trainer Count
|
||||
|
||||
- PServer Count: 20
|
||||
- Batch Size: 64
|
||||
- Metrics:
|
||||
|
||||
$S = \div(T1, TN)$
|
||||
|
||||
which S is the ratio of T1 over TN, training time of 1 and N trainers.
|
||||
The parallel efficiency is:
|
||||
|
||||
$E = \div(S, N)$
|
||||
|
||||
| Trainer Counter | 1 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 |
|
||||
| -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- |
|
||||
| PaddlePaddle Fluid | - | - | - | - | - | - | - | - | - | - | - |
|
||||
| PaddlePaddle v2 | - | - | - | - | - | - | - | - | - | - | - | - |
|
||||
| TensorFlow | - | - | - | - | - | - | - | - | - | - | - | - | - |
|
||||
|
||||
## Reproduce the benchmark
|
||||
|
||||
TODO
|
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,114 @@
|
||||
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser('Parse Log')
|
||||
parser.add_argument(
|
||||
'--file_path', '-f', type=str, help='the path of the log file')
|
||||
parser.add_argument(
|
||||
'--sample_rate',
|
||||
'-s',
|
||||
type=float,
|
||||
default=1.0,
|
||||
help='the rate to take samples from log')
|
||||
parser.add_argument(
|
||||
'--log_period', '-p', type=int, default=1, help='the period of log')
|
||||
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
def parse_file(file_name):
|
||||
loss = []
|
||||
error = []
|
||||
with open(file_name) as f:
|
||||
for i, line in enumerate(f):
|
||||
line = line.strip()
|
||||
if not line.startswith('pass'):
|
||||
continue
|
||||
line_split = line.split(' ')
|
||||
if len(line_split) != 5:
|
||||
continue
|
||||
|
||||
loss_str = line_split[2][:-1]
|
||||
cur_loss = float(loss_str.split('=')[-1])
|
||||
loss.append(cur_loss)
|
||||
|
||||
err_str = line_split[3][:-1]
|
||||
cur_err = float(err_str.split('=')[-1])
|
||||
error.append(cur_err)
|
||||
|
||||
accuracy = [1.0 - err for err in error]
|
||||
|
||||
return loss, accuracy
|
||||
|
||||
|
||||
def sample(metric, sample_rate):
|
||||
interval = int(1.0 / sample_rate)
|
||||
if interval > len(metric):
|
||||
return metric[:1]
|
||||
|
||||
num = len(metric) / interval
|
||||
idx = [interval * i for i in range(num)]
|
||||
metric_sample = [metric[id] for id in idx]
|
||||
return metric_sample
|
||||
|
||||
|
||||
def plot_metric(metric,
|
||||
batch_id,
|
||||
graph_title,
|
||||
line_style='b-',
|
||||
line_label='y',
|
||||
line_num=1):
|
||||
plt.figure()
|
||||
plt.title(graph_title)
|
||||
if line_num == 1:
|
||||
plt.plot(batch_id, metric, line_style, label=line_label)
|
||||
else:
|
||||
for i in range(line_num):
|
||||
plt.plot(batch_id, metric[i], line_style[i], label=line_label[i])
|
||||
plt.xlabel('batch')
|
||||
plt.ylabel(graph_title)
|
||||
plt.legend()
|
||||
plt.savefig(graph_title + '.jpg')
|
||||
plt.close()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
assert args.sample_rate > 0. and args.sample_rate <= 1.0, "The sample rate should in the range (0, 1]."
|
||||
|
||||
loss, accuracy = parse_file(args.file_path)
|
||||
batch = [args.log_period * i for i in range(len(loss))]
|
||||
|
||||
batch_sample = sample(batch, args.sample_rate)
|
||||
loss_sample = sample(loss, args.sample_rate)
|
||||
accuracy_sample = sample(accuracy, args.sample_rate)
|
||||
|
||||
plot_metric(loss_sample, batch_sample, 'loss', line_label='loss')
|
||||
plot_metric(
|
||||
accuracy_sample,
|
||||
batch_sample,
|
||||
'accuracy',
|
||||
line_style='g-',
|
||||
line_label='accuracy')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,69 @@
|
||||
set -e
|
||||
|
||||
function clock_to_seconds() {
|
||||
hours=`echo $1 | awk -F ':' '{print $1}'`
|
||||
mins=`echo $1 | awk -F ':' '{print $2}'`
|
||||
secs=`echo $1 | awk -F ':' '{print $3}'`
|
||||
echo `awk 'BEGIN{printf "%.2f",('$secs' + '$mins' * 60 + '$hours' * 3600)}'`
|
||||
}
|
||||
|
||||
function infer() {
|
||||
export OPENBLAS_MAIN_FREE=1
|
||||
topology=$1
|
||||
layer_num=$2
|
||||
bs=$3
|
||||
trainers=`nproc`
|
||||
if [ $trainers -gt $bs ]; then
|
||||
trainers=$bs
|
||||
fi
|
||||
log="logs/infer-${topology}-${layer_num}-${trainers}openblas-${bs}.log"
|
||||
threads=$((`nproc` / trainers))
|
||||
if [ $threads -eq 0 ]; then
|
||||
threads=1
|
||||
fi
|
||||
export OPENBLAS_NUM_THREADS=$threads
|
||||
|
||||
models_in="models/${topology}-${layer_num}/pass-00000/"
|
||||
if [ ! -d $models_in ]; then
|
||||
echo "./run_mkl_infer.sh to save the model first"
|
||||
exit 0
|
||||
fi
|
||||
log_period=$((32 / bs))
|
||||
paddle train --job=test \
|
||||
--config="${topology}.py" \
|
||||
--use_mkldnn=False \
|
||||
--use_gpu=False \
|
||||
--trainer_count=$trainers \
|
||||
--log_period=$log_period \
|
||||
--config_args="batch_size=${bs},layer_num=${layer_num},is_infer=True,num_samples=256" \
|
||||
--init_model_path=$models_in \
|
||||
2>&1 | tee ${log}
|
||||
|
||||
# calculate the last 5 logs period time of 160(=32*5) samples,
|
||||
# the time before are burning time.
|
||||
start=`tail ${log} -n 7 | head -n 1 | awk -F ' ' '{print $2}' | xargs`
|
||||
end=`tail ${log} -n 2 | head -n 1 | awk -F ' ' '{print $2}' | xargs`
|
||||
start_sec=`clock_to_seconds $start`
|
||||
end_sec=`clock_to_seconds $end`
|
||||
fps=`awk 'BEGIN{printf "%.2f",(160 / ('$end_sec' - '$start_sec'))}'`
|
||||
echo "Last 160 samples start: ${start}(${start_sec} sec), end: ${end}(${end_sec} sec;" >> ${log}
|
||||
echo "FPS: $fps images/sec" 2>&1 | tee -a ${log}
|
||||
}
|
||||
|
||||
if [ ! -f "train.list" ]; then
|
||||
echo " " > train.list
|
||||
fi
|
||||
if [ ! -f "test.list" ]; then
|
||||
echo " " > test.list
|
||||
fi
|
||||
if [ ! -d "logs" ]; then
|
||||
mkdir logs
|
||||
fi
|
||||
|
||||
# inference benchmark
|
||||
for batchsize in 1 2 4 8 16; do
|
||||
infer vgg 19 $batchsize
|
||||
infer resnet 50 $batchsize
|
||||
infer googlenet v1 $batchsize
|
||||
infer alexnet 2 $batchsize
|
||||
done
|