Python · Errors

Errors

import uformfrom uform import Error 4.0.0-rc.1 · 3ee5e534

Every failure raises a subclass of uform.Error, itself a RuntimeError, and each carries the status the C ABI reported as its status attribute, a uform.Status member:

try:
    model.on(executor).text_encode(texts, arena, progress=lambda completed, total: completed < 100)
except uform.CancelledError:
    ...  # The handler stopped the call, which published nothing
except uform.Error as error:
    print(error.status)  # Status.SHAPE_MISMATCH, Status.DEVICE, ...

SUCCESS and DEFERRED raise nothing, and every other member has its own class, which also derives the built-in naming the same fault where one exists:

  • OUT_OF_MEMORY → OutOfMemoryError, a MemoryError
  • SHAPE_MISMATCH → ShapeMismatchError, a ValueError
  • UNSUPPORTED_LAYOUT → UnsupportedLayoutError, a ValueError
  • UNKNOWN_KIND → UnknownKindError, a ValueError
  • IO → InputOutputError, an OSError
  • DEVICE → DeviceError
  • MALFORMED → MalformedError, a ValueError
  • INTERNAL → InternalError
  • CONFIG_MISMATCH → ConfigMismatchError, a ValueError
  • CONTENDED → ContendedError
  • CANCELLED → CancelledError
  • UNSUPPORTED → UnsupportedError, a NotImplementedError
  • INVALID_ARGUMENT → InvalidArgumentError, a ValueError

A failure the binding catches before the boundary raises the class the library would have raised for the same fault. Arguments the binding refuses raise at the call, while the library’s refusals of a deferred call raise at await or wait().

API

Types

StatusWhat a call finished with, valued as uform_status_t: Error.status and Deferred.status.
__init__.py:53 ↗
class Status(IntEnum)

Values

SUCCESS0
DEFERRED1
OUT_OF_MEMORY2
SHAPE_MISMATCH3
UNSUPPORTED_LAYOUT4
UNKNOWN_KIND5
IO7
DEVICE8
MALFORMED9
INTERNAL10
CONFIG_MISMATCH13
CONTENDED14
CANCELLED15
UNSUPPORTED16
INVALID_ARGUMENT17
OutOfMemoryErrorDevice, pinned, or host memory could not be allocated, or the scratch ceiling is too low.
__init__.py:232 ↗
class OutOfMemoryError(Error, MemoryError)
ShapeMismatchErrorItem counts, a pixel shape, or a batch envelope disagree with the call or the model.
__init__.py:235 ↗
class ShapeMismatchError(Error, ValueError)
UnsupportedLayoutErrorA stride or packing the model cannot read.
__init__.py:238 ↗
class UnsupportedLayoutError(Error, ValueError)
UnknownKindErrorA scalar, modality, or name this build does not know.
__init__.py:241 ↗
class UnknownKindError(Error, ValueError)
InputOutputErrorA checkpoint file could not be opened, read, or written.
__init__.py:244 ↗
class InputOutputError(Error, OSError)
DeviceErrorThe driver refused or the device faulted; after a fault the executor refuses every later call.
__init__.py:247 ↗
class DeviceError(Error)
MalformedErrorSupplied bytes could not be decoded: a checkpoint, an image, a clip, or a recording.
__init__.py:250 ↗
class MalformedError(Error, ValueError)
InternalErrorThe library reported neither success nor a failure - a defect.
__init__.py:253 ↗
class InternalError(Error)
ConfigMismatchErrorThe request contradicts a frozen configuration, like resuming a checkpoint of another geometry.
__init__.py:256 ↗
class ConfigMismatchError(Error, ValueError)
ContendedErrorAn executor's deferred table or an arena is already serving another call.
__init__.py:259 ↗
class ContendedError(Error)
CancelledErrorA progress handler stopped the call, which published nothing.
__init__.py:262 ↗
class CancelledError(Error)
UnsupportedErrorThe verb is declared, but this residency or model does not implement it.
__init__.py:265 ↗
class UnsupportedError(Error, NotImplementedError)
InvalidArgumentErrorAn argument breaks the verb's contract, a closed executor and a rewound arena's output included.
__init__.py:268 ↗
class InvalidArgumentError(Error, ValueError)
ClassErrorThe base of every failure the library reports, one subclass per status shared with the C API.1
lib.pyi:227 ↗
class Error(RuntimeError)
status
lib.pyi:230 ↗
status: Status