def _state_guard(
        self,
        func_name: str,
        previous: t.Sequence[State],
        next: State,
    ):
        """Ensure that the state is in the correct state and transition to the
        next correct state.
        """
        if self.state not in previous:
            previous_str = ", ".join([str(x) for x in previous])
            raise self.StateError(
                f"Calling `{func_name}` is only valid for `{previous_str}` "
                f"instead PackNet was in the `{self.state}` state"
            )
        self._state.fill_(next.value)
Ensure that the state is in the correct state and transition to the
        next correct state.
        
avalanche/models/packnet.py