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

Add optimizer weights to the model summary. #859

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Changes from 2 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: 18 additions & 2 deletions keras_core/utils/summary_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,19 @@
non_trainable_count = count_params(model.non_trainable_weights)
non_trainable_memory_size = weight_memory_size(model.non_trainable_weights)

total_count = trainable_count + non_trainable_count
total_memory_size = trainable_memory_size + non_trainable_memory_size
if model.compiled and model.optimizer.built:
optimizer_weight_count = count_params(model.optimizer.variables)
optimizer_memory_size = weight_memory_size(model.optimizer.variables)

Check warning on line 313 in keras_core/utils/summary_utils.py

View check run for this annotation

Codecov / codecov/patch

keras_core/utils/summary_utils.py#L312-L313

Added lines #L312 - L313 were not covered by tests
else:
optimizer_weight_count = 0
optimizer_memory_size = 0

total_count = trainable_count + non_trainable_count + optimizer_weight_count
total_memory_size = (
trainable_memory_size
+ non_trainable_memory_size
+ optimizer_memory_size
)

# Create a rich console for printing. Capture for non-interactive logging.
if print_fn:
Expand Down Expand Up @@ -338,6 +349,11 @@
+ highlight_number(f"{non_trainable_count:,}")
+ f" ({readable_memory_size(non_trainable_memory_size)})"
)
console.print(
bold_text(" Optimizer params: ")
+ highlight_number(f"{optimizer_weight_count:,}")
+ f" ({readable_memory_size(optimizer_memory_size)})"
)

# Output captured summary for non-interactive logging.
if print_fn:
Expand Down