Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

inference transpiler does not work properly

Open pzelazko-intel opened this issue 8 years ago • 3 comments

When I use inference transpiler in fluid_benchamark.py, I get much worse test accuracy.

This is result of benchmark with inference transpiler:

python fluid_benchmark.py --device CPU --data_set cifar10 --pass_num 1 --iterations 250  --use_inference_transpiler
...
Pass: 0, Iter: 250, Loss: 1.942829


Total examples: 7840, total time: 153.28633, 51.14611 examples/sed

Pass: 0, Loss: 1.942829 , Test Accuracy: 0.107514

And this is without inference transpiler:

python fluid_benchmark.py --device CPU --data_set cifar10 --pass_num 1 --iterations 250
...
Pass: 0, Iter: 250, Loss: 2.071917


Total examples: 7840, total time: 154.19125, 50.84594 examples/sed

Pass: 0, Loss: 2.071917 , Test Accuracy: 0.256182

This problem is connected with fuse_batch_norm method. fuse_relu_mkldnn works properly.

pzelazko-intel avatar Jun 29 '18 08:06 pzelazko-intel

fuse_batch_norm is used only for inference. We couldn't use it in training. And inference_transpiler is used for optimizing training program_desc to inference program_desc, so we should use it after saving program_desc.

luotao1 avatar Jun 29 '18 12:06 luotao1

@luotao1 But at the end of the training in fluid_benchmark there is a test phase. I use inference_transpiler only for that part.

pzelazko-intel avatar Jun 29 '18 14:06 pzelazko-intel

There are some tips and mistakes in the script.

  • tips: we should keep the random seed, otherwise the train loss is different each time when we run the same command python fluid_benchmark.py --device CPU --data_set cifar10 --pass_num 1 --iterations 250
  • mistakes: we should do inference_transpiler before test and after train.

I create a PR #11859 , and you can have a test.

python fluid_benchmark.py --device CPU --data_set cifar10 --pass_num 1 --iterations 250 --no_random
python fluid_benchmark.py --device CPU --data_set cifar10 --pass_num 1 --iterations 250 --use_inference_transpiler --no_random

The result of above two commands are the same now:

Pass: 0, Iter: 1, Loss: 3.768308

Pass: 0, Iter: 2, Loss: 3.569727

Pass: 0, Iter: 3, Loss: 3.335207

…
Pass: 0, Iter: 248, Loss: 1.999223

Pass: 0, Iter: 249, Loss: 1.998482

Pass: 0, Iter: 250, Loss: 1.997648


Total examples: 7840, total time: 157.29978, 49.84114 examples/sed

Pass: 0, Loss: 1.997648 , Test Accuracy: 0.362981

luotao1 avatar Jun 30 '18 03:06 luotao1