Skip to content

perf: reduce .item() calls and fuse optimizer - #150

Merged
lightseek-bot merged 2 commits into
lightseekorg:mainfrom
Dogacel:training-speed
Jul 31, 2026
Merged

perf: reduce .item() calls and fuse optimizer#150
lightseek-bot merged 2 commits into
lightseekorg:mainfrom
Dogacel:training-speed

Conversation

@Dogacel

@Dogacel Dogacel commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Improves training speed about ~25%.

image

Dogacel added 2 commits July 31, 2026 04:19
Signed-off-by: Doğaç Eldenk <dogacel@gmail.com>
Signed-off-by: Doğaç Eldenk <dogacel@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 665b03169c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

grad_norm = torch.nn.utils.clip_grad_norm_(self.fp32_params, self.max_grad_norm)
if grad_norm > 0.0:
self.optimizer.step()
self.optimizer.step()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard AdamW updates after NaN grad norms

When a training batch produces NaN gradients, clip_grad_norm_ returns NaN; the removed grad_norm > 0.0 guard previously skipped the AdamW update because the comparison was false. With the unconditional step here, AdamW consumes the NaN gradients and the fp32 master parameters are then copied back into the bf16 model, so a single bad batch can poison subsequent training and checkpoints instead of being skipped.

Useful? React with 👍 / 👎.

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.

echo one this, let's keep the guard

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry I missed this
@Dogacel may you fix in the followup

@lightseek-bot
lightseek-bot merged commit 5c84749 into lightseekorg:main Jul 31, 2026
2 checks passed
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.

3 participants