-
Notifications
You must be signed in to change notification settings - Fork 633
fix(disp): div 0 error when using disp_avg under multitask #5809
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1616,26 +1616,20 @@ def fake_model() -> dict: | |
| def log_loss_train( | ||
| _loss: Any, _more_loss: Any, _task_key: str = "Default" | ||
| ) -> dict: | ||
| results = {} | ||
| if not self.multi_task: | ||
| # Use accumulated average loss for single task | ||
| for item in self.train_loss_accu: | ||
| results[item] = ( | ||
| self.train_loss_accu[item] | ||
| / self.step_count_in_interval | ||
| ) | ||
| else: | ||
| # Use accumulated average loss for multi-task | ||
| if ( | ||
| _task_key in self.train_loss_accu | ||
| and _task_key in self.step_count_per_task | ||
| ): | ||
| for item in self.train_loss_accu[_task_key]: | ||
| results[item] = ( | ||
| self.train_loss_accu[_task_key][item] | ||
| / self.step_count_per_task[_task_key] | ||
| ) | ||
| return results | ||
| return { | ||
| item: value / self.step_count_in_interval | ||
| for item, value in self.train_loss_accu.items() | ||
| } | ||
|
|
||
| task_losses = self.train_loss_accu.get(_task_key, {}) | ||
| step_count = self.step_count_per_task.get(_task_key, 0) | ||
| if step_count == 0: | ||
| return dict.fromkeys(task_losses, float("nan")) | ||
| return { | ||
| item: value / step_count | ||
| for item, value in task_losses.items() | ||
| } | ||
| else: | ||
|
|
||
| def log_loss_train( | ||
|
|
@@ -1709,7 +1703,31 @@ def log_loss_valid(_task_key: str = "Default") -> dict: | |
| valid_results = {_key: {} for _key in self.model_keys} | ||
| if self.disp_avg: | ||
| # For multi-task, use accumulated average loss for all tasks | ||
| def initialize_task_loss_accumulator( | ||
| _task_key: str, | ||
| ) -> None: | ||
| if self.train_loss_accu[_task_key]: | ||
| return | ||
| self.optimizer.zero_grad(set_to_none=True) | ||
| task_input, task_label, _ = self.get_data( | ||
| is_train=True, task_key=_task_key | ||
| ) | ||
| if not task_input: | ||
| return | ||
|
OutisLi marked this conversation as resolved.
Comment on lines
+1715
to
+1716
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Handle filtered batches when initializing unsampled metrics. When Please populate the metric schema without relying on one consumable training batch, or loop until a valid batch is returned. 🛠️ Proposed fix- if not task_input:
- return
+ while not task_input:
+ task_input, task_label, _ = self.get_data(
+ is_train=True, task_key=_task_key
+ )🤖 Prompt for AI Agents |
||
| _, _, task_more_loss = self.wrapper( | ||
| **task_input, | ||
| cur_lr=pref_lr, | ||
| label=task_label, | ||
| task_key=_task_key, | ||
| ) | ||
| self.train_loss_accu[_task_key] = { | ||
| item: 0.0 | ||
| for item in task_more_loss | ||
| if "l2_" not in item | ||
| } | ||
|
|
||
| for _key in self.model_keys: | ||
| initialize_task_loss_accumulator(_key) | ||
| train_results[_key] = log_loss_train( | ||
| loss, more_loss, _task_key=_key | ||
| ) | ||
|
|
@@ -1732,25 +1750,30 @@ def log_loss_valid(_task_key: str = "Default") -> dict: | |
| train_results[_key] = log_loss_train( | ||
| loss, more_loss, _task_key=_key | ||
| ) | ||
| valid_results[_key] = log_loss_valid(_task_key=_key) | ||
| if self.rank == 0: | ||
| for _key in self.model_keys: | ||
| valid_results[_key] = log_loss_valid(_task_key=_key) | ||
| if self.rank == 0: | ||
| log.info( | ||
| format_training_message_per_task( | ||
| batch=display_step_id, | ||
| task_name=_key + "_trn", | ||
| rmse=train_results[_key], | ||
| learning_rate=cur_lr, | ||
| check_total_rmse_nan=not ( | ||
| self.disp_avg | ||
| and self.step_count_per_task.get(_key, 0) == 0 | ||
| ), | ||
| ) | ||
| ) | ||
| if valid_results[_key]: | ||
| log.info( | ||
| format_training_message_per_task( | ||
| batch=display_step_id, | ||
| task_name=_key + "_trn", | ||
| rmse=train_results[_key], | ||
| learning_rate=cur_lr, | ||
| task_name=_key + "_val", | ||
| rmse=valid_results[_key], | ||
| learning_rate=None, | ||
| ) | ||
| ) | ||
| if valid_results[_key]: | ||
| log.info( | ||
| format_training_message_per_task( | ||
| batch=display_step_id, | ||
| task_name=_key + "_val", | ||
| rmse=valid_results[_key], | ||
| learning_rate=None, | ||
| ) | ||
| ) | ||
| self.wrapper.train() | ||
|
|
||
| if self.disp_avg: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.