Skip to content

Wire total_weights into ML Diagnostics metrics - #474

Open
richaguptaa17 wants to merge 1 commit into
AI-Hypercomputer:mainfrom
richaguptaa17:mldiag-metric-weights
Open

Wire total_weights into ML Diagnostics metrics#474
richaguptaa17 wants to merge 1 commit into
AI-Hypercomputer:mainfrom
richaguptaa17:mldiag-metric-weights

Conversation

@richaguptaa17

Copy link
Copy Markdown
Contributor
  • Pass the existing num_model_parameters calculation into record_scalar_metrics(..., total_weights=num_model_parameters) across all trainers (Stable Diffusion, SDXL, Flux, Wan, and DreamBooth). This populates the total_weights card in Google Cloud ML Diagnostics.
  • Remove the redundant metric_types import and if/else branching. Standardize _METRICS_TO_MANAGED directly on canonical string literals, matching the SDK's internal representation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request simplifies metric reporting by removing the dependency on metric_types from google_cloud_mldiagnostics and directly mapping internal metrics to canonical string names. It also removes the gradient norm metric and updates several trainers (including base_wan, dreambooth, flux, sdxl, and stable_diffusion) to explicitly pass total_weights=num_model_parameters when recording scalar metrics. Corresponding updates were made to the documentation and tests. There are no review comments, so I have no feedback to provide.

- Wire total_weights into telemetry:
  Pass the existing `num_model_parameters` calculation into
  `record_scalar_metrics(..., total_weights=num_model_parameters)` across
  all trainers (Stable Diffusion, SDXL, Flux, Wan, and DreamBooth).
  This populates the total_weights card in Google Cloud ML
  Diagnostics.
- Remove the redundant `metric_types` import and `if/else` branching.
  Standardize `_METRICS_TO_MANAGED` directly on canonical string literals,
  matching the SDK's internal representation.

@Perseus14 Perseus14 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Most of it looks good, added a couple of comments. PTAL!

new_time - last_step_completion,
self.per_device_tflops,
unet_learning_rate_scheduler(step),
total_weights=num_model_parameters,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_model_parameters currently counts only unet_state.params, but when train_text_encoder=True, this trainer also updates text_encoder_state.params. Publishing the UNet-only count as total_weights underreports the documented total trainable parameter count.

Please include the text-encoder parameters when that flag is enabled, keeping the calculation outside the training loop. Please also cover both flag values in a focused test; the current metrics tests supply the count directly and cannot catch this omission.

new_time - last_step_completion,
self.per_device_tflops,
learning_rate_scheduler(step),
total_weights=num_model_parameters,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same counting issue applies here: num_model_parameters includes only the UNet, while DreamBooth also updates the text encoder when train_text_encoder=True. Please conditionally include text_encoder_state.params so total_weights reflects all trainable parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants