emmi_inference.device

Attributes

Classes

DeviceEnum

Supported execution devices.

DeviceContext

Carrier for device execution context.

Functions

resolve_device([device])

Resolve the effective device string.

sync_device(device)

Synchronize device streams.

resolve_autocast(effective_device, requested)

Decide whether autocast should be enabled.

Module Contents

class emmi_inference.device.DeviceEnum

Bases: enum.StrEnum

Supported execution devices.

AUTO

Let the library pick the best available backend (CUDA -> MPS -> CPU).

CPU

Force CPU execution.

CUDA

NVIDIA CUDA GPU (if available).

MPS

Apple Metal Performance Shaders backend on Apple Silicon (if available).

Initialize self. See help(type(self)) for accurate signature.

AUTO = 'auto'
CPU = 'cpu'
CUDA = 'cuda'
MPS = 'mps'
emmi_inference.device.DeviceType
emmi_inference.device.resolve_device(device=DeviceEnum.AUTO)

Resolve the effective device string.

Parameters:

device (DeviceType) – Either a DeviceEnum or a string (“auto”, “cpu”, “cuda”, “mps”). When set to “auto”, prefers CUDA, then MPS, then CPU.

Returns:

One of “cuda”, “mps”, or “cpu” depending on runtime availability.

Return type:

str

emmi_inference.device.sync_device(device)

Synchronize device streams.

Parameters:

device (DeviceType) – Either a DeviceEnum or string; will be resolved to the effective device.

Return type:

None

emmi_inference.device.resolve_autocast(effective_device, requested)

Decide whether autocast should be enabled.

Autocast is disabled on Apple MPS as PyTorch doesn’t support it.

Parameters:
  • effective_device (str) – The resolved device string (“cuda”, “mps”, or “cpu”).

  • requested (bool) – Whether the user requested autocast.

Returns:

True if autocast should be enabled on the effective device, otherwise False.

Return type:

bool

class emmi_inference.device.DeviceContext(device, dtype, autocast)

Carrier for device execution context.

Parameters:
  • device (str)

  • dtype (torch.dtype | None)

  • autocast (bool)

device

Effective device string (“cuda”, “mps”, or “cpu”).

dtype

Optional compute dtype used for autocast/mixed precision.

autocast

Whether to attempt autocast (subject to device support).

device
dtype
autocast
amp()

Return an AMP/autocast context manager for the current device.

Returns:

torch.cuda.amp.autocast when enabled on CUDA; otherwise a no-op context manager.

Return type:

ContextManager