code: def from_pipeline(
      cls: Type[TAPI],
      m: TPipeline,
      device: Optional[str] = None,
      *,
      use_amp: bool = False,
      use_half: bool = False,
      **kwargs: Any,
  ) -> TAPI:
      if use_amp and use_half:
          raise ValueError(
              "`use_amp` & `use_half` should not be True simultaneously"
          )
      model = m.build_model.model
      if use_half:
          model.half()
      if device is not None:
          model.to(device)
      return cls(
          model,
          get_device(model),
          use_amp=use_amp,
          use_half=use_half,
          **kwargs,
      )
  
imports: import torch
  import torch.nn
  from typing import Any
  from typing import Type
  from typing import TypeVar
  from typing import Optional
  from cftool.data_structures import ILoadableItem
  from cftool.data_structures import ILoadablePool
  from cftool.types import tensor_dict_type
  from torch.cuda.amp.autocast_mode import autocast
  from .zoo import TPipeline
  from ..misc.toolkit import is_cpu
  from ..misc.toolkit import get_device
  from ..misc.toolkit import empty_cuda_cache
label_desc: Use image node_id 5 for calling the APIMixin obj's underlying member method code with example usage: obj.from_pipeline(cls, m, device) and returns: cls