code: def with_seed(func, parallel_mode: ParallelMode):
      """
      A function wrapper which executes the function with a specified seed.
  
      Examples:
  
          >>> # use with decorator
          >>> @with_seed(ParallelMode.DATA)
          >>> def forward(input):
          >>>     return F.dropout(input)
          >>> out = forward(input)
          >>> # OR use it inline
          >>> def forward(input):
          >>>     return F.dropout(input)
          >>> wrapper_forward = with_seed(forward, ParallelMode.DATA)
          >>> out = wrapped_forward(input)
  
      Note:
          The parallel_mode should be concluded in ``ParallelMode``. More details about ``ParallelMode`` could be found
          in `parallel_mode <https://github.com/hpcaitech/ColossalAI/blob/main/colossalai/context/parallel_mode.py>`_.
      """
  
      @functools.wraps(func)
      def wrapper(*args, **kwargs):
          # switch mode
          current_mode = _SEED_MANAGER.current_mode
          _SEED_MANAGER.set_mode(parallel_mode)
  
          # exec func
          out = func(*args, **kwargs)
  
          # recover state
          _SEED_MANAGER.set_mode(current_mode)
  
          return out
  
      return wrapper
  
file_path: colossalai/colossalai/legacy/context/random/_helper.py
imports: import functools
  from contextlib import contextmanager
  import torch.cuda
  from torch import Tensor
  from ..parallel_mode import ParallelMode
  from .seed_manager import SeedManager
label_desc: Use image node_id 9 for calling a global function with example usage: with_seed(func, parallel_mode) and returns: wrapper, out