add throughput mode to validation scripts
make raptor also emit input sizes
This commit is contained in:
@@ -156,6 +156,42 @@ def gen_random_inputs(
|
||||
return arrays_in_order, arrays_by_name
|
||||
|
||||
|
||||
def generate_input_batch(onnx_inputs, first_inputs, batch_size, seed):
|
||||
if batch_size < 1:
|
||||
raise ValueError("batch size must be at least 1")
|
||||
if not onnx_inputs:
|
||||
return [first_inputs] * batch_size
|
||||
|
||||
batch = [first_inputs]
|
||||
for index in range(1, batch_size):
|
||||
sample, _ = gen_random_inputs(onnx_inputs, seed=seed + index)
|
||||
if all(np.array_equal(left, right) for left, right in zip(sample, batch[-1])):
|
||||
sample[0] = sample[0].copy()
|
||||
if sample[0].size == 0:
|
||||
raise ValueError("throughput validation cannot distinguish empty input tensors")
|
||||
if np.issubdtype(sample[0].dtype, np.bool_):
|
||||
sample[0].flat[0] = not sample[0].flat[0]
|
||||
elif np.issubdtype(sample[0].dtype, np.integer):
|
||||
info = np.iinfo(sample[0].dtype)
|
||||
value = sample[0].flat[0]
|
||||
sample[0].flat[0] = value + 1 if value < info.max else value - 1
|
||||
else:
|
||||
sample[0].flat[0] += 1
|
||||
batch.append(sample)
|
||||
return batch
|
||||
|
||||
|
||||
def write_input_batch_csv(path, input_batch):
|
||||
path = pathlib.Path(path)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open("w", newline="", encoding="utf-8") as output:
|
||||
writer = csv.writer(output)
|
||||
for sample in input_batch:
|
||||
writer.writerow(
|
||||
np.concatenate([array.reshape(-1) for array in sample]) if sample else ()
|
||||
)
|
||||
|
||||
|
||||
def save_inputs_to_files(onnx_path, arrays_in_order, out_dir):
|
||||
"""
|
||||
Save arrays to CSV files. Returns (flags, files) where flags is a list
|
||||
@@ -201,3 +237,22 @@ def write_inputs_to_memory_bin(memory_bin_path, config_json_path, arrays_in_orde
|
||||
native = arr.astype(arr.dtype.newbyteorder("="), copy=False)
|
||||
f.seek(addr)
|
||||
f.write(native.tobytes(order="C"))
|
||||
|
||||
|
||||
def write_inputs_binary(path, arrays_in_order):
|
||||
"""Write one simulator input in graph-input order."""
|
||||
with open(path, "wb") as f:
|
||||
for arr in arrays_in_order:
|
||||
native = arr.astype(arr.dtype.newbyteorder("="), copy=False)
|
||||
f.write(native.tobytes(order="C"))
|
||||
|
||||
|
||||
def write_input_batch_binaries(input_batch, output_dir, transform=None):
|
||||
output_dir = pathlib.Path(output_dir)
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
paths = []
|
||||
for index, sample in enumerate(input_batch):
|
||||
path = output_dir / f"input_{index}.bin"
|
||||
write_inputs_binary(path, [transform(sample[0])] if transform is not None else sample)
|
||||
paths.append(path)
|
||||
return paths
|
||||
|
||||
Reference in New Issue
Block a user