{"record":{"id":"8cd27ef181635bcb","repo":"apache/beam","slug":"unknown-error-type","errorCode":null,"errorMessage":"Unknown error type: {}","messagePattern":"Unknown error type: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/tensorrt_inference.py","lineNumber":94,"sourceCode":"def _build_engine(network, builder):\n  import tensorrt as trt\n  config = builder.create_builder_config()\n  runtime = trt.Runtime(TRT_LOGGER)\n  plan = builder.build_serialized_network(network, config)\n  engine = runtime.deserialize_cuda_engine(plan)\n  builder.reset()\n  return engine\n\n\ndef _assign_or_fail(args):\n  \"\"\"CUDA error checking.\"\"\"\n  from cuda import cuda\n  err, ret = args[0], args[1:]\n  if isinstance(err, cuda.CUresult):\n    if err != cuda.CUresult.CUDA_SUCCESS:\n      raise RuntimeError(\"Cuda Error: {}\".format(err))\n  else:\n    raise RuntimeError(\"Unknown error type: {}\".format(err))\n  # Special case so that no unpacking is needed at call-site.\n  if len(ret) == 1:\n    return ret[0]\n  return ret\n\n\nclass TensorRTEngine:\n  def __init__(self, engine: trt.ICudaEngine):\n    \"\"\"Implementation of the TensorRTEngine class which handles\n    allocations associated with TensorRT engine.\n\n    Example Usage::\n\n      TensorRTEngine(engine)\n\n    Args:\n      engine: trt.ICudaEngine object that contains TensorRT engine\n    \"\"\"","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/tensorrt_inference.py#L76-L112","documentation":"Raised in _assign_or_fail when the first element of a CUDA binding call's return tuple is not a cuda.CUresult instance, meaning the expected (err, ...) result shape from the cuda-python API was not received. It guards against unexpected return types before error-code checking.","triggerScenarios":"A cuda-python API call returns an unexpected tuple shape/type (version drift between the code's expectations and the installed cuda-python package), and the result is passed to _assign_or_fail.","commonSituations":"Mismatched cuda-python (nvidia-cuda-runtime) package version in the worker image versus what tensorrt_inference expects; calling _assign_or_fail with a hand-built args tuple whose first element is not a CUresult; API changes across CUDA minor versions.","solutions":["Pin/align the cuda-python package version with the version your Beam/TensorRT setup expects","Ensure _assign_or_fail is only invoked with raw tuples returned by cuda-python bindings (err first, then return values)","Upgrade the worker image's CUDA/cuda-python stack to a consistent, tested combination"],"exampleFix":"// before\n_assign_or_fail(cuda.cuInit(-1))  # wrong call signature returns unexpected shape\n// after\nerr, = cuda.cuInit(0)\n_assign_or_fail((err,))","handlingStrategy":"type-guard","validationCode":"from cuda import cuda\ndef validate_cuda_binding_shape(result):\n    if not (isinstance(result, tuple) and result and isinstance(result[0], cuda.CUresult)):\n        raise RuntimeError('cuda-python call returned unexpected shape; check package version compatibility')","typeGuard":"from cuda import cuda\ndef is_valid_cuda_result(args) -> bool:\n    return isinstance(args, tuple) and len(args) >= 1 and isinstance(args[0], cuda.CUresult)","tryCatchPattern":"try:\n    predictions = pcoll | RunInference(trt_handler)\nexcept RuntimeError as e:\n    if 'Unknown error type' in str(e):\n        raise RuntimeError('cuda-python API returned unexpected result shape; align cuda-python version with the pipeline image') from e\n    raise","preventionTips":["Pin the cuda-python package version to one tested with your tensorrt/Beam combination","Keep all CUDA stack components (driver, toolkit, cuda-python, tensorrt) in a consistent image","Never pass hand-constructed tuples to _assign_or_fail; feed it raw binding results only"],"tags":["cuda","tensorrt","apache-beam","gpu","version-mismatch"],"backgroundTag":"unexpected-response-shape","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}