Variable

class onnx_graphsurgeon.Variable(name: str, dtype: dtype | onnx.TensorProto.DataType = None, shape: Sequence[int | str] = None, type: str = 'tensor_type')

Bases: Tensor

Represents a Tensor whose value is not known until inference-time.

Parameters:
  • name (str) – The name of the tensor.

  • dtype (Union[numpy.dtype, onnx.TensorProto.DataType]) – The data type of the tensor.

  • shape (Sequence[Union[int, str]]) – The shape of the tensor. This may contain strings if the model uses dimension parameters.

  • type (str) – The type of the tensor.

to_constant(values: ndarray)

Modifies this tensor in-place to convert it to a Constant. This means that all consumers/producers of the tensor will see the update.

Parameters:
  • values (np.ndarray) – The values in this tensor

  • data_location (int) – An enum value indicating the location where the tensor data is stored. Generally, this will come from onnx.TensorProto.DataLocation.

Returns:

self

copy()

Makes a shallow copy of this tensor, omitting input and output information.

Note: Generally, you should only ever make a copy of a Graph.