Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] recipe_template cli #1170

Merged
merged 3 commits into from
Nov 21, 2022
Merged

[Bugfix] recipe_template cli #1170

merged 3 commits into from
Nov 21, 2022

Conversation

rahul-tuli
Copy link
Member

A recent bug was found in recipe_template where invoking the cli with sparseml.recipe quantization true --target vnni would error out

the reason was that from the cli side the mask_type wasn't settable to it defaulted to unstructured which is wrong.

This PR fixes that by setting the correct mask type from the cli type, and also adds tests to confirm correct working.

before this PR:

(sparseml3.8) 🥃 sparseml sparseml.recipe_template --quantization true --target vnni --lr constant
Traceback (most recent call last):
  File "/home/rahul/virtual_environments/sparseml3.8/bin/sparseml.recipe_template", line 8, in <module>
    sys.exit(main())
  File "/home/rahul/virtual_environments/sparseml3.8/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/rahul/virtual_environments/sparseml3.8/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/rahul/virtual_environments/sparseml3.8/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rahul/virtual_environments/sparseml3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/rahul/projects/sparseml/src/sparseml/pytorch/recipe_template/cli.py", line 108, in main
    template = recipe_template(**kwargs)
  File "/home/rahul/projects/sparseml/src/sparseml/pytorch/recipe_template/main.py", line 94, in recipe_template
    mask_type: str = _validate_mask_type(mask_type=mask_type, target=target)
  File "/home/rahul/projects/sparseml/src/sparseml/pytorch/recipe_template/main.py", line 151, in _validate_mask_type
    raise ValueError(
ValueError: The specified mask type unstructured and target vnni are incompatible, try overriding mask_type to block4

after this PR:

$sparseml.recipe_template --quantization true --target vnni --lr constant
2022-11-17 16:58:16 sparseml.pytorch.recipe_template.main INFO     Recipe written to file recipe.md
Template:
---
lr_func: constant
init_lr: 0.001
final_lr: 0.0
num_epochs: 20.0
num_qat_epochs: 5.0
num_qat_finetuning_epochs: 2.5
quantization_submodules: null

training_modifiers:
  - !EpochRangeModifier
    start_epoch: 0.0
    end_epoch: eval(num_epochs)

  - !LearningRateFunctionModifier
    start_epoch: 0.0
    end_epoch: eval(num_epochs)
    lr_func: eval(lr_func)
    init_lr: eval(init_lr)
    final_lr: eval(final_lr)

pruning_modifiers:
  - !ConstantPruningModifier
    start_epoch: 0.0
    params: __ALL_PRUNABLE__

quantization_modifiers:
  - !QuantizationModifier
    start_epoch: 0.0
    submodules: eval(quantization_submodules)
    disable_quantization_observer_epoch: eval(num_qat_epochs - num_qat_finetuning_epochs)
    freeze_bn_stats_epoch: eval(num_qat_epochs - num_qat_finetuning_epochs)
    tensorrt: False
    quantize_linear_activations: False
    quantize_conv_activations: False
    quantize_embedding_activations: False
    exclude_module_types:
    - LayerNorm
    - Tanh
---
This recipe defines the hyperparams necessary to apply specified sparsification
techniques.

Users are encouraged to experiment with the training length and initial learning
rate to either expedite training or to produce a more accurate model.

This can be done by either editing the recipe or supplying the `--recipe_args`
argument to the training commands.

For example, the following appended to the training commands will change the number
of epochs and the initial learning rate:

```bash
--recipe_args '{"num_epochs":8,"init_lr":0.0001}'

The following template can be used to apply this recipe in a one-shot manner:

from sparseml.pytorch.optim import ScheduledModifierManager

model = ... # instantiated model
recipe = ... # local path to this recipe

manager = ScheduledModifierManager.from_yaml(recipe)
manager.apply(model)

bfineran
bfineran previously approved these changes Nov 17, 2022
corey-nm
corey-nm previously approved these changes Nov 18, 2022
Copy link
Contributor

@corey-nm corey-nm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy diff!

@rahul-tuli rahul-tuli dismissed stale reviews from corey-nm and bfineran via 603a691 November 18, 2022 14:23
@rahul-tuli rahul-tuli merged commit 19acc03 into main Nov 21, 2022
@rahul-tuli rahul-tuli deleted the bugfix-recipe-template-cli branch November 21, 2022 04:04
rahul-tuli added a commit that referenced this pull request Nov 21, 2022
* Fix a small cli bug, update docstring, add test for confirming docstring examples work

* Update src/sparseml/pytorch/recipe_template/cli.py
rahul-tuli added a commit that referenced this pull request Nov 21, 2022
* [Bugfix] recipe_template cli (#1170)

* Fix a small cli bug, update docstring, add test for confirming docstring examples work

* Update src/sparseml/pytorch/recipe_template/cli.py

* Fix a bug where one-shot recipe should be applied in train mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants