code: def test__decode_as_placeholder():
      device = torch.device("cpu")
  
      encoded_msg = [-1] * 512
      encoded_msg[0] = 1
      res = ComputationModel._decode_as_placeholder(encoded_msg, device)
      assert isinstance(res, float) and res == 0.0
  
      encoded_msg = [-1] * 512
      encoded_msg[0] = 2
      res = ComputationModel._decode_as_placeholder(encoded_msg, device)
      assert isinstance(res, str) and res == ""
  
      encoded_msg = [-1] * 512
      encoded_msg[0] = 0
      encoded_msg[1 : 1 + 7] = [6, 2, 3, 4, 5, 6, 7]
      dtype_str = "torch.int64"
      payload = [len(dtype_str), *list(bytearray(dtype_str, "utf-8"))]
      encoded_msg[1 + 7 : 1 + 7 + len(payload)] = payload
      res = ComputationModel._decode_as_placeholder(encoded_msg, device)
      assert (
          isinstance(res, torch.Tensor)
          and res.dtype == torch.int64
          and res.shape == (2, 3, 4, 5, 6, 7)
      )
  
      encoded_msg = [-1] * 512
      with pytest.raises(
          RuntimeError, match="Internal error: unhandled dtype"
      ):
          ComputationModel._decode_as_placeholder(encoded_msg, device)
  
      t = torch.rand(2, 512, 32, 32, 64)
      encoded_msg = ComputationModel._encode_input_data(t, True)
      res = ComputationModel._decode_as_placeholder(encoded_msg, device)
      assert (
          isinstance(res, torch.Tensor)
          and res.dtype == t.dtype
          and res.shape == t.shape
      )
  
      t = torch.tensor(12)
      encoded_msg = ComputationModel._encode_input_data(t, True)
      res = ComputationModel._decode_as_placeholder(encoded_msg, device)
      assert (
          isinstance(res, torch.Tensor)
          and res.dtype == t.dtype
          and res.shape == t.shape
      )
  
file_path: ignite/tests/ignite/distributed/comp_models/test_base.py
imports: import pytest
  import torch
  from ignite.distributed.comp_models.base import _SerialModel, _torch_version_le_112, ComputationModel
label_desc: Use image node_id 4 for calling a global function with example usage: test__decode_as_placeholder() without return types