code: def mask_forward_fn_torch(forward_fn, batch, **kwargs):
      _check_batch(batch)
  
      # Extract the available actions tensor from the observation.
      action_mask = batch[SampleBatch.OBS]["action_mask"]
  
      # Modify the incoming batch so that the default models can compute logits and
      # values as usual.
      batch[SampleBatch.OBS] = batch[SampleBatch.OBS]["observations"]
  
      outputs = forward_fn(batch, **kwargs)
  
      # Mask logits
      logits = outputs[SampleBatch.ACTION_DIST_INPUTS]
      # Convert action_mask into a [0.0 || -inf]-type mask.
      inf_mask = torch.clamp(torch.log(action_mask), min=FLOAT_MIN)
      masked_logits = logits + inf_mask
  
      # Replace original values with masked values.
      outputs[SampleBatch.ACTION_DIST_INPUTS] = masked_logits
  
      return outputs
  
imports: import gymnasium
  from ray.rllib.algorithms.ppo.tf.ppo_tf_rl_module import PPOTfRLModule
  from ray.rllib.algorithms.ppo.torch.ppo_torch_rl_module import PPOTorchRLModule
  from ray.rllib.core.rl_module.rl_module import RLModule, RLModuleConfig
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.framework import try_import_torch, try_import_tf
  from ray.rllib.utils.torch_utils import FLOAT_MIN
label_desc: Use image node_id 1 for calling a global function with example usage: mask_forward_fn_torch(forward_fn, batch) and returns: outputs