Skip to content

Commit

Permalink
disable guess_language in codehighlite (PaddlePaddle#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
heavengate authored and baiyfbupt committed Jan 16, 2020
1 parent 8ba6f92 commit 405a468
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 51 deletions.
4 changes: 2 additions & 2 deletions docs/docs/api/analysis_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ paddleslim.analysis.flops(program, detail=False) [源代码](https://github.com/

**示例:**

```
```python
import paddle.fluid as fluid
from paddle.fluid.param_attr import ParamAttr
from paddleslim.analysis import flops
Expand Down Expand Up @@ -90,7 +90,7 @@ paddleslim.analysis.model_size(program) [源代码](https://github.com/PaddlePad

**示例:**

```
```python
import paddle.fluid as fluid
from paddle.fluid.param_attr import ParamAttr
from paddleslim.analysis import model_size
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/api/nas_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ paddleslim.nas.SANAS(configs, server_addr=("", 8881), init_temperature=100, redu
一个SANAS类的实例

**示例代码:**
```
```python
from paddleslim.nas import SANAS
config = [('MobileNetV2Space')]
sanas = SANAS(config=config)
Expand All @@ -54,7 +54,7 @@ tokens是一个列表,token映射到搜索空间转换成相应的网络结构
根据传入的token得到一个模型结构实例。

**示例代码:**
```
```python
import paddle.fluid as fluid
input = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
archs = sanas.token2arch(tokens)
Expand All @@ -70,7 +70,7 @@ paddleslim.nas.SANAS.next_archs()
返回模型结构实例的列表,形式为list。

**示例代码:**
```
```python
import paddle.fluid as fluid
input = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
archs = sanas.next_archs()
Expand Down
14 changes: 7 additions & 7 deletions docs/docs/api/prune_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ paddleslim.prune.Pruner(criterion="l1_norm")[源代码](https://github.com/Paddl

**示例代码:**

```
```python
from paddleslim.prune import Pruner
pruner = Pruner()
```
Expand All @@ -28,7 +28,7 @@ paddleslim.prune.Pruner.prune(program, scope, params, ratios, place=None, lazy=F
- **scope(paddle.fluid.Scope)** - 要裁剪的权重所在的`scope`,Paddle中用`scope`实例存放模型参数和运行时变量的值。Scope中的参数值会被`inplace`的裁剪。更多介绍请参考[Scope概念介绍]()

- **params(list<str>)** - 需要被裁剪的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称:
```
```python
for block in program.blocks:
for param in block.all_parameters():
print("param: {}; shape: {}".format(param.name, param.shape))
Expand Down Expand Up @@ -57,7 +57,7 @@ for block in program.blocks:
**示例:**

点击[AIStudio](https://aistudio.baidu.com/aistudio/projectDetail/200786)执行以下示例代码。
```
```python

import paddle.fluid as fluid
from paddle.fluid.param_attr import ParamAttr
Expand Down Expand Up @@ -149,7 +149,7 @@ paddleslim.prune.sensitivity(program, place, param_names, eval_func, sensitiviti

- **param_names(list<str>)** - 待分析的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称:

```
```python
for block in program.blocks:
for param in block.all_parameters():
print("param: {}; shape: {}".format(param.name, param.shape))
Expand All @@ -165,7 +165,7 @@ for block in program.blocks:

- **sensitivities(dict)** - 存放敏感度信息的dict,其格式为:

```
```python
{"weight_0":
{0.1: 0.22,
0.2: 0.33
Expand All @@ -183,7 +183,7 @@ for block in program.blocks:

点击[AIStudio](https://aistudio.baidu.com/aistudio/projectdetail/201401)运行以下示例代码。

```
```python
import paddle
import numpy as np
import paddle.fluid as fluid
Expand Down Expand Up @@ -291,7 +291,7 @@ paddleslim.prune.merge_sensitive(sensitivities)[源代码](https://github.com/Pa

- **sensitivities(dict)** - 合并后的敏感度信息。其格式为:

```
```bash
{"weight_0":
{0.1: 0.22,
0.2: 0.33
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api/quantization_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 量化配置
通过字典配置量化参数

```
```python
TENSORRT_OP_TYPES = [
'mul', 'conv2d', 'pool2d', 'depthwise_conv2d', 'elementwise_add',
'leaky_relu'
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ PaddleSlim是PaddlePaddle框架的一个子模块,主要用于压缩图像领
- 安装develop版本


```
```bash
git clone https://github.com/PaddlePaddle/PaddleSlim.git
cd PaddleSlim
python setup.py install
```

- 安装官方发布的最新版本

```
```bash
pip install paddleslim -i https://pypi.org/simple
```

Expand Down
12 changes: 6 additions & 6 deletions docs/docs/table_latency.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

**格式**

```
```text
op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stride,dilation\tlatency
```

Expand All @@ -57,7 +57,7 @@ op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stri

**格式**

```
```text
op_type,n_in,c_in,h_in,w_in\tlatency
```

Expand All @@ -74,7 +74,7 @@ op_type,n_in,c_in,h_in,w_in\tlatency

**格式**

```
```text
op_type,active_type,n_in,c_in,h_in,w_in\tlatency
```

Expand All @@ -92,7 +92,7 @@ op_type,active_type,n_in,c_in,h_in,w_in\tlatency

**格式**

```
```text
op_type,n_in,c_in,h_in,w_in\tlatency
```

Expand All @@ -109,7 +109,7 @@ op_type,n_in,c_in,h_in,w_in\tlatency

**格式**

```
```text
op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,pool_type\tlatency
```

Expand All @@ -132,7 +132,7 @@ op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,

**格式**

```
```text
op_type,axis,n_in,c_in,h_in,w_in\tlatency
```

Expand Down
12 changes: 6 additions & 6 deletions docs/docs/tutorials/nas_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

### 1. 配置搜索空间
详细的搜索空间配置可以参考<a href='../../../paddleslim/nas/nas_api.md'>神经网络搜索API文档</a>。
```
```python
config = [('MobileNetV2Space')]

```

### 2. 利用搜索空间初始化SANAS实例
```
```python
from paddleslim.nas import SANAS

sa_nas = SANAS(
Expand All @@ -27,12 +27,12 @@ sa_nas = SANAS(
```

### 3. 根据实例化的NAS得到当前的网络结构
```
```python
archs = sa_nas.next_archs()
```

### 4. 根据得到的网络结构和输入构造训练和测试program
```
```python
import paddle.fluid as fluid

train_program = fluid.Program()
Expand All @@ -57,14 +57,14 @@ with fluid.program_guard(train_program, startup_program):
```

### 5. 根据构造的训练program添加限制条件
```
```python
from paddleslim.analysis import flops

if flops(train_program) > 321208544:
continue
```

### 6. 回传score
```
```python
sa_nas.reward(score)
```
4 changes: 2 additions & 2 deletions docs/docs/tutorials/pruning_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

不同模型的参数命名不同,在剪裁前需要确定待裁卷积层的参数名称。可通过以下方法列出所有参数名:

```
```python
for param in program.global_block().all_parameters():
print("param name: {}; shape: {}".format(param.name, param.shape))
```
Expand All @@ -28,7 +28,7 @@ for param in program.global_block().all_parameters():

通过以下命令启动裁剪任务:

```
```python
export CUDA_VISIBLE_DEVICES=0
python train.py
```
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/tutorials/quant_aware_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

### 1. 配置量化参数

```
```python
quant_config = {
'weight_quantize_type': 'abs_max',
'activation_quantize_type': 'moving_average_abs_max',
Expand All @@ -27,15 +27,15 @@ quant_config = {

### 2. 对训练和测试program插入可训练量化op

```
```python
val_program = quant_aware(val_program, place, quant_config, scope=None, for_test=True)

compiled_train_prog = quant_aware(train_prog, place, quant_config, scope=None, for_test=False)
```

### 3.关掉指定build策略

```
```python
build_strategy = fluid.BuildStrategy()
build_strategy.fuse_all_reduce_ops = False
build_strategy.sync_batch_norm = False
Expand All @@ -48,7 +48,7 @@ compiled_train_prog = compiled_train_prog.with_data_parallel(

### 4. freeze program

```
```python
float_program, int8_program = convert(val_program,
place,
quant_config,
Expand All @@ -58,7 +58,7 @@ float_program, int8_program = convert(val_program,

### 5.保存预测模型

```
```python
fluid.io.save_inference_model(
dirname=float_path,
feeded_var_names=[image.name],
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/tutorials/quant_embedding_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mv text data/
词典格式: 词<空格>词频。注意低频词用'UNK'表示

可以按格式自建词典,如果自建词典跳过第一步。
```
```text
the 1061396
of 593677
and 416629
Expand Down Expand Up @@ -126,7 +126,7 @@ sh cluster_train.sh
```

本示例中按照单机多线程训练的命令进行训练,训练完毕后,可看到在当前文件夹下保存模型的路径为: ``v1_cpu5_b100_lr1dir``, 运行 ``ls v1_cpu5_b100_lr1dir``可看到该文件夹下保存了训练的10个epoch的模型文件。
```
```text
pass-0 pass-1 pass-2 pass-3 pass-4 pass-5 pass-6 pass-7 pass-8 pass-9
```

Expand All @@ -145,7 +145,7 @@ wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar
python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/ --start_index 0 --last_index 9
```
运行该预测命令, 可看到如下输出
```
```text
('start index: ', 0, ' last_index:', 9)
('vocab_size:', 63642)
step:1 249
Expand Down Expand Up @@ -173,7 +173,7 @@ epoch:9 acc:0.153
## 量化``基于skip-gram的word2vector模型``

量化配置为:
```
```python
config = {
'params_name': 'emb',
'quantize_type': 'abs_max'
Expand All @@ -188,7 +188,7 @@ python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test

运行输出为:

```
```text
('start index: ', 0, ' last_index:', 9)
('vocab_size:', 63642)
quant_embedding config {'quantize_type': 'abs_max', 'params_name': 'emb', 'quantize_bits': 8, 'dtype': 'int8'}
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/tutorials/quant_post_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

### 导出模型
通过运行以下命令可将模型转化为离线量化接口可用的模型:
```
```bash
python export_model.py --model "MobileNet" --pretrained_model ./pretrain/MobileNetV1_pretrained --data imagenet
```
转化之后的模型存储在``inference_model/MobileNet/``文件夹下,可看到该文件夹下有``'model'``, ``'weights'``两个文件。

### 离线量化
接下来对导出的模型文件进行离线量化,离线量化的脚本为[quant_post.py](./quant_post.py),脚本中使用接口``paddleslim.quant.quant_post``对模型进行离线量化。运行命令为:
```
```bash
python quant_post.py --model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights
```

Expand All @@ -51,22 +51,22 @@ python quant_post.py --model_path ./inference_model/MobileNet --save_path ./quan
使用[eval.py](./eval.py)脚本对量化前后的模型进行测试,得到模型的分类精度进行对比。

首先测试量化前的模型的精度,运行以下命令:
```
```bash
python eval.py --model_path ./inference_model/MobileNet --model_name model --params_name weights
```
精度输出为:
```
```text
top1_acc/top5_acc= [0.70913923 0.89548034]
```

使用以下命令测试离线量化后的模型的精度:

```
```bash
python eval.py --model_path ./quant_model_train/MobileNet
```

精度输出为
```
```text
top1_acc/top5_acc= [0.70141864 0.89086477]
```
从以上精度对比可以看出,对``mobilenet````imagenet``上的分类模型进行离线量化后 ``top1``精度损失为``0.77%````top5``精度损失为``0.46%``.

0 comments on commit 405a468

Please sign in to comment.