qonnx.util.basic (module)
- qonnx.util.basic.calculate_matvec_accumulator_range(matrix: numpy.ndarray, vec_dt: qonnx.core.datatype.DataType)
Calculate the minimum and maximum possible result (accumulator) values for a dot product x * A, given matrix A of dims (MW, MH), and vector (1, MW) with datatype vec_dt. Returns (acc_min, acc_max).
- qonnx.util.basic.calculate_signed_dot_prod_range(dt_a, dt_b, len)
Returns the (min,max) values a dot product between two signed vectors of types dt_a and dt_b of len elements can take.
- qonnx.util.basic.gen_finn_dt_tensor(finn_dt, tensor_shape)
Generates random tensor in given shape and with given QONNX DataType.
- qonnx.util.basic.get_by_name(container, name, name_field='name')
Return item from protobuf container by .name field if it exists, None otherwise. Will throw an Exception if multiple items are found, since this violates the ONNX standard.
- qonnx.util.basic.get_execution_error_thresh()
Return the max error that is allowed for rounding in QONNX execution.
- qonnx.util.basic.get_num_default_workers()
Return the number of workers for parallel transformations. Controllable via the NUM_DEFAULT_WORKERS environment variable. If the env.var. is undefined, the default value of 1 is returned.
- qonnx.util.basic.get_preferred_onnx_opset()
Return preferred ONNX opset version for QONNX
- qonnx.util.basic.get_sanitize_quant_tensors()
Return whether tensors with quantization annotations should be sanitized. Enabled by default, disabling will yield faster ONNX execution but may give incorrect results. Use with caution.
- qonnx.util.basic.interleave_matrix_outer_dim_from_partitions(matrix, n_partitions)
Interleave the outermost dimension of a matrix from given partitions (n_partitions).
- qonnx.util.basic.is_finn_op(op_type)
Return whether given op_type string is a QONNX or FINN custom op
- qonnx.util.basic.pad_tensor_to_multiple_of(ndarray, pad_to_dims, val=0, distr_pad=False)
Pad each dimension of given NumPy ndarray using val, so that each dimension is a multiple of the respective value in pad_to_dims. -1 means do not pad that particular dimension. If distr_pad is False, all padding will be inserted after the existing values; otherwise it will be split evenly between before and after the existing values, with one extra value inserted after if the padding amount is not divisible by two.
- qonnx.util.basic.qonnx_make_model(graph_proto, **kwargs)
Wrapper around ONNX make_model with preferred qonnx opset version
- qonnx.util.basic.random_string(stringLength=6)
Randomly generate a string of letters and digits.
- qonnx.util.basic.remove_by_name(container, name, name_field='name')
Remove item from protobuf container by .name field if it exists.
- qonnx.util.basic.roundup_to_integer_multiple(x, factor)
Round up integer x to the nearest integer multiple of integer factor. Returns x if factor is set to -1. Both x and factor must otherwise be positive.
- qonnx.util.basic.sanitize_quant_values(model, node_tensors, execution_context, check_values=False)
Sanitize given list of tensors in execution_context by rounding values that are supposed to be integers (as indicated by their quantization annotation). Will raise an assertion if the amount of rounding is too large. Returns the sanitized execution context.
If check_values is specified, an extra DataType.allowed() check will be performed on any rounded tensors.
Background: QONNX uses floating point tensors as a carrier data type to represent integers. Floating point arithmetic can introduce rounding errors, e.g. (int_num * float_scale) / float_scale is not always equal to int_num. We use this function to ensure that the values that are supposed to be integers are indeed integers.