apache/beam · error · ValueError
Failed to load ONNX file
Error message
Failed to load ONNX file: {onnx_path} What it means
Raised in tensorrt_inference._load_onnx when the TensorRT OnnxParser fails to parse the ONNX file; the individual parser errors are logged first, then a ValueError naming the ONNX path is raised so engine building aborts early.
Solutions
- Check the worker logs for the per-error output of parser.get_error to identify the failing op/opset
- Re-export the model with an opset version supported by your TensorRT version (e.g. opset 13-17 for TRT 8.x)
- Upgrade the TensorRT (and onnx/onnxruntime) versions in the worker image, or simplify/replace unsupported ops in the exported graph
- Validate the file locally with onnx.checker.check_model before submitting the pipeline
Example fix
// before # exported with opset 18, worker has TensorRT 8.2 (max opset 17) // after # re-export: torch.onnx.export(model, x, path, opset_version=17)
Defensive patterns
Strategy: validation
Validate before calling
import onnx m = onnx.load_model(onnx_path) onnx.checker.check_model(m) # raises on invalid/unsupported models assert m.ir_version <= 8, 'ONNX IR version may exceed TensorRT support'
Try / catch
try:
handler = TensorRTEngineHandlerNumpy(...)
except ValueError as e:
if e.args and str(e).startswith('Failed to load ONNX file'):
raise RuntimeError('Re-export ONNX with an opset supported by the worker TensorRT version; see logs for parser errors') from e
raise Prevention
- Match the export opset to the TensorRT version in the worker image
- Run onnx.checker and an onnxruntime load locally before pipeline launch
- Pin onnx/tensorrt versions together in the container image
When it happens
Trigger: Loading an ONNX file whose format/IR version is unsupported by the installed TensorRT version, a corrupted/truncated file, or a model with unsupported operators — parser.parse returns False.
Common situations: ONNX exported by a newer opset than the TensorRT version supports; model exported with ops (e.g. custom or latest transformers ops) TRT cannot parse; downloading/serializing the file incorrectly (partial upload to GCS); mismatch between onnx and tensorrt package versions.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Cuda Error
- inference_args were provided, but should be None because…
- Unable to load the TensorFlow model
- Callable create_model_fn must be passedwith…
- Cannot make make an unkeyed model handler with pre or…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/66b575f56acb866e.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/ml/inference/tensorrt_inference.py:72
file = FileSystems.open(engine_path, 'rb')
runtime = trt.Runtime(TRT_LOGGER)
engine = runtime.deserialize_cuda_engine(file.read())
assert engine
return engine
def _load_onnx(onnx_path):
import tensorrt as trt
builder = trt.Builder(TRT_LOGGER)
network = builder.create_network(
flags=1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH))
parser = trt.OnnxParser(network, TRT_LOGGER)
with FileSystems.open(onnx_path) as f:
if not parser.parse(f.read()):
LOGGER.error("Failed to load ONNX file: %s", onnx_path)
for error in range(parser.num_errors):
LOGGER.error(parser.get_error(error))
raise ValueError(f"Failed to load ONNX file: {onnx_path}")
return network, builder
def _build_engine(network, builder):
import tensorrt as trt
config = builder.create_builder_config()
runtime = trt.Runtime(TRT_LOGGER)
plan = builder.build_serialized_network(network, config)
engine = runtime.deserialize_cuda_engine(plan)
builder.reset()
return engine
def _assign_or_fail(args):
"""CUDA error checking."""
from cuda import cuda
err, ret = args[0], args[1:]
if isinstance(err, cuda.CUresult):View on GitHub (pinned to 12126d8942)