Skip to content

Commit deec01b

Browse files
authored
Add doc ci (OpenPPL#112)
* CI(github): add lint * update * update * update * docs(ppq): update doc and add ci
1 parent 84df014 commit deec01b

File tree

151 files changed

+2642
-2803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+2642
-2803
lines changed

.github/workflows/lint.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-18.04
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python 3.7
11+
uses: actions/setup-python@v2
12+
with:
13+
python-version: 3.7
14+
- name: Install pre-commit hook
15+
run: |
16+
# markdownlint requires ruby >= 2.7
17+
sudo apt-add-repository ppa:brightbox/ruby-ng -y
18+
sudo apt-get update
19+
sudo apt-get install -y ruby2.7
20+
pip install pre-commit
21+
pre-commit install

.github/workflows/ppq_simulator.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030

3131
- name: Test
3232
run: |
33-
cd ../../ && ./test_ppq.sh ${{ github.run_id }}
33+
cd ../../ && ./test_ppq.sh ${{ github.run_id }}

.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: check-yaml
7+
- id: end-of-file-fixer
8+
- id: requirements-txt-fixer
9+
- id: double-quote-string-fixer
10+
- id: check-merge-conflict
11+
- id: fix-encoding-pragma
12+
args: ["--remove"]
13+
- id: mixed-line-ending
14+
args: ["--fix=lf"]
15+
- repo: https://github.com/markdownlint/markdownlint
16+
rev: v0.11.0
17+
hooks:
18+
- id: markdownlint
19+
args:
20+
[
21+
"-r",
22+
"~MD002,~MD013,~MD029,~MD033,~MD034",
23+
"-t",
24+
"allow_different_nesting",
25+
]
26+
- repo: https://github.com/myint/docformatter
27+
rev: v1.4
28+
hooks:
29+
- id: docformatter
30+
args: ["--in-place", "--wrap-descriptions", "79"]

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,4 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
include ppq/parser/caffe/*
22
include ppq/csrc/cuda/*
3-
include ppq/csrc/build/readme.md
3+
include ppq/csrc/build/readme.md

ProgramEntrance.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
"""
2-
这是一个 PPQ 量化的入口脚本,将你的模型和数据按要求进行打包:
1+
"""这是一个 PPQ 量化的入口脚本,将你的模型和数据按要求进行打包:
32
4-
This file will show you how to quantize your network with PPQ
5-
You should prepare your model and calibration dataset as follow:
3+
This file will show you how to quantize your network with PPQ
4+
You should prepare your model and calibration dataset as follow:
65
7-
~/working/model.onnx <-- your model
8-
~/working/data/*.npy or ~/working/data/*.bin <-- your dataset
6+
~/working/model.onnx <-- your model
7+
~/working/data/*.npy or ~/working/data/*.bin <-- your dataset
98
10-
if you are using caffe model:
11-
~/working/model.caffemdoel <-- your model
12-
~/working/model.prototext <-- your model
9+
if you are using caffe model:
10+
~/working/model.caffemdoel <-- your model
11+
~/working/model.prototext <-- your model
1312
14-
### MAKE SURE YOUR INPUT LAYOUT IS [N, C, H, W] or [C, H, W] ###
13+
### MAKE SURE YOUR INPUT LAYOUT IS [N, C, H, W] or [C, H, W] ###
1514
16-
quantized model will be generated at: ~/working/quantized.onnx
15+
quantized model will be generated at: ~/working/quantized.onnx
1716
"""
1817
from ppq import *
1918
from ppq.IR.processor import GraphCommandProcessor

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ PPL QuantTool 是一个工业级的神经网络量化工具:我们已经准备
1010

1111
PPQ 使用量化计算图(QIR)描述量化细节,即便在网络极度复杂的情况下,我们依然能够保证以正确的方法模拟硬件计算,从而降低模拟误差。我们知晓硬件的运算细节——在所有已知平台上,PPQ 的模拟误差不超过1%,且保证模拟误差不会指数级扩散。PPQ 有着自定义的量化算子库、网络执行器、调度器与异构执行能力,在网络量化与量化训练方面,使用 PPQ 比原生 PyTorch 快3 ~ 50倍。 借助 PPQ, OpenPPL, TensorRT, Tengine等框架,开发者可以将神经网络模型加速5 ~ 10倍,并部署到多种多样的目标终端,我们期待你将人工智慧真正带到千家万户之间。
1212

13-
### Acceptable Framework:
13+
### Acceptable Framework:
1414
PyTorch | TensorFlow | Caffe | ONNX | MMlab
1515

1616
### Deploy Platform:
1717
TensorRT | OpenPPL-CUDA | OpenPPL-DSP | SNPE(Qualcomm) | NXP | Metax | Tengine(Developing) | Ncnn(Developing)
18-
|
18+
|
1919
# Video Tutorial(Bilibili 视频教程)
2020
Watch video tutorial series on www.bilibili.com, following are links of PPQ tutorial links(Only Chinese version).
2121

22-
* 安装教程: [https://www.bilibili.com/video/BV1WS4y1N7Kn](https://www.bilibili.com/video/BV1WS4y1N7Kn "PPQ Installation Tutorial")
23-
* 使用教程: [https://www.bilibili.com/video/BV1934y147p2](https://www.bilibili.com/video/BV1934y147p2 "PPQ User Guide")
24-
* 基础知识:[https://www.bilibili.com/video/BV1gS4y1Y7KR](https://www.bilibili.com/video/BV1gS4y1Y7KR "Basic Theory")
25-
* 网络性能分析:[https://www.bilibili.com/video/BV1oT4y1h73e](https://www.bilibili.com/video/BV1oT4y1h73e "Analysing Your Model")
26-
* 量化计算原理(Part 1):[https://www.bilibili.com/video/BV1fB4y1m7fJ](https://www.bilibili.com/video/BV1fB4y1m7fJ "Quantized Computing")
27-
* 量化计算原理(Part 2):[https://www.bilibili.com/video/BV1qA4y1Q7Uh](https://www.bilibili.com/video/BV1qA4y1Q7Uh "Quantized Computing")
28-
* 图优化与量化模拟:[https://www.bilibili.com/video/BV1Kr4y1n7cy](https://www.bilibili.com/video/BV1Kr4y1n7cy "Graph Optimization & quantization simulating.")
29-
* 图调度与模式匹配:[https://www.bilibili.com/video/BV1xY411A7ea](https://www.bilibili.com/video/BV1xY411A7ea "Graph Dispatching & Pattern Matching.")
22+
* 安装教程: [https://www.bilibili.com/video/BV1WS4y1N7Kn](https://www.bilibili.com/video/BV1WS4y1N7Kn "PPQ Installation Tutorial")
23+
* 使用教程: [https://www.bilibili.com/video/BV1934y147p2](https://www.bilibili.com/video/BV1934y147p2 "PPQ User Guide")
24+
* 基础知识:[https://www.bilibili.com/video/BV1gS4y1Y7KR](https://www.bilibili.com/video/BV1gS4y1Y7KR "Basic Theory")
25+
* 网络性能分析:[https://www.bilibili.com/video/BV1oT4y1h73e](https://www.bilibili.com/video/BV1oT4y1h73e "Analysing Your Model")
26+
* 量化计算原理(Part 1):[https://www.bilibili.com/video/BV1fB4y1m7fJ](https://www.bilibili.com/video/BV1fB4y1m7fJ "Quantized Computing")
27+
* 量化计算原理(Part 2):[https://www.bilibili.com/video/BV1qA4y1Q7Uh](https://www.bilibili.com/video/BV1qA4y1Q7Uh "Quantized Computing")
28+
* 图优化与量化模拟:[https://www.bilibili.com/video/BV1Kr4y1n7cy](https://www.bilibili.com/video/BV1Kr4y1n7cy "Graph Optimization & quantization simulating.")
29+
* 图调度与模式匹配:[https://www.bilibili.com/video/BV1xY411A7ea](https://www.bilibili.com/video/BV1xY411A7ea "Graph Dispatching & Pattern Matching.")
3030

3131
* 其他教程: 等待缓慢更新...
3232

@@ -47,7 +47,7 @@ ATTENTION: Make sure your Python version is >= 3.6.0. PPL Quantization Tool is w
4747

4848
* For Windows User:
4949
* Download ninja.exe from [https://github.com/ninja-build/ninja/releases](https://github.com/ninja-build/ninja/releases), add it to Windows PATH Environment
50-
* Download Visual Studio from [https://visualstudio.microsoft.com](https://visualstudio.microsoft.com/zh-hans/), if you already got a c++ compiler, you can skip this step.
50+
* Download Visual Studio from [https://visualstudio.microsoft.com](https://visualstudio.microsoft.com/zh-hans/), if you already got a c++ compiler, you can skip this step.
5151
* Please Update Visual studio to 2019, otherwise there might be some compile error like: CxxFrameHandler4 unresolved, GSHandlerCheck unresolved.
5252
* Add your c++ compiler to Windows PATH Environment, if you are using Visual Studio, it should be something like "C:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86"
5353

@@ -70,7 +70,7 @@ python setup.py install
7070

7171
```bash
7272
python3 -m pip install ppq
73-
```
73+
```
7474

7575
# Tutorials and Running Examples
7676

Util.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def load_calibration_dataset(directory: str, input_shape: List[int], batchsize:
6565
for idx, tensor in enumerate(samples[: 5]):
6666
print(f'Loaded sample {idx}, shape: {tensor.shape}')
6767
assert len(batches) > 0, '你送入了空的数据集'
68-
68+
6969
print(f'Batch Shape: {batches[0].shape}')
7070
return batches
7171

@@ -116,7 +116,7 @@ def export(working_directory: str, quantized: BaseGraph, platform: TargetPlatfor
116116

117117

118118
def load_from_file(
119-
filename: str, dtype: np.dtype = np.float32,
119+
filename: str, dtype: np.dtype = np.float32,
120120
shape: List[int] = None, format: str = '.npy') -> np.ndarray:
121121
if not os.path.exists(filename) or os.path.isdir(filename):
122122
raise FileNotFoundError(f'Can not load data from file: {filename}. '
@@ -135,14 +135,14 @@ def load_from_file(
135135

136136

137137
def dump_to_file(
138-
filename: str, data: Union[torch.Tensor, np.ndarray],
138+
filename: str, data: Union[torch.Tensor, np.ndarray],
139139
format: str = '.npy') -> None:
140140
if os.path.isdir(filename):
141141
raise FileExistsError(f'Can not dump data to file: {filename}',
142142
' Cause it is a directory.')
143143
if os.path.exists(filename):
144144
ppq_warning(f'Overwritting file {filename} ...')
145-
145+
146146
data = convert_any_to_numpy(data)
147147
if format == '.npy':
148148
np.save(file=filename, arr=data)
@@ -180,24 +180,24 @@ def compare_cosine_similarity_between_results(
180180

181181
print(f'总计 {len(samples)} 个 Sample 被检出,{len(outputs)} 个待测输出 Variable')
182182
recorders = {name: MeasureRecorder(measurement=method) for name in outputs}
183-
183+
184184
for sample_name in samples:
185185
for output in outputs:
186186

187187
ref_file = os.path.join(ref_dir, sample_name, output)
188188
target_file = os.path.join(target_dir, sample_name, output)
189-
189+
190190
ref = load_from_file(filename=ref_file, format='.dat')[:1000]
191191
target = load_from_file(filename=target_file, format='.dat')[:1000]
192192

193193
recorders[output].update(
194-
y_real=convert_any_to_torch_tensor(ref),
194+
y_real=convert_any_to_torch_tensor(ref),
195195
y_pred=convert_any_to_torch_tensor(target))
196196

197197
results = {}
198198
for output, recorder in recorders.items():
199199
results[output] = recorder.measure
200-
200+
201201
method_str = 'MEASUREMENT'
202202
if method == 'snr': method_str = 'NOISE:SIGNAL POWER RATIO'
203203
if method == 'cosine': method_str = 'COSINE SIMILARITY'
@@ -206,7 +206,7 @@ def compare_cosine_similarity_between_results(
206206

207207

208208
def dump_internal_results(
209-
graph: BaseGraph, dataloader: Iterable,
209+
graph: BaseGraph, dataloader: Iterable,
210210
dump_dir: str, executing_device: str, sample: bool = True):
211211

212212
i_dir = os.path.join(dump_dir, 'inputs')
@@ -218,12 +218,12 @@ def dump_internal_results(
218218
# 找出所有量化点,抽出所有中间结果.
219219
for var in graph.variables.values():
220220
if isinstance(var, QuantableVariable):
221-
if (var.source_op_config is not None and
221+
if (var.source_op_config is not None and
222222
var.source_op_config.state == QuantizationStates.ACTIVATED):
223223
graph.outputs[var.name] = var # 直接标记为网络输出
224224

225225
executor = TorchExecutor(graph, device=executing_device)
226-
for batch_idx, batch in tqdm(enumerate(dataloader),
226+
for batch_idx, batch in tqdm(enumerate(dataloader),
227227
total=len(dataloader), desc='Dumping Results ...'):
228228
batch = batch.to(executing_device)
229229
outputs = executor.forward(batch)
@@ -234,11 +234,11 @@ def dump_internal_results(
234234
# 如果数字太多就抽样
235235
if output.numel() > 10000 and sample:
236236
output = tensor_random_fetch(
237-
tensor=output, seed=10086, # 保证随机种子一致才能比对结果
237+
tensor=output, seed=10086, # 保证随机种子一致才能比对结果
238238
num_of_fetches=4096)
239239

240240
dump_to_file(
241-
filename=os.path.join(o_dir, str(batch_idx), name + '.dat'),
241+
filename=os.path.join(o_dir, str(batch_idx), name + '.dat'),
242242
data=output, format='.dat')
243243

244244
dump_to_file(
@@ -249,11 +249,11 @@ def split_result_to_directory(raw_dir: str, to_dir: str):
249249
print(f'正从 {raw_dir} 分割数据')
250250
data_files, sample_names = [], set()
251251
for file_name in os.listdir(raw_dir):
252-
if file_name.endswith('.dat'):
252+
if file_name.endswith('.dat'):
253253
sample_name = file_name.split('_')[0]
254254
sample_names.add(sample_name)
255255
data_files.append((sample_name, file_name))
256-
256+
257257
print(f'加载 {len(data_files)} 数据文件,总计 {len(sample_names)} 个样本')
258258
create_dir(to_dir)
259259
for sample_name in sample_names:

doc/assets/css/page.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/assets/css/page.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)