AttentionMaskAnnealingHook#

class AttentionMaskAnnealingHook(log_frequency=100, log_per_layer=False, prefix='anneal')[source]#

Bases: HookBase

Drive 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_train it seeds the step counter from resumed progress, checks whether the model exposes update_anneal_step (disabling itself otherwise), and logs the annealing schedule. In after_step it advances the model’s annealing step every step and, every log_frequency steps, reads each decoder block’s anneal factor to log the average (and per-block factors when log_per_layer=True) to trainer.storage and the writer, announcing once when annealing completes. Registered as AttentionMaskAnnealingHook.

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 to False.

  • 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_step or has annealing turned off.

Example

Add to cfg.hooks for 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)
after_step()[source]#

Update annealing progress and optionally log statistics.

before_train()[source]#

Check if model supports annealing and log initial state.