Skip to content

Commit c48e271

Browse files
committed
Checks output type
Signed-off-by: Flavia Beo <[email protected]>
1 parent ce42e32 commit c48e271

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

scripts/generate_layers_metrics.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,13 @@ def generate_layers_metrics(model_path, batch_size, seq_length, max_new_tokens):
257257
if cpu_layer == layer:
258258
print("CPU Layer {} GPU Layer {}".format(cpu_layer, layer))
259259

260-
tensor_cpu_cuda_out = cuda_out.to(torch.device('cpu'))
260+
if not type(cuda_out) is tuple:
261+
tensor_cpu_cuda_out = cuda_out.to(torch.device('cpu'))
262+
else:
263+
cuda_out_unique = set(cuda_out)
264+
keys = {key: value for key, value in zip(cuda_out_unique, range(len(cuda_out_unique)))}
265+
tensor_cpu_cuda_out = torch.zeros(size=(len(cuda_out), len(keys)))
266+
261267
abs_diff = torch.abs(cpu_output - tensor_cpu_cuda_out).flatten().tolist()
262268
absolute_differences.extend(abs_diff)
263269

0 commit comments

Comments
 (0)