Git Product home page Git Product logo

Comments (5)

guyjacob avatar guyjacob commented on May 19, 2024

I'm not sure what the issue is. The optimizer created in compress_classifier.py is passed to the file_config method, and from there it is passed to the __init__ function of Quantizer. So the instance maintained within Quantizer - which is the one you refer to in the call self.optimizer.setstate above, is the same optimizer as in the main application.
Are you running with the PACT quantizer and this is not what you're seeing? Is the optimizer in the main application not updating for you after the quantizer is created?

from distiller.

hunterkun avatar hunterkun commented on May 19, 2024

Thanks for your reply@guyjacob. The problem is what you said in the last sentence. When I run PACT quantizer, the optimizer in the compress_classifier.py is not updated after the quantizer is initialized. I simply print the optimizer.param_groups after calling file_config. The reasonable result should print list containing two dict as returned by the _get_updated_optimizer_params_groups in PACTQuantizer class. But it is still the optimizer before call file_config. So I doubt this line self.optimizer.setstate({'param_groups': new_optimizer.param_groups}) can not change the optimizer passed to the file_config method.

from distiller.

guyjacob avatar guyjacob commented on May 19, 2024

I tried printing the optimizer.param_groups before and after the call to file_config as you described, and I do see the second parameter group after the call to file_config. See below - marked in bold.
Those single-element tensors are the tensors containing the alpha argument, which is initialized to 8.

Can you give the command-line you're using to run this?
Are you using the sample YAML we provided at distiller/examples/quantization/preact_resnet20_cifar_pact.yaml or you're own?

2018-07-31 12:00:13,609 - Optimizer before:
[{'lr': 0.1, 'dampening': 0, 'momentum': 0.9, 'nesterov': False, 'params': [Parameter containing:
tensor([[[[ 0.0109, -0.1648,  0.0566],
          [-0.0265, -0.0163,  0.0223],
          [-0.0187,  0.1541, -0.0383]],

...
...

tensor([ 0.0638, -0.0619,  0.0348, -0.0428, -0.0342,  0.0349, -0.1236,
         0.0083,  0.0702,  0.0129], device='cuda:1')], 'weight_decay': 0.0001}]

2018-07-31 12:00:14,069 - Optimizer after:
[{'lr': 0.1, 'dampening': 0, 'momentum': 0.9, 'nesterov': False, 'params': [Parameter containing:
tensor([[[[ 0.0109, -0.1648,  0.0566],
          [-0.0265, -0.0163,  0.0223],
          [-0.0187,  0.1541, -0.0383]],

...
...

tensor([ 0.0638, -0.0619,  0.0348, -0.0428, -0.0342,  0.0349, -0.1236,
         0.0083,  0.0702,  0.0129], device='cuda:1')], 'initial_lr': 0.1, 'weight_decay': 0.0001},
{'lr': 0.1, 'dampening': 0, 'momentum': 0.9, 'nesterov': False, 'params': [Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.]), Parameter containing:
tensor([ 8.])], 'initial_lr': 0.1, 'weight_decay': 0.0001}]

from distiller.

hunterkun avatar hunterkun commented on May 19, 2024

Thank you very much for your patience. I found where the problem is and solved it. I used the old version config.py, so elif 'quantizer' in policy_def branch, i still have the following codes, therefore, it change the optimizer back.

if quantizer.train_with_fp_copy:
     optimizer_type = type(optimizer)
      new_optimizer = optimizer_type(model.parameters(), **optimizer.defaults)
      optimizer.__setstate__({'param_groups': new_optimizer.param_groups})

One more little question is I think optimizer.setstate({'param_groups': new_optimizer.param_groups}) is equal to optimizer.param_groups=new_optimizer.param_groups. So why you choose the former rather than the latter.

from distiller.

guyjacob avatar guyjacob commented on May 19, 2024

Glad you found the issue.

Why use __setstate__ - don't recall 100%. It could be that setting param_groups directly is good enough for our needs right now. But, __setstate__ is a bit more generic, and is also over-ridden by Optimizer sub-classes which add specific logic. So it seems safer to use, in case we'll want to modify more than the param groups, and also in case some of the internal logic of the optimizers changes.

from distiller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.