AttentionMaskAnnealingHook#
- class AttentionMaskAnnealingHook(log_frequency=100, log_per_layer=False, prefix='anneal')[source]#
Bases:
HookBaseDrive and log attention-mask annealing for the Panda detector decoder.
For models that gradually anneal their decoder attention masks (e.g. a Mask3Former-style decoder). In
before_trainit seeds the step counter from resumed progress, checks whether the model exposesupdate_anneal_step(disabling itself otherwise), and logs the annealing schedule. Inafter_stepit advances the model’s annealing step every step and, everylog_frequencysteps, reads each decoder block’s anneal factor to log the average (and per-block factors whenlog_per_layer=True) totrainer.storageand the writer, announcing once when annealing completes. Registered asAttentionMaskAnnealingHook.- Parameters:
log_frequency (int) – Log annealing factors every this many steps. Defaults to
100.log_per_layer (bool) – If
True, also log each decoder block’s anneal factor. Defaults toFalse.prefix (str) – Namespace prefix for the logged keys. Defaults to
"anneal".
Note
This hook updates the model’s annealing state, so it is functionally required (not merely diagnostic) for models that anneal. It silently disables itself if the model lacks
update_anneal_stepor has annealing turned off.Example
Add to
cfg.hooksfor a Mask3Former-style Panda decoder; it both drives and logs attention-mask annealing:hooks = [ dict(type="AttentionMaskAnnealingHook", log_frequency=100, log_per_layer=True), ] # → calls model.update_anneal_step(step) every step; every 100 steps # puts "anneal_factor" in trainer.storage and writes "anneal/average" # (and "anneal/layer_<i>" per block) to the writer; logs once when the # factor drops below 0.01 (annealing complete)