Constant

class onnx_graphsurgeon.Constant(name: str, values: ndarray | LazyValues, data_location: int = None, export_dtype: dtype | onnx.TensorProto.DataType = None)

Bases: Tensor

Represents a Tensor whose value is known.

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

  • values (numpy.ndarray) – The values in this tensor, in the form of a NumPy array.

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

  • export_dtype (Union[np.dtype, onnx.TensorProto.DataType]) – The data type of the tensor when exported to onnx. If not specified, then the data type of values will be used.

to_variable(dtype: dtype | None = None, shape: Sequence[int | str] = [])

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

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

  • shape (Sequence[int]) – The shape of the tensor.

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.