This document is relevant for: Inf2, Trn1, Trn2, Trn3

nrtpy error handling#

This page documents the exception hierarchy raised by nrtpy.

Exception hierarchy#

RuntimeError
+-- NrtpyError        # nrtpy-level errors (e.g., using a freed tensor)
+-- NrtError          # libnrt errors with preserved status code

Both exception classes inherit from Python’s built-in RuntimeError, so a bare except RuntimeError catches all nrtpy errors.

NrtpyError#

exception nrtpy.NrtpyError#

Raised for errors detected at the nrtpy Python layer — for example, passing a freed tensor to an operation, or calling configure() when the runtime is already active.

NrtError#

exception nrtpy.NrtError#

Raised when the underlying libnrt C API returns a non-success status code. The exception message includes the NRT status name and numeric code.

Common causes:

  • Loading a NEFF file that does not exist or is corrupt.

  • Allocating a tensor larger than available device memory.

  • Executing a model with mismatched input/output tensor names.

Examples#

from nrtpy import NrtpyModel, NrtpyError, NrtError

# Catch libnrt errors (e.g., file not found)
try:
    model = NrtpyModel.load_from_neff("nonexistent.neff")
except NrtError as e:
    print(f"NRT error: {e}")
    # "NRT Error NRT_FAILURE(1): Failed to load model"

# Catch nrtpy-level errors (e.g., invalid state)
try:
    # ... use a tensor after nrtpy.reset() ...
    pass
except NrtpyError as e:
    print(f"nrtpy error: {e}")

# Catch all nrtpy errors
try:
    model(inputs={"x": some_tensor})
except RuntimeError as e:
    print(f"Error: {e}")