def METHOD_NAME(self, beam_size):
    """Sets the beam size in the decoder and all children."""
    if getattr(self, "_beam_size", -1) != beam_size:
        seen = set()
        def apply_set_beam_size(module):
            if (
                module != self
                and hasattr(module, "set_beam_size")
                and module not in seen
            ):
                seen.add(module)
                module.METHOD_NAME(beam_size)
        self.apply(apply_set_beam_size)
        self._beam_size = beam_size