-
Notifications
You must be signed in to change notification settings - Fork 4
MDMM hardware-aware metrics (FPGA + PACA), tests and docs #46
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # file: /src/pquant/configs/config_mdmm_fpga.yaml | ||
| # MDMM pruning with the hardware-aware FPGA metric (DSP/BRAM resource grouping). | ||
|
|
||
| pruning_parameters: | ||
| pruning_method: mdmm | ||
| enable_pruning: true | ||
| disable_pruning_for_layers: [] # Disable pruning for these layers, even if enable_pruning is true | ||
| constraint_type: "Equality" | ||
| target_value: 0.0 | ||
| metric_type: "FPGAAwareSparsity" | ||
| target_sparsity: 0.9 | ||
| rf: 4 | ||
| epsilon: 1.0e-03 | ||
| scale: 50.0 | ||
| damping: 1.0 | ||
| use_grad: false | ||
| constraint_lr: 1.0e-3 | ||
| # FPGAAwareSparsityMetric-specific | ||
| precision: 16 # weight bit-width | ||
| target_resource: "DSP" # "DSP" or "BRAM" | ||
| bram_width: 36 # BRAM word width (only used when target_resource == "BRAM") | ||
|
|
||
| quantization_parameters: | ||
| enable_quantization: true | ||
| default_weight_keep_negatives: 1. | ||
| default_weight_integer_bits: 0. | ||
| default_weight_fractional_bits: 7. | ||
| default_data_keep_negatives: 0. | ||
| default_data_integer_bits: 0. | ||
| default_data_fractional_bits: 7. | ||
| dynamic_data_quantization: false | ||
| granularity: "per_tensor" | ||
| quantize_input: true | ||
| quantize_output: false | ||
| hgq_beta: 1e-5 | ||
| hgq_gamma: 0.0003 | ||
| hgq_heterogeneous: True | ||
| layer_specific: {} | ||
| use_high_granularity_quantization: false | ||
| use_real_tanh: false | ||
| use_relu_multiplier: false | ||
| use_symmetric_quantization: false | ||
| overflow_mode_parameters: SAT | ||
| overflow_mode_data: SAT | ||
| round_mode: RND | ||
| training_parameters: | ||
| epochs: 200 | ||
| fine_tuning_epochs: 30 | ||
| pretraining_epochs: 0 | ||
| pruning_first: true | ||
| rewind: never | ||
| rounds: 1 | ||
| save_weights_epoch: -1 | ||
| fitcompress_parameters: | ||
| enable_fitcompress : false | ||
| optimize_quantization : true | ||
| quantization_schedule : [7.,4.,3.,2] | ||
| pruning_schedule : {start : 0, end : -3, steps : 40} | ||
| compression_goal : 0.10 | ||
| optimize_pruning : false | ||
| greedy_astar : true | ||
| approximate : true | ||
| f_lambda : 1 | ||
| hpo_parameters: | ||
| experiment_name: experiment_name | ||
| model_name: jet_tagger | ||
| num_trials: 1 | ||
| sampler: | ||
| type: RandomSampler | ||
| hyperparameter_search: | ||
| numerical: {} | ||
| categorical: {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # file: /src/pquant/configs/config_mdmm_paca.yaml | ||
| # MDMM pruning with the PACA pattern metric. PACA always pairs with an equality | ||
| # constraint at target 0 (enforced by the config model); the values below are listed | ||
| # for clarity. | ||
|
|
||
| pruning_parameters: | ||
| pruning_method: mdmm | ||
| enable_pruning: true | ||
| disable_pruning_for_layers: [] # Disable pruning for these layers, even if enable_pruning is true | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, too much redundant parameters
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| constraint_type: "Equality" # Forced to Equality/0 for PACA by MDMMPruningModel. | ||
| target_value: 0.0 | ||
| metric_type: "PACAPatternSparsity" | ||
| target_sparsity: 0.9 | ||
| rf: 1 | ||
| epsilon: 1.0e-03 | ||
| scale: 1.0 | ||
| damping: 1.0 | ||
| use_grad: false | ||
| constraint_lr: 1.0e-3 | ||
| # PACAPatternMetric-specific | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarification about PACAPatternMetric-specific values; are these values result in the best results?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They were the values (hand-tuned) that worked best for the SmartPixels. Do you think it would be better to scan for the best hyperparameters? If Yes, Kindly let me know if you also have any dataset in mind, that you would like this to be tuned to.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say, that in this situation it would be nice just to leave the best values based on your point of view. If they are the same, leave them as it's. |
||
| num_patterns_to_keep: 16 | ||
| beta: 0.85 # cumulative pattern-frequency coverage kept (0..1) | ||
| distance_metric: "cosine" # "hamming", "valued_hamming", or "cosine" | ||
|
|
||
| quantization_parameters: | ||
| enable_quantization: true | ||
| default_weight_keep_negatives: 1. | ||
| default_weight_integer_bits: 0. | ||
| default_weight_fractional_bits: 7. | ||
| default_data_keep_negatives: 0. | ||
| default_data_integer_bits: 0. | ||
| default_data_fractional_bits: 7. | ||
| dynamic_data_quantization: false | ||
| granularity: "per_tensor" | ||
| quantize_input: true | ||
| quantize_output: false | ||
| hgq_beta: 1e-5 | ||
| hgq_gamma: 0.0003 | ||
| hgq_heterogeneous: True | ||
| layer_specific: {} | ||
| use_high_granularity_quantization: false | ||
| use_real_tanh: false | ||
| use_relu_multiplier: false | ||
| use_symmetric_quantization: false | ||
| overflow_mode_parameters: SAT | ||
| overflow_mode_data: SAT | ||
| round_mode: RND | ||
| training_parameters: | ||
| epochs: 200 | ||
| fine_tuning_epochs: 30 | ||
| pretraining_epochs: 0 | ||
| pruning_first: true | ||
| rewind: never | ||
| rounds: 1 | ||
| save_weights_epoch: -1 | ||
| fitcompress_parameters: | ||
| enable_fitcompress : false | ||
| optimize_quantization : true | ||
| quantization_schedule : [7.,4.,3.,2] | ||
| pruning_schedule : {start : 0, end : -3, steps : 40} | ||
| compression_goal : 0.10 | ||
| optimize_pruning : false | ||
| greedy_astar : true | ||
| approximate : true | ||
| f_lambda : 1 | ||
| hpo_parameters: | ||
| experiment_name: experiment_name | ||
| model_name: jet_tagger | ||
| num_trials: 1 | ||
| sampler: | ||
| type: RandomSampler | ||
| hyperparameter_search: | ||
| numerical: {} | ||
| categorical: {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,3 +44,20 @@ | |
| CONFIG_FILE = "config.yaml" | ||
|
|
||
| N_JOBS = 1 | ||
|
|
||
| # --- Hardware-aware pruning metric constants --- | ||
| # Conv-kernel layout -> axis index, used to canonicalise weight layouts in the PACA | ||
| # pattern utilities. Keras conv weights are HWIO, Torch conv weights are OIHW. | ||
| CONV_LAYOUT_AXES = {"H": 0, "W": 1, "I": 2, "O": 3} | ||
| CANONICAL_CONV_LAYOUT = "OIHW" | ||
|
|
||
| # PACAPatternMetric pattern-distance metrics | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not make sth like distance_metrics_registry similar to what is done for SAMPLER_REGISTRY
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! working on it
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Amazing:) |
||
| DISTANCE_HAMMING = "hamming" | ||
| DISTANCE_VALUED_HAMMING = "valued_hamming" | ||
| DISTANCE_COSINE = "cosine" | ||
| PACA_DISTANCE_METRICS = (DISTANCE_HAMMING, DISTANCE_VALUED_HAMMING, DISTANCE_COSINE) | ||
|
|
||
| # FPGAAwareSparsityMetric target hardware resources | ||
| TARGET_RESOURCE_DSP = "DSP" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, why not to make FPGA_TARGET_RESOURCES_REGISTRY, etc? |
||
| TARGET_RESOURCE_BRAM = "BRAM" | ||
| FPGA_TARGET_RESOURCES = (TARGET_RESOURCE_DSP, TARGET_RESOURCE_BRAM) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too much redundant parameters in config files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure Happy to trim them. these two were clones from the
config_mdmm.yamlto stay consistent and trimming them might make it a bit confusing for the user (ommited = default or ommited = forgotten). Do you think we should trim just these two or all of them? the minimal versions should be ~15 linesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can make separate variation of files, including different mdmm parameters for different settings? All others blocks (training, hpo, quantization) should stay the same within the files.