The Megatron attack employs two custom attention-based loss terms: a latent loss that aligns the last attention layer between triggered and clean samples of the target label, and an attention diffusion loss that emphasizes the trigger's diffusion area, enhancing stealth.