Vui Seng Chua
commited on
Commit
·
5d8fc83
1
Parent(s):
a555ead
Add tile sparsity distribution plots
Browse files- plot_tile_dist.py +45 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.0.png +0 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.1.png +0 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.2.png +0 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.3.png +0 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.4.png +0 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.5.png +0 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.6.png +0 -0
- tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.7.png +0 -0
plot_tile_dist.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from lookup_sparsity_blob import SparseBlob
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
from glob import glob
|
4 |
+
|
5 |
+
def plot_layer_hist(df, row_id, ax, type=None):
|
6 |
+
if type is None:
|
7 |
+
return "pls specify type='widest' or 'narrowest'"
|
8 |
+
|
9 |
+
cols = ['layer_id', 'shape', 'sparsity','tile_limit', 'tile_min', 'tile_med', 'tile_max', 'tile_shape', 'n_tile']
|
10 |
+
meta = df.loc[row_id, cols]
|
11 |
+
tensor = sb._blob[meta.layer_id]['tile_sparsity']
|
12 |
+
|
13 |
+
l = meta.layer_id
|
14 |
+
l_shape = str(tuple(meta['shape']))
|
15 |
+
l_sparsity = meta.sparsity*100
|
16 |
+
hist_limit = f"min: {meta.tile_min:.2f}, median: {meta.tile_med:.2f}, max: {meta.tile_max:.2f}"
|
17 |
+
l_cfg = f"{meta.n_tile} tiles of {meta.tile_shape}"
|
18 |
+
|
19 |
+
ax.hist(tensor.flatten().cpu().numpy(), bins=25, edgecolor='white', color='blue')
|
20 |
+
ax.set_xlabel('Tile Sparsity')
|
21 |
+
ax.set_ylabel('Frequency')
|
22 |
+
ax.set_title(f'{l} {l_shape}\nlayer_sparsity: {l_sparsity:2.0f}%\n\ntile_sparsity ({type}):\n{hist_limit}\n\n{l_cfg}')
|
23 |
+
|
24 |
+
ax.grid(True, axis='y', linestyle='--', alpha=0.3)
|
25 |
+
ax.spines['top'].set_visible(False)
|
26 |
+
ax.spines['right'].set_visible(False)
|
27 |
+
ax.tick_params(axis='both', which='major', labelsize=12)
|
28 |
+
|
29 |
+
|
30 |
+
sparse_model_list = sorted(glob("blob.sparsity*"))
|
31 |
+
|
32 |
+
for model_blob in sparse_model_list:
|
33 |
+
plot_name = model_blob.replace("blob.sparsity.", "tile_sparsity_dist.")
|
34 |
+
sb = SparseBlob(model_blob)
|
35 |
+
|
36 |
+
df = sb._rpt[:-1]
|
37 |
+
df['tile_limit'] = df.tile_max - df.tile_min
|
38 |
+
|
39 |
+
fig, axes = plt.subplots(1, 2, figsize=(12, 5)) # 1 row, 2 columns
|
40 |
+
|
41 |
+
plot_layer_hist(df, df.tile_limit.idxmin(), axes[0], type="narrowest")
|
42 |
+
plot_layer_hist(df, df.tile_limit.idxmax(), axes[1], type="widest")
|
43 |
+
|
44 |
+
plt.tight_layout()
|
45 |
+
plt.savefig(f'{plot_name}.png')
|
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.0.png
ADDED
![]() |
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.1.png
ADDED
![]() |
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.2.png
ADDED
![]() |
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.3.png
ADDED
![]() |
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.4.png
ADDED
![]() |
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.5.png
ADDED
![]() |
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.6.png
ADDED
![]() |
tile_sparsity_dist._Meta-Llama-3.1-8B-wanda-unstructured-0.7.png
ADDED
![]() |