mit-han-lab / haq Goto Github PK
View Code? Open in Web Editor NEW[CVPR 2019, Oral] HAQ: Hardware-Aware Automated Quantization with Mixed Precision
Home Page: https://hanlab.mit.edu/projects/haq/
License: MIT License
[CVPR 2019, Oral] HAQ: Hardware-Aware Automated Quantization with Mixed Precision
Home Page: https://hanlab.mit.edu/projects/haq/
License: MIT License
If we applied haq on fused mobilenet v1, i.e., fuse convolutional and batch norm layer together, it seems very difficult to quantize such model in 1~8bits.
Do you have any comment on such case?
I figure out the procedure of linear quantization and reproduce the experiments,
It seems like the final accuracy of the quantized model is more dependent on the fine-tuning.
Another question is why the bit reduction process starts from the last layer as the _final_action_wall
function shows.
By diving deep into the codes and the paper, I have two questions.
I've read from the paper that "If the current policy exceeds our resource budget (on latency, energy or model size), we will sequentially decrease the bitwidth of each layer until the
constraint is finally satisfied." Where in the codes correspond to this statement "decrease the bitwidth of the layer when the current policy exceeds budget?"
Why don't you use the k-means quantization for latency/energy constraint experiments? Will you release codes for linear quantization?
Hi,
The work is amazing.
When I looked through the code, I foud that you employed the 8-bit floating numbers to compute the original cost and store
it as a lookup table. I wondered why not use the 32-bit floating(not use the flag "--half" in the pretraining process) or use the 16-bit floating (use the flag "--half" in the pretraining process)? Could you please clarify that?
Thanks a lot!
I have noticed that the quantization mechanism is quantize(w, ak, c) = round(clamp(w, c)/s) × s. It seems like you have use the "Training with simulated quantization" in paper "Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference". Is it true?
If yes, Training with simulated quantization is just used for training. I wonder does the model also use the Integer-arithmetic-only inference process like round(clamp(w, c)/s) during the inference process?
https://hanlab.mit.edu/files/haq/mobilenetv2-150.pth.tar
Oops! That page can’t be found.
hello,
Thanks for your code! I wonder how do you compute the latency and energy in the paper?
It seems that only weight quantization is supported in this repo, isn't it?
Do you have plan to release the implementation including activation quantization in the future?
Dear authors,
I notice in the first two lines of Table 6 that your searched model has a model size even smaller than 2-bits quantization but a much higher accuracy. Can you illustrate your quantization policy under this constraint? It's a little strange to me because it seems your minimum bitwidth choice is 2 in the paper.
Thank you
Thanks for sharing the amazing work! I'm wondering how did you measure the model size. I downloaded your pretrained model 'resnet50_0.1_75.48.pth.tar', and found the size of the model is 102.7MB which is big.
Thanks for sharing a great work!
I was interested in the results of deep compression vs HAQ in the paper: in case of resnets, mixed precision quantization did not bring much benefits.
I was wondering if mixed precision quantization is effective in resnet architecture or not.
Did you compare the results of HAQ vs PACT with resnets? It would be great if you can share!
Can this project be used for the Hardware Aware quantization of self made custom models that are trained on datasets other than ImageNet so as to reduce the latency on a particular GPU?
can you tell me which part is using for quantize activation?
I just find quantization codes for weights and bias, but not activation.
Hi, Dear author,
The figures in the paper show the parameters' bitwidth in MobileNet. Is it possible for you to release the pretrained quantized MobileNet model?
Thanks!
(.haq) [root@b6706b6a30d7 HAQ-master]# python rl_quantize.py --gpu_id 2
support models: ['alexnet', 'densenet121', 'densenet161', 'densenet169', 'densenet201', 'googlenet', 'inception_v3', 'mobilenet_v2', 'resnet101', 'resnet152', 'resnet18', 'resnet34', 'resnet50', 'resnext101_32x8d', 'resnext50_32x4d', 'shufflenet_v2_x0_5', 'shufflenet_v2_x1_0', 'shufflenet_v2_x1_5', 'shufflenet_v2_x2_0', 'squeezenet1_0', 'squeezenet1_1', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn', 'mobilenet_v3']
==> Output path: ../../save/mobilenet_v2_imagenet...
Traceback (most recent call last):
File "rl_quantize.py", line 210, in
model = torch.nn.DataParallel(model).cuda()
File "/aiml/.haq/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 265, in cuda
return self._apply(lambda t: t.cuda(device))
File "/aiml/.haq/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 193, in _apply
module._apply(fn)
File "/aiml/.haq/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 193, in _apply
module._apply(fn)
File "/aiml/.haq/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 193, in _apply
module._apply(fn)
[Previous line repeated 1 more time]
File "/aiml/.haq/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 199, in _apply
param.data = fn(param.data)
File "/aiml/.haq/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 265, in
return self._apply(lambda t: t.cuda(device))
RuntimeError: CUDA error: out of memory
Can you please point to the part where the linear quantization is used? Thanks. I can't find it in linear quantize environment.
self.quantizable_layer_types = [QConv2d, QLinear] might be [nn.Conv2d, nn.Linear]?
In quantize_env.py line 130, 131
self.cur_ind += 1 # the index of next layer
self.layer_embedding[self.cur_ind][-1] = action
Why cur_ind is increased by one before layer_embedding is updated?
In HAQ/lib/utils/data_utils.py in lane 93 valset = datasets.ImageFolder(traindir, test_transform) should be valset = datasets.ImageFolder(valdir, test_transform) ?
I want to use this method to detect the network. Do you have any relevant practice?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.