code: def from_str(cls, string: str) -> "Device":
      if string.startswith("cuda") or string.startswith("gpu"):
          return cls(
              DeviceType.GPU,
              int(string.split(":")[1] if ":" in string else 0),
          )
      elif string.startswith("tpu"):
          return cls(
              DeviceType.TPU,
              int(string.split(":")[1] if ":" in string else 0),
          )
  
      return cls(DeviceType.CPU)
  
imports: import subprocess
  from dataclasses import dataclass
  from enum import Enum
  from functools import cached_property
  from typing import Optional, Any, Union, Tuple, List, Dict
  import numpy
  from nebullvm.optional_modules.tensorflow import tensorflow
  from nebullvm.optional_modules.torch import torch
label_desc: Use image node_id 2 for calling the Device obj's underlying member method code with example usage: obj.from_str(cls, string) and returns: cls, cls, cls