|
| 1 | +<!-- |
| 2 | +Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, |
| 11 | +software distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +--- |
| 18 | +# General Epoch/LR variables |
| 19 | +num_epochs: &num_epochs 10 |
| 20 | +lr: &lr 0.008 |
| 21 | + |
| 22 | +# Pruning variables |
| 23 | +pruning_start_epoch: &pruning_start_epoch 1.0 |
| 24 | +pruning_end_epoch: &pruning_end_epoch 8.0 |
| 25 | +pruning_update_frequency: &pruning_update_frequency 0.5 |
| 26 | +init_sparsity: &init_sparsity 0.05 |
| 27 | + |
| 28 | +prune_low_target_sparsity: &prune_low_target_sparsity 0.8 |
| 29 | +prune_mid_target_sparsity: &prune_mid_target_sparsity 0.85 |
| 30 | +prune_high_target_sparsity: &prune_high_target_sparsity 0.9 |
| 31 | + |
| 32 | +training_modifiers: |
| 33 | + - !EpochRangeModifier |
| 34 | + start_epoch: 0.0 |
| 35 | + end_epoch: *num_epochs |
| 36 | + |
| 37 | + - !SetLearningRateModifier |
| 38 | + start_epoch: 0.0 |
| 39 | + learning_rate: *lr |
| 40 | + |
| 41 | +pruning_modifiers: |
| 42 | + - !GMPruningModifier |
| 43 | + params: |
| 44 | + - sections.0.0.conv1.weight |
| 45 | + - sections.0.0.conv2.weight |
| 46 | + - sections.0.0.conv3.weight |
| 47 | + - sections.0.0.identity.conv.weight |
| 48 | + - sections.0.1.conv1.weight |
| 49 | + - sections.0.1.conv3.weight |
| 50 | + - sections.0.2.conv1.weight |
| 51 | + - sections.0.2.conv3.weight |
| 52 | + - sections.1.0.conv1.weight |
| 53 | + - sections.1.0.conv3.weight |
| 54 | + - sections.1.2.conv3.weight |
| 55 | + - sections.1.3.conv1.weight |
| 56 | + - sections.2.0.conv1.weight |
| 57 | + - sections.3.0.conv1.weight |
| 58 | + - classifier.fc.weight |
| 59 | + init_sparsity: *init_sparsity |
| 60 | + final_sparsity: *prune_low_target_sparsity |
| 61 | + start_epoch: *pruning_start_epoch |
| 62 | + end_epoch: *pruning_end_epoch |
| 63 | + update_frequency: *pruning_update_frequency |
| 64 | + |
| 65 | + - !GMPruningModifier |
| 66 | + params: |
| 67 | + - sections.0.1.conv2.weight |
| 68 | + - sections.0.2.conv2.weight |
| 69 | + - sections.1.0.identity.conv.weight |
| 70 | + - sections.1.1.conv1.weight |
| 71 | + - sections.1.1.conv2.weight |
| 72 | + - sections.1.1.conv3.weight |
| 73 | + - sections.1.2.conv1.weight |
| 74 | + - sections.1.2.conv2.weight |
| 75 | + - sections.1.3.conv2.weight |
| 76 | + - sections.1.3.conv3.weight |
| 77 | + - sections.2.0.conv3.weight |
| 78 | + - sections.2.0.identity.conv.weight |
| 79 | + - sections.2.1.conv1.weight |
| 80 | + - sections.2.1.conv3.weight |
| 81 | + - sections.2.2.conv1.weight |
| 82 | + - sections.2.2.conv3.weight |
| 83 | + - sections.2.3.conv1.weight |
| 84 | + - sections.2.3.conv3.weight |
| 85 | + - sections.2.4.conv1.weight |
| 86 | + - sections.2.4.conv3.weight |
| 87 | + - sections.2.5.conv1.weight |
| 88 | + - sections.2.5.conv3.weight |
| 89 | + - sections.3.1.conv1.weight |
| 90 | + - sections.3.2.conv1.weight |
| 91 | + init_sparsity: *init_sparsity |
| 92 | + final_sparsity: *prune_mid_target_sparsity |
| 93 | + start_epoch: *pruning_start_epoch |
| 94 | + end_epoch: *pruning_end_epoch |
| 95 | + update_frequency: *pruning_update_frequency |
| 96 | + |
| 97 | + - !GMPruningModifier |
| 98 | + params: |
| 99 | + - sections.1.0.conv2.weight |
| 100 | + - sections.2.0.conv2.weight |
| 101 | + - sections.2.1.conv2.weight |
| 102 | + - sections.2.2.conv2.weight |
| 103 | + - sections.2.3.conv2.weight |
| 104 | + - sections.2.4.conv2.weight |
| 105 | + - sections.2.5.conv2.weight |
| 106 | + - sections.3.0.conv2.weight |
| 107 | + - sections.3.0.conv3.weight |
| 108 | + - sections.3.0.identity.conv.weight |
| 109 | + - sections.3.1.conv2.weight |
| 110 | + - sections.3.1.conv3.weight |
| 111 | + - sections.3.2.conv2.weight |
| 112 | + - sections.3.2.conv3.weight |
| 113 | + init_sparsity: *init_sparsity |
| 114 | + final_sparsity: *prune_high_target_sparsity |
| 115 | + start_epoch: *pruning_start_epoch |
| 116 | + end_epoch: *pruning_end_epoch |
| 117 | + update_frequency: *pruning_update_frequency |
| 118 | +--- |
| 119 | + |
| 120 | +# ResNet-50 Imagenette Conservative Sparse |
| 121 | + |
| 122 | +This recipe creates a sparse [ResNet-50](https://arxiv.org/abs/1512.03385) model that |
| 123 | +achieves full recovery of its baseline accuracy on the Imagenette dataset. |
| 124 | +Training was done using 1 GPU with a total training batch size of 128 |
| 125 | +using a SGD optimizer. |
| 126 | + |
| 127 | +When running, adjust hyperparameters based on training environment and dataset. |
| 128 | + |
| 129 | +## Training |
| 130 | +The training script can be found at `sparseml/integrations/pytorch/scripts/vision.py`. |
| 131 | +Alternatively, a full walk-through notebook is located at `sparseml/notebooks/pytorch_classification.ipynb`. |
| 132 | + |
| 133 | +*script command:* |
| 134 | + |
| 135 | +``` |
| 136 | +python integrations/pytorch/scripts/vision.py train \ |
| 137 | + --recipe-path zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenette/pruned-conservative?recipe_type=original \ |
| 138 | + --pretrained True \ |
| 139 | + --arch-key resnet50 \ |
| 140 | + --dataset imagenette \ |
| 141 | + --dataset-path /PATH/TO/IMAGENETTE \ |
| 142 | + --train-batch-size 128 --test-batch-size 256 \ |
| 143 | + --loader-num-workers 8 \ |
| 144 | + --model-tag resnet50-imagenette-pruned-conservative |
| 145 | +``` |
0 commit comments