Closed brisker closed 5 years ago
Are you sure your path to imagenet dataset properly configured? You need to providing --data "PATH_TO_ILSVRC" or copy ILSVRC dir to ~/datasets/ILSVRC2012 Could you please run w/o quantization and check the result. python inference/inference_sim.py -a resnet50 -b 512
In addition you may need to run this script to prepare validation set for pytorch. https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh
You can find instructions here in pytorch documentation https://github.com/pytorch/examples/tree/master/imagenet
@ynahshan
root@debug-3r6heg347:/data/cnn-quantization-master# python inference/inference_sim.py -a resnet50 -b 512
=> using pre-trained model 'resnet50'
Perform BN folding
Test: [0/98] Time 29.235 (29.235) Loss 0.5774 (0.5774) Prec@1 84.766 (84.766) Prec@5 96.484 (96.484)
Test: [10/98] Time 0.824 (8.053) Loss 0.6856 (0.6809) Prec@1 85.352 (83.043) Prec@5 94.141 (95.455)
Test: [20/98] Time 12.384 (6.726) Loss 0.6628 (0.6858) Prec@1 82.812 (82.571) Prec@5 96.094 (95.750)
Test: [30/98] Time 0.824 (5.417) Loss 0.8957 (0.7008) Prec@1 78.125 (81.811) Prec@5 94.727 (95.917)
Test: [40/98] Time 9.252 (5.006) Loss 1.4035 (0.7189) Prec@1 65.430 (81.398) Prec@5 88.867 (95.636)
Test: [50/98] Time 0.824 (4.565) Loss 1.0886 (0.8133) Prec@1 71.289 (79.274) Prec@5 91.797 (94.627)
Test: [60/98] Time 10.787 (4.405) Loss 1.5274 (0.8610) Prec@1 60.547 (78.253) Prec@5 85.156 (94.003)
Test: [70/98] Time 0.827 (4.136) Loss 0.9446 (0.9043) Prec@1 77.344 (77.308) Prec@5 92.578 (93.566)
Test: [80/98] Time 8.448 (4.071) Loss 1.0883 (0.9397) Prec@1 76.562 (76.654) Prec@5 91.602 (93.065)
Test: [90/98] Time 0.820 (3.930) Loss 1.0987 (0.9689) Prec@1 71.094 (75.998) Prec@5 92.969 (92.793)
* Prec@1 76.130 Prec@5 92.862
@ynahshan I think it is not the bug related to data.
I was able to reproduce the issue. The is issue related to kmeans model, I will debug it. Meanwhile you can run 4W4A mode w/o kmean. It should give you 69.8%. python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -pcq_w -pcq_a -c laplace -qw int4
@ynahshan In your 4w4a mode, what if no "per-channel-quantization" trick implemented on acticvations? What will the accuracy be? (Asking this because that lots of papers only implement per-channel on weights)
Per channel trick can be done on weights and activations independently. To check this you can run respectively. python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -c laplace -qw int4 -pcq_w python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -c laplace -qw int4 -pcq_a python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -c laplace -qw int4
@ynahshan
python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -pcq_w -pcq_a -c laplace -qw int4
?
root@debug-3r6heg347:/data/cnn-quantization-master# python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -c laplace -qw int4
=> using pre-trained model 'resnet50'
Perform BN folding
Test: [0/98] Time 19.385 (19.385) Loss 14.5781 (14.5781) Prec@1 0.000 (0.000) Prec@5 0.000 (0.000)
Test: [10/98] Time 1.398 (3.058) Loss 13.2234 (12.1870) Prec@1 0.000 (0.107) Prec@5 0.000 (0.817)
Test: [20/98] Time 4.273 (2.928) Loss 14.1718 (13.0394) Prec@1 0.000 (0.056) Prec@5 0.000 (0.549)
Test: [30/98] Time 5.744 (3.419) Loss 10.3249 (13.0239) Prec@1 0.000 (0.050) Prec@5 2.344 (0.504)
Test: [40/98] Time 1.435 (3.371) Loss 11.8965 (12.8655) Prec@1 0.000 (0.062) Prec@5 0.000 (0.548)
Test: [50/98] Time 1.389 (3.583) Loss 11.5615 (12.5767) Prec@1 0.000 (0.149) Prec@5 0.000 (0.701)
Test: [60/98] Time 1.394 (3.585) Loss 10.3793 (12.4067) Prec@1 0.000 (0.147) Prec@5 0.195 (0.765)
Test: [70/98] Time 1.394 (3.744) Loss 12.1444 (12.2745) Prec@1 0.000 (0.239) Prec@5 0.000 (0.974)
Test: [80/98] Time 1.397 (3.710) Loss 11.1917 (12.1116) Prec@1 0.195 (0.294) Prec@5 1.367 (1.114)
Test: [90/98] Time 1.391 (3.771) Loss 13.7696 (12.0343) Prec@1 0.000 (0.324) Prec@5 0.000 (1.206)
* Prec@1 0.356 Prec@5 1.278050) Prec@5 2.344 (0.504)
python pytorch_quantizer/quantization/kmeans_quantization.py -a resnet50 -bits 4 -t quantize
Fine-tuning is possible but not implemented in this code. W/o per-channel and 4W4A configuration results should be near 0 due to high quantization error.
@ynahshan Is the bug fixed?
Does this code support uniform quantization, not non-uniform quantization?
I pushed a fix. Please rerun python pytorch_quantizer/quantization/kmeans_quantization.py -a resnet18 -bits 4 -t quantize and python pytorch_quantizer/quantization/kmeans_quantization.py -a resnet50 -bits 4 -t quantize to regenerate kmeans quantized model weights. Than rerunning python inference/inference_sim.py -a resnet18 -b 512 -sm use --qtype int4 -pcq_w -pcq_a -c laplace -qm 4 -qw f32 and python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -pcq_w -pcq_a -c laplace -qm 4 -qw f32 Should give 65.2% and 72% accuracy respectively.
Uniform quantization is also supported by: python inference/inference_sim.py -a resnet50 -b 512 -sm use --qtype int4 -pcq_w -pcq_a -c laplace -qw int4
Fixed and closed.
In your paper , why is the weight quantization methods different from the activation quantization? Why not use the optimal clipping quantization methods which you use to quantize the activations, to quantize the weights? @ynahshan @submission2019
In addition you may need to run this script to prepare validation set for pytorch. https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh
You can find instructions here in pytorch documentation https://github.com/pytorch/examples/tree/master/imagenet
I met the same problem fix by using this method TY
After I run the following commands one by one: (they are all the default commands)
Then it gives me these lines and weird classification accuracy: