Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added lower_triangle #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions statistics_util/statistic_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ def create_statistics(self, graph_y_labels):

for i, i_head in enumerate(i_first_batch):
## Flatten across heads, height, and width
flattened = i_head.view(-1)
i_head = i_head[torch.tril(torch.ones_like(i_head)) == 1]

## Calculate statistics
i_means.append(torch.nanmean(flattened).item())
i_medians.append(torch.nanmedian(flattened).item())
i_means.append(torch.nanmean(i_head).item())
i_medians.append(torch.nanmedian(i_head).item())

# Standard deviation, ignoring NaNs
mask = ~torch.isnan(i_head)
Expand All @@ -213,8 +213,8 @@ def create_statistics(self, graph_y_labels):
denominator.append(sum.item())

## Append statistic to the input list of each head in each layer
self.stats['mean'][layer][i].append(torch.nanmean(flattened).item())
self.stats['median'][layer][i].append(torch.nanmedian(flattened).item())
self.stats['mean'][layer][i].append(torch.nanmean(i_head).item())
self.stats['median'][layer][i].append(torch.nanmedian(i_head).item())
self.stats['stdev'][layer][i].append(torch.std(i_head[mask]).item())
self.stats['max'][layer][i].append(torch.max(torch.where(torch.isnan(i_head), torch.tensor(float('-inf')), i_head)).item())
self.stats['min'][layer][i].append(torch.min(torch.where(torch.isnan(i_head), torch.tensor(float('inf')), i_head)).item())
Expand All @@ -228,12 +228,12 @@ def create_statistics(self, graph_y_labels):
for i, o_head in enumerate(o_first_batch):

# Step 3: Flatten across heads, height, and width
flattened = o_head.view(-1)
o_head = o_head[torch.tril(torch.ones_like(o_head)) == 1]

# Step 4: Calculate statistics
## Calculate statistics
o_means.append(torch.nanmean(flattened).item())
o_medians.append(torch.nanmedian(flattened).item())
o_means.append(torch.nanmean(o_head).item())
o_medians.append(torch.nanmedian(o_head).item())
# Standard deviation, ignoring NaNs
mask = ~torch.isnan(o_head)
o_stdevs.append(torch.std(o_head[mask]).item())
Expand All @@ -247,8 +247,8 @@ def create_statistics(self, graph_y_labels):
o_min_values.append(torch.min(torch.where(torch.isnan(o_head), torch.tensor(float('inf')), o_head)).item())

# Append statistic to the output list of each head in each layer
self.stats['o_mean'][layer][i].append(torch.nanmean(flattened).item())
self.stats['o_median'][layer][i].append(torch.nanmedian(flattened).item())
self.stats['o_mean'][layer][i].append(torch.nanmean(o_head).item())
self.stats['o_median'][layer][i].append(torch.nanmedian(o_head).item())
self.stats['o_stdev'][layer][i].append(torch.std(o_head[mask]).item())
self.stats['o_max'][layer][i].append(torch.max(torch.where(torch.isnan(o_head), torch.tensor(float('-inf')), o_head)).item())
self.stats['o_min'][layer][i].append(torch.min(torch.where(torch.isnan(o_head), torch.tensor(float('inf')), o_head)).item())
Expand Down
Loading