avalanche icon indicating copy to clipboard operation
avalanche copied to clipboard

New mixin-based template structure

Open HamedHemati opened this issue 3 years ago • 7 comments

I'm creating this draft PR for the new mixin-based template structure. For now, the main goal is to implement working version of the templates that we want and get feedback to improve the structure's simplicity and fix potential bugs.

Current status and next step:

  • Current changes are completely separated from the main templates and do not affect existing strategies.
  • I've tested the current changes for Naive and OnlineNaive strategies and both work fine.
  • Next step: add meta-learning template.

Here is a summary of the changes that I've made:

  • I added a new template called BaseGeneralSGDTemplate that combines the callbacks from the existingBaseSGDTemplate and SupervisedTemplate in order to create a more general template.
  • As discussed in #1079 a new template can be implemented with the following structure: NewTemplate(ObservationType, ProblemType, UpdateType, BaseGeneralSGDTemplate)
  • In common_templates.py I've added the templates for supervised and online supervised strategies and inside strategy_wrappers_temp.py you can see Naive and OnlineNaive strategies.

HamedHemati avatar Jul 12 '22 15:07 HamedHemati

Pull Request Test Coverage Report for Build 3284238644

  • 221 of 278 (79.5%) changed or added relevant lines in 44 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.3%) to 73.124%

Changes Missing Coverage Covered Lines Changed/Added Lines %
avalanche/evaluation/metric_definitions.py 0 1 0.0%
avalanche/evaluation/metric_utils.py 0 1 0.0%
avalanche/evaluation/metrics/checkpoint.py 0 1 0.0%
avalanche/evaluation/metrics/confusion_matrix.py 0 1 0.0%
avalanche/evaluation/metrics/forgetting_bwt.py 0 1 0.0%
avalanche/evaluation/metrics/forward_transfer.py 0 1 0.0%
avalanche/evaluation/metrics/gpu_usage.py 0 1 0.0%
avalanche/evaluation/metrics/images_samples.py 0 1 0.0%
avalanche/evaluation/metrics/labels_repartition.py 0 1 0.0%
avalanche/evaluation/metrics/mean_scores.py 0 1 0.0%
<!-- Total: 221 278
Files with Coverage Reduction New Missed Lines %
avalanche/benchmarks/utils/data_loader.py 1 81.17%
avalanche/training/templates/base_sgd.py 1 89.19%
<!-- Total: 2
Totals Coverage Status
Change from base Build 3282871086: -0.3%
Covered Lines: 12932
Relevant Lines: 17685

💛 - Coveralls

coveralls avatar Jul 12 '22 15:07 coveralls

@AntonioCarta There is also another point regarding plugins: I thought about implementing an existing meta-learning-based strategy as a plugin for SupervisedMetaLearningTemplate and realized that we also need to include inner/outer callbacks to the base plugin class.

We can either have one general base plugin class that consists of all possible callbacks that trigger plugins, or we can extend BaseSGDPlugin as below: BaseSGDPlugin->SupervisedPlugin *which already exists BaseSGDPlugin->MetaLearningPlugin *this needs to be added

What do you think about the extension of plugins? we should also consider that we might need to update it for every new "common" template as well.

HamedHemati avatar Jul 14 '22 08:07 HamedHemati

We can either have one general base plugin class that consists of all possible callbacks

This doesn't make much sense from an inheritance perspective. Childs can add callbacks but they cannot remove them, i.e. they need to support all the callbacks of the parents.

Notice that this is what we do now, where Base -> BaseSGD -> Supervised progressively add new callbacks.

AntonioCarta avatar Jul 18 '22 15:07 AntonioCarta

  • The meta-update class is updated.
  • @AntonioCarta I applied some of your comments, for the other comments I need to discuss them with you in the next meeting.
  • Working examples for Naive, OnlineNaive, and LaMAML (as a plugin) are added.
  • We also need to discuss potential conflicts that can happen with the distributed training PR from Lorenzo

** I've added the prefix NEW_ for the files related to this PR.

HamedHemati avatar Jul 24 '22 18:07 HamedHemati

let me know your opinion about how to create a more "general" plugin class that would cover all possible callbacks

I think you are breaking the inheritance hierarchy with this approach. For example, in your general template you have inner and outer loops, but these do not make sense for some of the child classes. This is undesirable for many reasons.

To give a more concrete example: imagine that you want to create a hierarchy of animals (BaseAnimal is the parent, FlyingAnimal and SeaAnimal the childs). You are saying that all the animals should implement both swim and fly (methods in BaseAnimal), even though SeaAnimal will never fly.

AntonioCarta avatar Aug 23 '22 11:08 AntonioCarta

@AntonioCarta the updates are made according to our last discussion.

HamedHemati avatar Aug 31 '22 16:08 HamedHemati

@HamedHemati can you explain the difference between a template and an observation type? update and problem type are clear to me. I think there isn't a clear separation between template and observation.

AntonioCarta avatar Sep 06 '22 14:09 AntonioCarta

Update:

  • Old template files are removed, and all imports are updated
  • _train_exp is removed from observation_typenow it's a part of the BasedSGDTemplate again
  • observation_type now only checks the model adaptation and optimizer resetting. The behavior is currently different for batch and online updates because of the experience boundary checks (currently specific to OnlineCLExperience)

HamedHemati avatar Sep 30 '22 15:09 HamedHemati