docstr: Test models are initialized properly
docstr_tok: ["Test","models","are","initialized","properly"]
code: def test_torch_model_init(self):
      """Test models are initialized properly"""
      model_config = {
          "embed_dim": 32,
          "num_layers": 2,
          "max_seq_len": 4,
          "max_ep_len": 10,
          "num_heads": 2,
          "embed_pdrop": 0.1,
          "resid_pdrop": 0.1,
          "attn_pdrop": 0.1,
          "use_obs_output": False,
          "use_return_output": False,
      }
  
      num_outputs = 2
      observation_space = gym.spaces.Box(
          -1.0, 1.0, shape=(num_outputs,)
      )
  
      action_dim = 5
      action_spaces = [
          gym.spaces.Box(-1.0, 1.0, shape=(action_dim,)),
          gym.spaces.Discrete(action_dim),
      ]
  
      B, T = 3, 4
  
      for action_space in action_spaces:
          # Generate input dict.
          input_dict = _generate_input_dict(
              B, T, observation_space, action_space
          )
  
          # Do random initialization a few times and make sure outputs are different
          outputs = []
          for _ in range(10):
              model = DTTorchModel(
                  observation_space,
                  action_space,
                  num_outputs,
                  model_config,
                  "model",
              )
              # so dropout is not in effect
              model.eval()
              model_out, _ = model(input_dict)
              output = model.get_prediction(model_out, input_dict)
              outputs.append(convert_to_numpy(output))
          _assert_outputs_not_equal(outputs)
  
          # Initialize once and make sure dropout is working
          model = DTTorchModel(
              observation_space,
              action_space,
              num_outputs,
              model_config,
              "model",
          )
  
          # Dropout should make outputs different in training mode
          model.train()
          outputs = []
          for _ in range(10):
              model_out, _ = model(input_dict)
              output = model.get_prediction(model_out, input_dict)
              outputs.append(convert_to_numpy(output))
          _assert_outputs_not_equal(outputs)
  
          # Dropout should make outputs the same in eval mode
          model.eval()
          outputs = []
          for _ in range(10):
              model_out, _ = model(input_dict)
              output = model.get_prediction(model_out, input_dict)
              outputs.append(convert_to_numpy(output))
          _assert_outputs_equal(outputs)
  
file_path: ray/rllib_contrib/dt/tests/test_dt_model.py
imports: import unittest
  import gymnasium
  import numpy
  from rllib_dt.dt.dt_torch_model import DTTorchModel
  import ray
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.framework import try_import_tf, try_import_torch
  from ray.rllib.utils.numpy import convert_to_numpy
  from ray.rllib.utils.torch_utils import convert_to_torch_tensor
label_desc: Use image node_id 3 for calling the TestDTModel obj's underlying member method code with example usage: obj.test_torch_model_init() without return types