Skip to content

Commit

Permalink
Fix duplication of plugin callbacks (#2090)
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragjn authored Nov 20, 2024
1 parent db51a9e commit 68a26f1
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/axolotl/core/trainer_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,11 +1212,17 @@ def get_post_trainer_create_callbacks(self, trainer):
Callbacks added after the trainer is created, usually b/c these need access to the trainer
"""
callbacks = []

plugin_manager = PluginManager.get_instance()
callbacks.extend(
plugin_manager.add_callbacks_post_trainer(cfg=self.cfg, trainer=trainer)
)
if self.cfg.plugins:
plugin_manager = PluginManager.get_instance()
callbacks.extend(
[
cb
for cb in plugin_manager.add_callbacks_post_trainer(
self.cfg, trainer
)
if cb
]
)
return callbacks

def hook_pre_create_training_args(self, training_arguments_kwargs):
Expand Down Expand Up @@ -1263,7 +1269,7 @@ def get_callbacks(self):
return callbacks

def get_post_trainer_create_callbacks(self, trainer):
callbacks = super().get_post_trainer_create_callbacks(trainer=trainer)
callbacks = []
if self.cfg.use_wandb and self.cfg.eval_table_size > 0:
LogPredictionCallback = log_prediction_callback_factory(
trainer, self.tokenizer, "wandb"
Expand Down Expand Up @@ -1301,17 +1307,7 @@ def get_post_trainer_create_callbacks(self, trainer):
if self.cfg.lisa_step_interval and self.cfg.lisa_n_layers:
callbacks.append(lisa_callback_factory(trainer))

if self.cfg.plugins:
plugin_manager = PluginManager.get_instance()
callbacks.extend(
[
cb
for cb in plugin_manager.add_callbacks_post_trainer(
self.cfg, trainer
)
if cb
]
)
callbacks.extend(super().get_post_trainer_create_callbacks(trainer=trainer))
return callbacks

def _get_trainer_cls(self):
Expand Down

0 comments on commit 68a26f1

Please sign in to comment.