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

fix normalization by number of examples #80

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion analog/statistic/covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def update(
data = binfo.log[module_name][log_type]

# extract and reshape data to 2d tensor for mean computation
batch_size = data.size(0)
data = make_2d(data, module, log_type).detach()

# initialize covariance state if necessary
Expand Down Expand Up @@ -55,6 +56,6 @@ def update(

# update mean counter
if binfo.mask is None or log_type == "grad":
covariance_counter[module_name][log_type] += len(data)
covariance_counter[module_name][log_type] += batch_size
else:
covariance_counter[module_name][log_type] += binfo.mask.sum().item()
3 changes: 2 additions & 1 deletion analog/statistic/mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def update(
data = binfo.log[module_name][log_type]

# extract and reshape data to 2d tensor for mean computation
batch_size = data.size(0)
data = make_2d(data, module, log_type).detach()

# initialize mean state if necessary
Expand All @@ -51,6 +52,6 @@ def update(

# update mean counter
if binfo.mask is None or log_type == "grad":
mean_counter[module_name][log_type] += len(data)
mean_counter[module_name][log_type] += batch_size
else:
mean_counter[module_name][log_type] += binfo.mask.sum().item()
Loading